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 extern "C" int initialize_gdb_stub(); // start up GDB stub
52 ExplorerGlobals g_Globals
;
55 ExplorerGlobals::ExplorerGlobals()
61 _prescan_nodes
= false;
62 _desktop_mode
= false;
64 #ifndef __MINGW32__ // SHRestricted() missing in MinGW (as of 29.10.2003)
70 void _log_(LPCTSTR txt
)
72 FmtString
msg(TEXT("%s\n"), txt
);
75 _fputts(msg
, g_Globals
._log
);
77 OutputDebugString(msg
);
81 ResString::ResString(UINT nid
)
83 TCHAR buffer
[BUFFER_LEN
];
85 int len
= LoadString(g_Globals
._hInstance
, nid
, buffer
, sizeof(buffer
)/sizeof(TCHAR
));
87 super::assign(buffer
, len
);
91 ResIcon::ResIcon(UINT nid
)
93 _hIcon
= LoadIcon(g_Globals
._hInstance
, MAKEINTRESOURCE(nid
));
96 SmallIcon::SmallIcon(UINT nid
)
98 _hIcon
= (HICON
)LoadImage(g_Globals
._hInstance
, MAKEINTRESOURCE(nid
), IMAGE_ICON
, GetSystemMetrics(SM_CXSMICON
), GetSystemMetrics(SM_CYSMICON
), LR_SHARED
);
101 ResIconEx::ResIconEx(UINT nid
, int w
, int h
)
103 _hIcon
= (HICON
)LoadImage(g_Globals
._hInstance
, MAKEINTRESOURCE(nid
), IMAGE_ICON
, w
, h
, LR_SHARED
);
107 void SetWindowIcon(HWND hwnd
, UINT nid
)
109 HICON hIcon
= ResIcon(nid
);
110 Window_SetIcon(hwnd
, ICON_BIG
, hIcon
);
112 HICON hIconSmall
= SmallIcon(nid
);
113 Window_SetIcon(hwnd
, ICON_SMALL
, hIconSmall
);
117 ResBitmap::ResBitmap(UINT nid
)
119 _hBmp
= LoadBitmap(g_Globals
._hInstance
, MAKEINTRESOURCE(nid
));
123 void explorer_show_frame(HWND hwndDesktop
, int cmdshow
)
125 if (g_Globals
._hMainWnd
)
128 g_Globals
._prescan_nodes
= false;
130 // create main window
131 HWND hMainFrame
= MainFrame::Create();
134 g_Globals
._hMainWnd
= hMainFrame
;
136 ShowWindow(hMainFrame
, cmdshow
);
137 UpdateWindow(hMainFrame
);
139 // Open the first child window after initializing the whole application
140 PostMessage(hMainFrame
, PM_OPEN_WINDOW
, OWM_EXPLORE
|OWM_DETAILS
, 0);
145 static void InitInstance(HINSTANCE hInstance
)
147 CONTEXT("InitInstance");
149 setlocale(LC_COLLATE
, ""); // set collating rules to local settings for compareName
151 // register frame window class
152 g_Globals
._hframeClass
= IconWindowClass(CLASSNAME_FRAME
,IDI_EXPLORER
);
154 // register child windows class
155 WindowClass(CLASSNAME_CHILDWND
, CS_CLASSDC
|CS_DBLCLKS
|CS_VREDRAW
).Register();
157 // register tree windows class
158 WindowClass(CLASSNAME_WINEFILETREE
, CS_CLASSDC
|CS_DBLCLKS
|CS_VREDRAW
).Register();
160 g_Globals
._cfStrFName
= RegisterClipboardFormat(CFSTR_FILENAME
);
164 int explorer_main(HINSTANCE hInstance
, HWND hwndDesktop
, int cmdshow
)
166 CONTEXT("explorer_main");
168 // initialize COM and OLE
171 // initialize Common Controls library
172 CommonControlInit usingCmnCtrl
;
175 InitInstance(hInstance
);
176 } catch(COMException
& e
) {
177 HandleException(e
, hwndDesktop
);
182 g_Globals
._desktop_mode
= true;
184 if (cmdshow
!= SW_HIDE
) {
185 /* // don't maximize if being called from the ROS desktop
186 if (cmdshow == SW_SHOWNORMAL)
187 ///@todo read window placement from registry
188 cmdshow = SW_MAXIMIZE;
191 explorer_show_frame(hwndDesktop
, cmdshow
);
194 return Window::MessageLoop();
198 // MinGW does not provide a Unicode startup routine, so we have to implement an own.
199 #if defined(__MINGW32__) && defined(UNICODE)
201 #define _tWinMain wWinMain
202 int WINAPI
wWinMain(HINSTANCE
, HINSTANCE
, LPWSTR
, int);
204 int main(int argc
, char* argv
[])
208 STARTUPINFO startupinfo
;
209 int nShowCmd
= SW_SHOWNORMAL
;
211 GetStartupInfo(&startupinfo
);
213 if (startupinfo
.dwFlags
& STARTF_USESHOWWINDOW
)
214 nShowCmd
= startupinfo
.wShowWindow
;
216 return wWinMain(GetModuleHandle(NULL
), 0, GetCommandLine(), nShowCmd
);
219 #endif // __MINGW && UNICODE
222 int WINAPI
_tWinMain(HINSTANCE hInstance
, HINSTANCE hPrevInstance
, LPTSTR lpCmdLine
, int nShowCmd
)
224 CONTEXT("WinMain()");
226 // create desktop window and task bar only, if there is no other shell and we are
227 // the first explorer instance
228 BOOL startup_desktop
= !IsAnyDesktopRunning();
230 bool autostart
= true;
232 #ifdef _DEBUG //MF: disabled for debugging
236 // If there is given the command line option "-desktop", create desktop window anyways
237 if (_tcsstr(lpCmdLine
,TEXT("-desktop")))
238 startup_desktop
= TRUE
;
240 if (_tcsstr(lpCmdLine
,TEXT("-nodesktop")))
241 startup_desktop
= FALSE
;
243 if (_tcsstr(lpCmdLine
,TEXT("-noexplorer"))) {
245 startup_desktop
= TRUE
;
248 if (_tcsstr(lpCmdLine
,TEXT("-noautostart")))
252 if (_tcsstr(lpCmdLine
,TEXT("-console"))) {
255 _dup2(_open_osfhandle((long)GetStdHandle(STD_INPUT_HANDLE
), _O_RDONLY
), 0);
256 _dup2(_open_osfhandle((long)GetStdHandle(STD_OUTPUT_HANDLE
), 0), 1);
257 _dup2(_open_osfhandle((long)GetStdHandle(STD_ERROR_HANDLE
), 0), 2);
259 g_Globals
._log
= fdopen(1, "w");
260 setvbuf(g_Globals
._log
, 0, _IONBF
, 0);
262 LOG(TEXT("starting explorer debug log\n"));
266 bool use_gdb_stub
= false; // !IsDebuggerPresent();
268 if (_tcsstr(lpCmdLine
,TEXT("-debug")))
271 // activate GDB remote debugging stub if no other debugger is running
273 LOG(TEXT("waiting for debugger connection...\n"));
275 initialize_gdb_stub();
278 g_Globals
._hInstance
= hInstance
;
279 #ifndef __MINGW32__ // SHRestricted() missing in MinGW (as of 29.10.2003)
280 g_Globals
._SHRestricted
= (DWORD(STDAPICALLTYPE
*)(RESTRICTIONS
)) GetProcAddress(GetModuleHandle(TEXT("SHELL32")), "SHRestricted");
283 HWND hwndDesktop
= 0;
287 hwndDesktop
= DesktopWindow::Create();
291 char* argv
[] = {"", "s"}; // call startup routine in SESSION_START mode
296 int ret
= explorer_main(hInstance
, hwndDesktop
, nShowCmd
);