2 * Copyright 2003 Martin Fuchs
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25 // Martin Fuchs, 23.07.2003
27 // Credits: Thanks to Leon Finker for his explorer window example
31 #include "utility/utility.h"
34 #include "desktop/desktop.h"
37 #include "externals.h"
39 #include "explorer_intres.h"
41 #include <locale.h> // for setlocale()
44 #include <io.h> // for dup2()
45 #include <fcntl.h> // for _O_RDONLY
49 ExplorerGlobals g_Globals
;
52 ExplorerGlobals::ExplorerGlobals()
58 _prescan_nodes
= false;
59 _desktop_mode
= false;
61 #ifndef __MINGW32__ // SHRestricted() missing in MinGW (as of 29.10.2003)
67 void _log_(LPCTSTR txt
)
69 FmtString
msg(TEXT("%s\n"), txt
);
72 _fputts(msg
, g_Globals
._log
);
74 OutputDebugString(msg
);
78 ResString::ResString(UINT nid
)
80 TCHAR buffer
[BUFFER_LEN
];
82 int len
= LoadString(g_Globals
._hInstance
, nid
, buffer
, sizeof(buffer
)/sizeof(TCHAR
));
84 super::assign(buffer
, len
);
88 ResIcon::ResIcon(UINT nid
)
90 _hIcon
= LoadIcon(g_Globals
._hInstance
, MAKEINTRESOURCE(nid
));
93 SmallIcon::SmallIcon(UINT nid
)
95 _hIcon
= (HICON
)LoadImage(g_Globals
._hInstance
, MAKEINTRESOURCE(nid
), IMAGE_ICON
, GetSystemMetrics(SM_CXSMICON
), GetSystemMetrics(SM_CYSMICON
), LR_SHARED
);
98 ResIconEx::ResIconEx(UINT nid
, int w
, int h
)
100 _hIcon
= (HICON
)LoadImage(g_Globals
._hInstance
, MAKEINTRESOURCE(nid
), IMAGE_ICON
, w
, h
, LR_SHARED
);
104 void SetWindowIcon(HWND hwnd
, UINT nid
)
106 HICON hIcon
= ResIcon(nid
);
107 Window_SetIcon(hwnd
, ICON_BIG
, hIcon
);
109 HICON hIconSmall
= SmallIcon(nid
);
110 Window_SetIcon(hwnd
, ICON_SMALL
, hIconSmall
);
114 ResBitmap::ResBitmap(UINT nid
)
116 _hBmp
= LoadBitmap(g_Globals
._hInstance
, MAKEINTRESOURCE(nid
));
120 void explorer_show_frame(HWND hwndDesktop
, int cmdshow
)
122 if (g_Globals
._hMainWnd
)
125 g_Globals
._prescan_nodes
= false;
127 // create main window
128 HWND hMainFrame
= MainFrame::Create();
131 g_Globals
._hMainWnd
= hMainFrame
;
133 ShowWindow(hMainFrame
, cmdshow
);
134 UpdateWindow(hMainFrame
);
136 // Open the first child window after initializing the whole application
137 PostMessage(hMainFrame
, PM_OPEN_WINDOW
, OWM_EXPLORE
|OWM_DETAILS
, 0);
142 static void InitInstance(HINSTANCE hInstance
)
144 CONTEXT("InitInstance");
146 setlocale(LC_COLLATE
, ""); // set collating rules to local settings for compareName
148 // register frame window class
149 g_Globals
._hframeClass
= IconWindowClass(CLASSNAME_FRAME
,IDI_EXPLORER
);
151 // register child windows class
152 WindowClass(CLASSNAME_CHILDWND
, CS_CLASSDC
|CS_DBLCLKS
|CS_VREDRAW
).Register();
154 // register tree windows class
155 WindowClass(CLASSNAME_WINEFILETREE
, CS_CLASSDC
|CS_DBLCLKS
|CS_VREDRAW
).Register();
157 g_Globals
._cfStrFName
= RegisterClipboardFormat(CFSTR_FILENAME
);
161 int explorer_main(HINSTANCE hInstance
, HWND hwndDesktop
, int cmdshow
)
163 CONTEXT("explorer_main");
165 // initialize COM and OLE
168 // initialize Common Controls library
169 CommonControlInit usingCmnCtrl
;
172 InitInstance(hInstance
);
173 } catch(COMException
& e
) {
174 HandleException(e
, hwndDesktop
);
179 g_Globals
._desktop_mode
= true;
181 if (cmdshow
!= SW_HIDE
) {
182 /* // don't maximize if being called from the ROS desktop
183 if (cmdshow == SW_SHOWNORMAL)
184 ///@todo read window placement from registry
185 cmdshow = SW_MAXIMIZE;
188 explorer_show_frame(hwndDesktop
, cmdshow
);
191 return Window::MessageLoop();
195 // MinGW does not provide a Unicode startup routine, so we have to implement an own.
196 #if defined(__MINGW32__) && defined(UNICODE)
198 #define _tWinMain wWinMain
199 int WINAPI
wWinMain(HINSTANCE
, HINSTANCE
, LPWSTR
, int);
201 int main(int argc
, char* argv
[])
205 STARTUPINFO startupinfo
;
206 int nShowCmd
= SW_SHOWNORMAL
;
208 GetStartupInfo(&startupinfo
);
210 if (startupinfo
.dwFlags
& STARTF_USESHOWWINDOW
)
211 nShowCmd
= startupinfo
.wShowWindow
;
213 return wWinMain(GetModuleHandle(NULL
), 0, GetCommandLine(), nShowCmd
);
216 #endif // __MINGW && UNICODE
219 int WINAPI
_tWinMain(HINSTANCE hInstance
, HINSTANCE hPrevInstance
, LPTSTR lpCmdLine
, int nShowCmd
)
221 CONTEXT("WinMain()");
223 // create desktop window and task bar only, if there is no other shell and we are
224 // the first explorer instance
225 BOOL startup_desktop
= !IsAnyDesktopRunning();
227 bool autostart
= true;
229 #ifdef _DEBUG //MF: disabled for debugging
233 // If there is given the command line option "-desktop", create desktop window anyways
234 if (_tcsstr(lpCmdLine
,TEXT("-desktop")))
235 startup_desktop
= TRUE
;
237 if (_tcsstr(lpCmdLine
,TEXT("-nodesktop")))
238 startup_desktop
= FALSE
;
240 if (_tcsstr(lpCmdLine
,TEXT("-noexplorer"))) {
242 startup_desktop
= TRUE
;
245 if (_tcsstr(lpCmdLine
,TEXT("-noautostart")))
249 if (_tcsstr(lpCmdLine
,TEXT("-console"))) {
252 _dup2(_open_osfhandle((long)GetStdHandle(STD_INPUT_HANDLE
), _O_RDONLY
), 0);
253 _dup2(_open_osfhandle((long)GetStdHandle(STD_OUTPUT_HANDLE
), 0), 1);
254 _dup2(_open_osfhandle((long)GetStdHandle(STD_ERROR_HANDLE
), 0), 2);
256 g_Globals
._log
= fdopen(1, "w");
257 setvbuf(g_Globals
._log
, 0, _IONBF
, 0);
259 LOG(TEXT("starting explore debug log\n"));
263 g_Globals
._hInstance
= hInstance
;
264 #ifndef __MINGW32__ // SHRestricted() missing in MinGW (as of 29.10.2003)
265 g_Globals
._SHRestricted
= (DWORD(STDAPICALLTYPE
*)(RESTRICTIONS
)) GetProcAddress(GetModuleHandle(TEXT("SHELL32")), "SHRestricted");
268 HWND hwndDesktop
= 0;
272 hwndDesktop
= DesktopWindow::Create();
276 char* argv
[] = {"", "s"}; // call startup routine in SESSION_START mode
281 int ret
= explorer_main(hInstance
, hwndDesktop
, nShowCmd
);