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
, LPTSTR lpCmdLine
)
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 bool valid_dir
= false;
142 DWORD attribs
= GetFileAttributes(lpCmdLine
);
144 if (attribs
!=INVALID_FILE_ATTRIBUTES
&& (attribs
&FILE_ATTRIBUTE_DIRECTORY
))
146 else if (*lpCmdLine
==':' || *lpCmdLine
=='"')
150 // Open the first child window after initializing the application
152 PostMessage(hMainFrame
, PM_OPEN_WINDOW
, 0, (LPARAM
)lpCmdLine
);
154 PostMessage(hMainFrame
, PM_OPEN_WINDOW
, OWM_EXPLORE
|OWM_DETAILS
, 0);
159 /// "About Explorer" Dialog
160 struct ExplorerAboutDlg
: public
162 OwnerDrawParent
<Dialog
>
165 typedef CtlColorParent
<
166 OwnerDrawParent
<Dialog
>
169 ExplorerAboutDlg(HWND hwnd
)
172 SetWindowIcon(hwnd
, IDI_REACTOS
);
174 new FlatButton(hwnd
, IDOK
);
176 _hfont
= CreateFont(20, 0, 0, 0, FW_BOLD
, TRUE
, 0, 0, 0, 0, 0, 0, 0, TEXT("Sans Serif"));
177 new ColorStatic(hwnd
, IDC_ROS_EXPLORER
, RGB(32,32,128), 0, _hfont
);
179 new HyperlinkCtrl(hwnd
, IDC_WWW
);
186 DeleteObject(_hfont
);
189 LRESULT
WndProc(UINT nmsg
, WPARAM wparam
, LPARAM lparam
)
197 return super::WndProc(nmsg
, wparam
, lparam
);
205 PaintCanvas
canvas(_hwnd
);
207 HICON hicon
= (HICON
) LoadImage(g_Globals
._hInstance
, MAKEINTRESOURCE(IDI_REACTOS_BIG
), IMAGE_ICON
, 0, 0, LR_SHARED
);
209 DrawIconEx(canvas
, 20, 10, hicon
, 0, 0, 0, 0, DI_NORMAL
);
216 void explorer_about(HWND hwndParent
)
218 Dialog::DoModal(IDD_ABOUT_EXPLORER
, WINDOW_CREATOR(ExplorerAboutDlg
), hwndParent
);
222 static void InitInstance(HINSTANCE hInstance
)
224 CONTEXT("InitInstance");
226 setlocale(LC_COLLATE
, ""); // set collating rules to local settings for compareName
228 // register frame window class
229 g_Globals
._hframeClass
= IconWindowClass(CLASSNAME_FRAME
,IDI_EXPLORER
);
231 // register child windows class
232 WindowClass(CLASSNAME_CHILDWND
, CS_CLASSDC
|CS_DBLCLKS
|CS_VREDRAW
).Register();
234 // register tree windows class
235 WindowClass(CLASSNAME_WINEFILETREE
, CS_CLASSDC
|CS_DBLCLKS
|CS_VREDRAW
).Register();
237 g_Globals
._cfStrFName
= RegisterClipboardFormat(CFSTR_FILENAME
);
241 int explorer_main(HINSTANCE hInstance
, HWND hwndDesktop
, LPTSTR lpCmdLine
, int cmdshow
)
243 CONTEXT("explorer_main");
245 // initialize COM and OLE
248 // initialize Common Controls library
249 CommonControlInit usingCmnCtrl
;
252 InitInstance(hInstance
);
253 } catch(COMException
& e
) {
254 HandleException(e
, hwndDesktop
);
259 g_Globals
._desktop_mode
= true;
261 if (cmdshow
!= SW_HIDE
) {
262 /* // don't maximize if being called from the ROS desktop
263 if (cmdshow == SW_SHOWNORMAL)
264 ///@todo read window placement from registry
265 cmdshow = SW_MAXIMIZE;
268 explorer_show_frame(hwndDesktop
, cmdshow
, lpCmdLine
);
271 return Window::MessageLoop();
275 // MinGW does not provide a Unicode startup routine, so we have to implement an own.
276 #if defined(__MINGW32__) && defined(UNICODE)
278 #define _tWinMain wWinMain
279 int WINAPI
wWinMain(HINSTANCE
, HINSTANCE
, LPWSTR
, int);
281 int main(int argc
, char* argv
[])
285 STARTUPINFO startupinfo
;
286 int nShowCmd
= SW_SHOWNORMAL
;
288 GetStartupInfo(&startupinfo
);
290 if (startupinfo
.dwFlags
& STARTF_USESHOWWINDOW
)
291 nShowCmd
= startupinfo
.wShowWindow
;
293 LPWSTR cmdline
= GetCommandLineW();
295 while(*cmdline
&& !_istspace(*cmdline
))
298 return wWinMain(GetModuleHandle(NULL
), 0, cmdline
, nShowCmd
);
301 #endif // __MINGW && UNICODE
304 int WINAPI
_tWinMain(HINSTANCE hInstance
, HINSTANCE hPrevInstance
, LPTSTR lpCmdLine
, int nShowCmd
)
306 CONTEXT("WinMain()");
308 // create desktop window and task bar only, if there is no other shell and we are
309 // the first explorer instance
310 BOOL startup_desktop
= !IsAnyDesktopRunning();
312 bool autostart
= true;
314 #ifdef _DEBUG //MF: disabled for debugging
318 // If there is given the command line option "-desktop", create desktop window anyways
319 if (_tcsstr(lpCmdLine
,TEXT("-desktop")))
320 startup_desktop
= TRUE
;
321 else if (_tcsstr(lpCmdLine
,TEXT("-nodesktop")))
322 startup_desktop
= FALSE
;
324 // Don't display cabinet window in desktop mode
325 if (startup_desktop
&& !_tcsstr(lpCmdLine
,TEXT("-explorer")))
328 if (_tcsstr(lpCmdLine
,TEXT("-noautostart")))
332 if (_tcsstr(lpCmdLine
,TEXT("-console"))) {
335 _dup2(_open_osfhandle((long)GetStdHandle(STD_INPUT_HANDLE
), _O_RDONLY
), 0);
336 _dup2(_open_osfhandle((long)GetStdHandle(STD_OUTPUT_HANDLE
), 0), 1);
337 _dup2(_open_osfhandle((long)GetStdHandle(STD_ERROR_HANDLE
), 0), 2);
339 g_Globals
._log
= fdopen(1, "w");
340 setvbuf(g_Globals
._log
, 0, _IONBF
, 0);
342 LOG(TEXT("starting explorer debug log\n"));
346 bool use_gdb_stub
= false; // !IsDebuggerPresent();
348 if (_tcsstr(lpCmdLine
,TEXT("-debug")))
351 if (_tcsstr(lpCmdLine
,TEXT("-break"))) {
352 LOG(TEXT("debugger breakpoint"));
360 // activate GDB remote debugging stub if no other debugger is running
362 LOG(TEXT("waiting for debugger connection...\n"));
364 initialize_gdb_stub();
367 g_Globals
._hInstance
= hInstance
;
368 #ifndef __MINGW32__ // SHRestricted() missing in MinGW (as of 29.10.2003)
369 g_Globals
._SHRestricted
= (DWORD(STDAPICALLTYPE
*)(RESTRICTIONS
)) GetProcAddress(GetModuleHandle(TEXT("SHELL32")), "SHRestricted");
372 HWND hwndDesktop
= 0;
376 hwndDesktop
= DesktopWindow::Create();
380 char* argv
[] = {"", "s"}; // call startup routine in SESSION_START mode
385 /**TODO fix command line handling */
386 if (*lpCmdLine
=='"' && lpCmdLine
[_tcslen(lpCmdLine
)-1]=='"') {
388 lpCmdLine
[_tcslen(lpCmdLine
)-1] = '\0';
391 int ret
= explorer_main(hInstance
, hwndDesktop
, lpCmdLine
, nShowCmd
);