2 * Copyright 2003, 2004, 2005 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 cabinet window example
31 #include <precomp.h> // <precomp.h> instead of "precomp.h" because the ROS build system needs this to find the precompiled header file (*.gch) in the output directory tree
35 #include <locale.h> // for setlocale()
38 #include <io.h> // for dup2()
39 #include <fcntl.h> // for _O_RDONLY
42 #include "dialogs/settings.h" // for MdiSdiDlg
44 #include "services/shellservices.h"
47 extern "C" int initialize_gdb_stub(); // start up GDB stub
50 DynamicLoadLibFct
<void(__stdcall
*)(BOOL
)> g_SHDOCVW_ShellDDEInit(TEXT("SHDOCVW"), 118);
53 ExplorerGlobals g_Globals
;
56 ExplorerGlobals::ExplorerGlobals()
64 _desktop_mode
= false;
65 _prescan_nodes
= false;
69 #ifndef __MINGW32__ // SHRestricted() missing in MinGW (as of 29.10.2003)
78 void ExplorerGlobals::init(HINSTANCE hInstance
)
80 _hInstance
= hInstance
;
82 #ifndef __MINGW32__ // SHRestricted() missing in MinGW (as of 29.10.2003)
83 _SHRestricted
= (DWORD(STDAPICALLTYPE
*)(RESTRICTIONS
)) GetProcAddress(GetModuleHandle(TEXT("SHELL32")), "SHRestricted");
90 void ExplorerGlobals::read_persistent()
92 // read configuration file
93 _cfg_dir
.printf(TEXT("%s\\ReactOS"), (LPCTSTR
)SpecialFolderFSPath(CSIDL_APPDATA
,0));
94 _cfg_path
.printf(TEXT("%s\\ros-explorer-cfg.xml"), _cfg_dir
.c_str());
96 if (!_cfg
.read(_cfg_path
)) {
97 if (_cfg
._last_error
!= XML_ERROR_NO_ELEMENTS
)
98 MessageBox(g_Globals
._hwndDesktop
, String(_cfg
._last_error_msg
.c_str()),
99 TEXT("ROS Explorer - reading user settings"), MB_OK
);
101 _cfg
.read(TEXT("explorer-cfg-template.xml"));
105 _favorites_path
.printf(TEXT("%s\\ros-explorer-bookmarks.xml"), _cfg_dir
.c_str());
107 if (!_favorites
.read(_favorites_path
)) {
108 _favorites
.import_IE_favorites(0);
109 _favorites
.write(_favorites_path
);
113 void ExplorerGlobals::write_persistent()
115 // write configuration file
116 RecursiveCreateDirectory(_cfg_dir
);
118 _cfg
.write(_cfg_path
);
119 _favorites
.write(_favorites_path
);
123 XMLPos
ExplorerGlobals::get_cfg()
125 XMLPos
cfg_pos(&_cfg
);
127 cfg_pos
.smart_create("explorer-cfg");
132 XMLPos
ExplorerGlobals::get_cfg(const char* path
)
134 XMLPos
cfg_pos(&_cfg
);
136 cfg_pos
.smart_create("explorer-cfg");
137 cfg_pos
.create_relative(path
);
143 void _log_(LPCTSTR txt
)
145 FmtString
msg(TEXT("%s\n"), txt
);
148 _fputts(msg
, g_Globals
._log
);
150 OutputDebugString(msg
);
154 bool FileTypeManager::is_exe_file(LPCTSTR ext
)
156 static const LPCTSTR s_executable_extensions
[] = {
167 TCHAR ext_buffer
[_MAX_EXT
];
172 for(s
=ext
+1,d
=ext_buffer
; (*d
=toupper(*s
)); s
++)
175 for(p
=s_executable_extensions
; *p
; p
++)
176 if (!lstrcmp(ext_buffer
, *p
))
183 const FileTypeInfo
& FileTypeManager::operator[](String ext
)
187 iterator found
= find(ext
);
189 return found
->second
;
191 FileTypeInfo
& ftype
= super::operator[](ext
);
193 ftype
._neverShowExt
= false;
196 TCHAR value
[MAX_PATH
], display_name
[MAX_PATH
];
197 LONG valuelen
= sizeof(value
);
199 if (!RegQueryValue(HKEY_CLASSES_ROOT
, ext
, value
, &valuelen
)) {
200 ftype
._classname
= value
;
202 valuelen
= sizeof(display_name
);
203 if (!RegQueryValue(HKEY_CLASSES_ROOT
, ftype
._classname
, display_name
, &valuelen
))
204 ftype
._displayname
= display_name
;
206 if (!RegOpenKey(HKEY_CLASSES_ROOT
, ftype
._classname
, &hkey
)) {
207 if (!RegQueryValueEx(hkey
, TEXT("NeverShowExt"), 0, NULL
, NULL
, NULL
))
208 ftype
._neverShowExt
= true;
217 LPCTSTR
FileTypeManager::set_type(Entry
* entry
, bool dont_hide_ext
)
219 LPCTSTR ext
= _tcsrchr(entry
->_data
.cFileName
, TEXT('.'));
222 const FileTypeInfo
& type
= (*this)[ext
];
224 if (!type
._displayname
.empty())
225 entry
->_type_name
= _tcsdup(type
._displayname
);
227 // hide some file extensions
228 if (type
._neverShowExt
&& !dont_hide_ext
) {
229 int len
= ext
- entry
->_data
.cFileName
;
230 entry
->_display_name
= (LPTSTR
) malloc((len
+1)*sizeof(TCHAR
));
231 lstrcpyn(entry
->_display_name
, entry
->_data
.cFileName
, len
+ 1);
234 if (is_exe_file(ext
))
235 entry
->_data
.dwFileAttributes
|= ATTRIBUTE_EXECUTABLE
;
249 Icon::Icon(ICON_ID id
, UINT nid
) //, int cx, int cy
252 _hicon(ResIcon(nid
)) // ResIconEx(nid, cx, cy)
256 Icon::Icon(ICON_TYPE itype
, int id
, HICON hIcon
)
263 Icon::Icon(ICON_TYPE itype
, int id
, int sys_idx
)
270 void Icon::draw(HDC hdc
, int x
, int y
, int cx
, int cy
, COLORREF bk_color
, HBRUSH bk_brush
) const
272 if (_itype
== IT_SYSCACHE
)
273 ImageList_DrawEx(g_Globals
._icon_cache
.get_sys_imagelist(), _sys_idx
, hdc
, x
, y
, cx
, cy
, bk_color
, CLR_DEFAULT
, ILD_NORMAL
);
275 DrawIconEx(hdc
, x
, y
, _hicon
, cx
, cy
, 0, bk_brush
, DI_NORMAL
);
278 HBITMAP
Icon::create_bitmap(COLORREF bk_color
, HBRUSH hbrBkgnd
, HDC hdc_wnd
) const
280 if (_itype
== IT_SYSCACHE
) {
281 HIMAGELIST himl
= g_Globals
._icon_cache
.get_sys_imagelist();
284 ImageList_GetIconSize(himl
, &cx
, &cy
);
286 HBITMAP hbmp
= CreateCompatibleBitmap(hdc_wnd
, cx
, cy
);
287 HDC hdc
= CreateCompatibleDC(hdc_wnd
);
288 HBITMAP hbmp_old
= SelectBitmap(hdc
, hbmp
);
289 ImageList_DrawEx(himl
, _sys_idx
, hdc
, 0, 0, cx
, cy
, bk_color
, CLR_DEFAULT
, ILD_NORMAL
);
290 SelectBitmap(hdc
, hbmp_old
);
295 return create_bitmap_from_icon(_hicon
, hbrBkgnd
, hdc_wnd
);
299 int Icon::add_to_imagelist(HIMAGELIST himl
, HDC hdc_wnd
, COLORREF bk_color
, HBRUSH bk_brush
) const
303 if (_itype
== IT_SYSCACHE
) {
304 HIMAGELIST himl
= g_Globals
._icon_cache
.get_sys_imagelist();
307 ImageList_GetIconSize(himl
, &cx
, &cy
);
309 HBITMAP hbmp
= CreateCompatibleBitmap(hdc_wnd
, cx
, cy
);
310 HDC hdc
= CreateCompatibleDC(hdc_wnd
);
311 HBITMAP hbmp_old
= SelectBitmap(hdc
, hbmp
);
312 ImageList_DrawEx(himl
, _sys_idx
, hdc
, 0, 0, cx
, cy
, bk_color
, CLR_DEFAULT
, ILD_NORMAL
);
313 SelectBitmap(hdc
, hbmp_old
);
316 ret
= ImageList_Add(himl
, hbmp
, 0);
320 ret
= ImageList_AddAlphaIcon(himl
, _hicon
, bk_brush
, hdc_wnd
);
325 HBITMAP
create_bitmap_from_icon(HICON hIcon
, HBRUSH hbrush_bkgnd
, HDC hdc_wnd
/*, bool large_icons*/)
327 int cx
= GetSystemMetrics(SM_CXSMICON
); //ICON_SIZE_X;
328 int cy
= GetSystemMetrics(SM_CYSMICON
); //ICON_SIZE_Y;
329 HBITMAP hbmp
= CreateCompatibleBitmap(hdc_wnd
, cx
, cy
);
332 BitmapSelection
sel(canvas
, hbmp
);
334 RECT rect
= {0, 0, cx
, cy
};
335 FillRect(canvas
, &rect
, hbrush_bkgnd
);
337 DrawIconEx(canvas
, 0, 0, hIcon
, cx
, cy
, 0, hbrush_bkgnd
, DI_NORMAL
);
342 HBITMAP
create_small_bitmap_from_icon(HICON hIcon
, HBRUSH hbrush_bkgnd
, HDC hdc_wnd
)
344 int cx
= GetSystemMetrics(SM_CXSMICON
);
345 int cy
= GetSystemMetrics(SM_CYSMICON
);
346 HBITMAP hbmp
= CreateCompatibleBitmap(hdc_wnd
, cx
, cy
);
349 BitmapSelection
sel(canvas
, hbmp
);
351 RECT rect
= {0, 0, cx
, cy
};
352 FillRect(canvas
, &rect
, hbrush_bkgnd
);
354 DrawIconEx(canvas
, 0, 0, hIcon
, cx
, cy
, 0, hbrush_bkgnd
, DI_NORMAL
);
359 int ImageList_AddAlphaIcon(HIMAGELIST himl
, HICON hIcon
, HBRUSH hbrush_bkgnd
, HDC hdc_wnd
)
361 HBITMAP hbmp
= create_bitmap_from_icon(hIcon
, hbrush_bkgnd
, hdc_wnd
);
363 int ret
= ImageList_Add(himl
, hbmp
, 0);
371 int IconCache::s_next_id
= ICID_DYNAMIC
;
374 void IconCache::init()
376 _icons
[ICID_NONE
] = Icon(IT_STATIC
, ICID_NONE
, (HICON
)0);
378 _icons
[ICID_FOLDER
] = Icon(ICID_FOLDER
, IDI_FOLDER
);
379 //_icons[ICID_DOCUMENT] = Icon(ICID_DOCUMENT, IDI_DOCUMENT);
380 _icons
[ICID_EXPLORER
] = Icon(ICID_EXPLORER
, IDI_EXPLORER
);
381 _icons
[ICID_APP
] = Icon(ICID_APP
, IDI_APPICON
);
383 _icons
[ICID_CONFIG
] = Icon(ICID_CONFIG
, IDI_CONFIG
);
384 _icons
[ICID_DOCUMENTS
] = Icon(ICID_DOCUMENTS
, IDI_DOCUMENTS
);
385 _icons
[ICID_FAVORITES
] = Icon(ICID_FAVORITES
, IDI_FAVORITES
);
386 _icons
[ICID_INFO
] = Icon(ICID_INFO
, IDI_INFO
);
387 _icons
[ICID_APPS
] = Icon(ICID_APPS
, IDI_APPS
);
388 _icons
[ICID_SEARCH
] = Icon(ICID_SEARCH
, IDI_SEARCH
);
389 _icons
[ICID_ACTION
] = Icon(ICID_ACTION
, IDI_ACTION
);
390 _icons
[ICID_SEARCH_DOC
] = Icon(ICID_SEARCH_DOC
, IDI_SEARCH_DOC
);
391 _icons
[ICID_PRINTER
] = Icon(ICID_PRINTER
, IDI_PRINTER
);
392 _icons
[ICID_NETWORK
] = Icon(ICID_NETWORK
, IDI_NETWORK
);
393 _icons
[ICID_COMPUTER
] = Icon(ICID_COMPUTER
, IDI_COMPUTER
);
394 _icons
[ICID_LOGOFF
] = Icon(ICID_LOGOFF
, IDI_LOGOFF
);
395 _icons
[ICID_SHUTDOWN
] = Icon(ICID_SHUTDOWN
, IDI_SHUTDOWN
);
396 _icons
[ICID_BOOKMARK
] = Icon(ICID_BOOKMARK
, IDI_DOT_TRANS
);
397 _icons
[ICID_MINIMIZE
] = Icon(ICID_MINIMIZE
, IDI_MINIMIZE
);
398 _icons
[ICID_CONTROLPAN
] = Icon(ICID_CONTROLPAN
, IDI_CONTROLPAN
);
399 _icons
[ICID_DESKSETTING
] = Icon(ICID_DESKSETTING
, IDI_DESKSETTING
);
400 _icons
[ICID_NETCONNS
] = Icon(ICID_NETCONNS
, IDI_NETCONNS
);
401 _icons
[ICID_ADMINISTRATION
] = Icon(ICID_ADMINISTRATION
, IDI_ADMINISTRATION
);
402 _icons
[ICID_RECENT
] = Icon(ICID_RECENT
, IDI_RECENT
);
406 const Icon
& IconCache::extract(LPCTSTR path
, ICONCACHE_FLAGS flags
)
408 // search for matching icon with unchanged flags in the cache
409 CacheKey
mapkey(path
, flags
);
410 PathCacheMap::iterator found
= _pathCache
.find(mapkey
);
412 if (found
!= _pathCache
.end())
413 return _icons
[found
->second
];
415 // search for matching icon with handle
416 CacheKey
mapkey_hicon(path
, flags
|ICF_HICON
);
417 if (flags
!= mapkey_hicon
.second
) {
418 found
= _pathCache
.find(mapkey_hicon
);
420 if (found
!= _pathCache
.end())
421 return _icons
[found
->second
];
424 // search for matching icon in the system image list cache
425 CacheKey
mapkey_syscache(path
, flags
|ICF_SYSCACHE
);
426 if (flags
!= mapkey_syscache
.second
) {
427 found
= _pathCache
.find(mapkey_syscache
);
429 if (found
!= _pathCache
.end())
430 return _icons
[found
->second
];
437 if (flags
& ICF_OPEN
)
438 shgfi_flags
|= SHGFI_OPENICON
;
440 if ((flags
&(ICF_LARGE
|ICF_OVERLAYS
|ICF_HICON
)) && !(flags
&ICF_SYSCACHE
)) {
441 shgfi_flags
|= SHGFI_ICON
;
443 if (!(flags
& ICF_LARGE
))
444 shgfi_flags
|= SHGFI_SMALLICON
;
446 if (flags
& ICF_OVERLAYS
)
447 shgfi_flags
|= SHGFI_ADDOVERLAYS
;
449 // get small/big icons with/without overlays
450 if (SHGetFileInfo(path
, 0, &sfi
, sizeof(sfi
), shgfi_flags
)) {
451 const Icon
& icon
= add(sfi
.hIcon
, IT_CACHED
);
453 ///@todo limit cache size
454 _pathCache
[mapkey_hicon
] = icon
;
459 assert(!(flags
&ICF_OVERLAYS
));
461 shgfi_flags
|= SHGFI_SYSICONINDEX
|SHGFI_SMALLICON
;
463 // use system image list - the "search program dialog" needs it
464 HIMAGELIST himlSys_small
= (HIMAGELIST
) SHGetFileInfo(path
, 0, &sfi
, sizeof(sfi
), shgfi_flags
);
467 _himlSys_small
= himlSys_small
;
469 const Icon
& icon
= add(sfi
.iIcon
/*, IT_SYSCACHE*/);
471 ///@todo limit cache size
472 _pathCache
[mapkey_syscache
] = icon
;
478 return _icons
[ICID_NONE
];
481 const Icon
& IconCache::extract(LPCTSTR path
, int idx
, ICONCACHE_FLAGS flags
)
483 IdxCacheKey
key(path
, make_pair(idx
, (flags
|ICF_HICON
)&~ICF_SYSCACHE
));
487 IdxCacheMap::iterator found
= _idxCache
.find(key
);
489 if (found
!= _idxCache
.end())
490 return _icons
[found
->second
];
494 if ((int)ExtractIconEx(path
, idx
, NULL
, &hIcon
, 1) > 0) {
495 const Icon
& icon
= add(hIcon
, IT_CACHED
);
497 _idxCache
[key
] = icon
;
502 ///@todo retreive "http://.../favicon.ico" format icons
504 return _icons
[ICID_NONE
];
508 const Icon
& IconCache::extract(IExtractIcon
* pExtract
, LPCTSTR path
, int idx
, ICONCACHE_FLAGS flags
)
510 HICON hIconLarge
= 0;
513 bool large_icons
= flags
& ICF_LARGE
;
514 HRESULT hr
= pExtract
->Extract(path
, idx
, &hIconLarge
, &hIcon
, MAKELONG(GetSystemMetrics(SM_CXICON
), ICON_SIZE_X
));
516 if (hr
== NOERROR
) { //@@ oder SUCCEEDED(hr) ?
517 if (large_icons
) { //@@ OK?
524 DestroyIcon(hIconLarge
);
528 return add(hIcon
); //@@ When do we want not to free this icons?
531 return _icons
[ICID_NONE
];
534 const Icon
& IconCache::add(HICON hIcon
, ICON_TYPE type
)
536 int id
= ++s_next_id
;
538 return _icons
[id
] = Icon(type
, id
, hIcon
);
541 const Icon
& IconCache::add(int sys_idx
/*, ICON_TYPE type=IT_SYSCACHE*/)
543 int id
= ++s_next_id
;
545 return _icons
[id
] = SysCacheIcon(id
, sys_idx
);
548 const Icon
& IconCache::get_icon(int id
)
553 void IconCache::free_icon(int icon_id
)
555 IconMap::iterator found
= _icons
.find(icon_id
);
557 if (found
!= _icons
.end()) {
558 Icon
& icon
= found
->second
;
566 ResString::ResString(UINT nid
)
568 TCHAR buffer
[BUFFER_LEN
];
570 int len
= LoadString(g_Globals
._hInstance
, nid
, buffer
, sizeof(buffer
)/sizeof(TCHAR
));
572 super::assign(buffer
, len
);
576 ResIcon::ResIcon(UINT nid
)
578 _hicon
= LoadIcon(g_Globals
._hInstance
, MAKEINTRESOURCE(nid
));
581 SmallIcon::SmallIcon(UINT nid
)
583 _hicon
= (HICON
)LoadImage(g_Globals
._hInstance
, MAKEINTRESOURCE(nid
), IMAGE_ICON
, GetSystemMetrics(SM_CXSMICON
), GetSystemMetrics(SM_CYSMICON
), LR_SHARED
);
586 ResIconEx::ResIconEx(UINT nid
, int w
, int h
)
588 _hicon
= (HICON
)LoadImage(g_Globals
._hInstance
, MAKEINTRESOURCE(nid
), IMAGE_ICON
, w
, h
, LR_SHARED
);
592 void SetWindowIcon(HWND hwnd
, UINT nid
)
594 HICON hIcon
= ResIcon(nid
);
595 (void)Window_SetIcon(hwnd
, ICON_BIG
, hIcon
);
597 HICON hIconSmall
= SmallIcon(nid
);
598 (void)Window_SetIcon(hwnd
, ICON_SMALL
, hIconSmall
);
602 ResBitmap::ResBitmap(UINT nid
)
604 _hBmp
= LoadBitmap(g_Globals
._hInstance
, MAKEINTRESOURCE(nid
));
610 void explorer_show_frame(int cmdShow
, LPTSTR lpCmdLine
)
614 if (g_Globals
._hMainWnd
) {
615 if (IsIconic(g_Globals
._hMainWnd
))
616 ShowWindow(g_Globals
._hMainWnd
, SW_RESTORE
);
618 SetForegroundWindow(g_Globals
._hMainWnd
);
623 g_Globals
._prescan_nodes
= false;
625 XMLPos explorer_options
= g_Globals
.get_cfg("general/explorer");
626 XS_String mdiStr
= XMLString(explorer_options
, "mdi");
628 // If there isn't yet the "mdi" setting in the configuration, display MDI/SDI dialog.
630 Dialog::DoModal(IDD_MDI_SDI
, WINDOW_CREATOR(MdiSdiDlg
), g_Globals
._hwndDesktop
);
632 // Now read the MDI attribute again and interpret it as boolean value.
633 cmd
._mdi
= XMLBool(explorer_options
, "mdi", true);
635 cmd
._cmdShow
= cmdShow
;
637 // parse command line options, which may overwrite the MDI flag
639 cmd
.ParseCmdLine(lpCmdLine
);
641 // create main window
642 MainFrameBase::Create(cmd
);
645 bool ExplorerCmd::ParseCmdLine(LPCTSTR lpCmdLine
)
649 LPCTSTR b
= lpCmdLine
;
653 // remove leading space
654 while(_istspace((unsigned)*b
))
661 // options are separated by ','
663 if (*p
== '"') // Quote characters may appear at any position in the command line.
665 else if (*p
==',' && !quote
)
672 // remove trailing space
673 while(l
>0 && _istspace((unsigned)b
[l
-1]))
676 if (!EvaluateOption(String(b
, l
)))
689 bool ExplorerCmd::EvaluateOption(LPCTSTR option
)
693 // Remove quote characters, as they are evaluated at this point.
694 for(; *option
; ++option
)
700 if (option
[0] == '/') {
703 // option /e for windows in explorer mode
704 if (!_tcsicmp(option
, TEXT("e")))
705 _flags
|= OWM_EXPLORE
;
706 // option /root for rooted explorer windows
707 else if (!_tcsicmp(option
, TEXT("root")))
708 _flags
|= OWM_ROOTED
;
709 // non-standard options: /mdi, /sdi
710 else if (!_tcsicmp(option
, TEXT("mdi")))
712 else if (!_tcsicmp(option
, TEXT("sdi")))
726 bool ExplorerCmd::IsValidPath() const
728 if (!_path
.empty()) {
729 DWORD attribs
= GetFileAttributes(_path
);
731 if (attribs
!=INVALID_FILE_ATTRIBUTES
&& (attribs
&FILE_ATTRIBUTE_DIRECTORY
))
732 return true; // file system path
733 else if (*_path
==':' && _path
.at(1)==':')
734 return true; // text encoded IDL
742 void explorer_show_frame(int cmdShow
, LPTSTR lpCmdLine
)
745 lpCmdLine
= TEXT("explorer.exe");
747 launch_file(GetDesktopWindow(), lpCmdLine
, cmdShow
);
753 PopupMenu::PopupMenu(UINT nid
)
755 HMENU hMenu
= LoadMenu(g_Globals
._hInstance
, MAKEINTRESOURCE(nid
));
756 _hmenu
= GetSubMenu(hMenu
, 0);
760 /// "About Explorer" Dialog
761 struct ExplorerAboutDlg
: public
763 OwnerDrawParent
<Dialog
>
766 typedef CtlColorParent
<
767 OwnerDrawParent
<Dialog
>
770 ExplorerAboutDlg(HWND hwnd
)
773 SetWindowIcon(hwnd
, IDI_REACTOS
);
775 new FlatButton(hwnd
, IDOK
);
777 _hfont
= CreateFont(20, 0, 0, 0, FW_BOLD
, TRUE
, 0, 0, 0, 0, 0, 0, 0, TEXT("Sans Serif"));
778 new ColorStatic(hwnd
, IDC_ROS_EXPLORER
, RGB(32,32,128), 0, _hfont
);
780 new HyperlinkCtrl(hwnd
, IDC_WWW
);
782 FmtString
ver_txt(ResString(IDS_EXPLORER_VERSION_STR
), (LPCTSTR
)ResString(IDS_VERSION_STR
));
783 SetWindowText(GetDlgItem(hwnd
, IDC_VERSION_TXT
), ver_txt
);
785 HWND hwnd_winver
= GetDlgItem(hwnd
, IDC_WIN_VERSION
);
786 SetWindowText(hwnd_winver
, get_windows_version_str());
787 SetWindowFont(hwnd_winver
, GetStockFont(DEFAULT_GUI_FONT
), FALSE
);
794 DeleteObject(_hfont
);
797 LRESULT
WndProc(UINT nmsg
, WPARAM wparam
, LPARAM lparam
)
805 return super::WndProc(nmsg
, wparam
, lparam
);
813 PaintCanvas
canvas(_hwnd
);
815 HICON hicon
= (HICON
) LoadImage(g_Globals
._hInstance
, MAKEINTRESOURCE(IDI_REACTOS_BIG
), IMAGE_ICON
, 0, 0, LR_SHARED
);
817 DrawIconEx(canvas
, 20, 10, hicon
, 0, 0, 0, 0, DI_NORMAL
);
824 void explorer_about(HWND hwndParent
)
826 Dialog::DoModal(IDD_ABOUT_EXPLORER
, WINDOW_CREATOR(ExplorerAboutDlg
), hwndParent
);
830 static void InitInstance(HINSTANCE hInstance
)
832 CONTEXT("InitInstance");
834 setlocale(LC_COLLATE
, ""); // set collating rules to local settings for compareName
837 // register frame window class
838 g_Globals
._hframeClass
= IconWindowClass(CLASSNAME_FRAME
,IDI_EXPLORER
);
840 // register child window class
841 WindowClass(CLASSNAME_CHILDWND
, CS_CLASSDC
|CS_DBLCLKS
|CS_VREDRAW
).Register();
843 // register tree window class
844 WindowClass(CLASSNAME_WINEFILETREE
, CS_CLASSDC
|CS_DBLCLKS
|CS_VREDRAW
).Register();
847 g_Globals
._cfStrFName
= RegisterClipboardFormat(CFSTR_FILENAME
);
851 int explorer_main(HINSTANCE hInstance
, LPTSTR lpCmdLine
, int cmdShow
)
853 CONTEXT("explorer_main");
855 // initialize Common Controls library
856 CommonControlInit usingCmnCtrl
;
859 InitInstance(hInstance
);
860 } catch(COMException
& e
) {
861 HandleException(e
, GetDesktopWindow());
866 if (cmdShow
!= SW_HIDE
) {
867 /* // don't maximize if being called from the ROS desktop
868 if (cmdShow == SW_SHOWNORMAL)
869 ///@todo read window placement from registry
870 cmdShow = SW_MAXIMIZE;
873 explorer_show_frame(cmdShow
, lpCmdLine
);
877 return Window::MessageLoop();
881 // MinGW does not provide a Unicode startup routine, so we have to implement an own.
882 #if defined(__MINGW32__) && defined(UNICODE)
884 #define _tWinMain wWinMain
885 int WINAPI
wWinMain(HINSTANCE
, HINSTANCE
, LPWSTR
, int);
887 int main(int argc
, char* argv
[])
891 STARTUPINFO startupinfo
;
892 int nShowCmd
= SW_SHOWNORMAL
;
894 GetStartupInfo(&startupinfo
);
896 if (startupinfo
.dwFlags
& STARTF_USESHOWWINDOW
)
897 nShowCmd
= startupinfo
.wShowWindow
;
899 LPWSTR cmdline
= GetCommandLineW();
901 while(*cmdline
&& !_istspace((unsigned)*cmdline
))
904 while(_istspace((unsigned)*cmdline
))
907 return wWinMain(GetModuleHandle(NULL
), 0, cmdline
, nShowCmd
);
910 #endif // __MINGW && UNICODE
913 static bool SetShellReadyEvent(LPCTSTR evtName
)
915 HANDLE hEvent
= OpenEvent(EVENT_MODIFY_STATE
, FALSE
, evtName
);
926 int WINAPI
_tWinMain(HINSTANCE hInstance
, HINSTANCE hPrevInstance
, LPTSTR lpCmdLine
, int nShowCmd
)
928 CONTEXT("WinMain()");
930 BOOL any_desktop_running
= IsAnyDesktopRunning();
932 BOOL startup_desktop
;
934 // strip extended options from the front of the command line
937 while(*lpCmdLine
== '-') {
938 while(*lpCmdLine
&& !_istspace((unsigned)*lpCmdLine
))
939 ext_options
+= *lpCmdLine
++;
941 while(_istspace((unsigned)*lpCmdLine
))
945 // command line option "-install" to replace previous shell application with ROS Explorer
946 if (_tcsstr(ext_options
,TEXT("-install"))) {
947 // install ROS Explorer into the registry
948 TCHAR path
[MAX_PATH
];
950 int l
= GetModuleFileName(0, path
, COUNTOF(path
));
954 if (!RegOpenKey(HKEY_LOCAL_MACHINE
, TEXT("SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Winlogon"), &hkey
)) {
956 ///@todo save previous shell application in config file
958 RegSetValueEx(hkey
, TEXT("Shell"), 0, REG_SZ
, (LPBYTE
)path
, l
*sizeof(TCHAR
));
962 if (!RegOpenKey(HKEY_CURRENT_USER
, TEXT("SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Winlogon"), &hkey
)) {
964 ///@todo save previous shell application in config file
966 RegSetValueEx(hkey
, TEXT("Shell"), 0, REG_SZ
, (LPBYTE
)TEXT(""), l
*sizeof(TCHAR
));
971 HWND shellWindow
= GetShellWindow();
976 // terminate shell process for NT like systems
977 GetWindowThreadProcessId(shellWindow
, &pid
);
978 HANDLE hProcess
= OpenProcess(PROCESS_ALL_ACCESS
, FALSE
, pid
);
980 // On Win 9x it's sufficient to destroy the shell window.
981 DestroyWindow(shellWindow
);
983 if (TerminateProcess(hProcess
, 0))
984 WaitForSingleObject(hProcess
, INFINITE
);
986 CloseHandle(hProcess
);
989 startup_desktop
= TRUE
;
991 // create desktop window and task bar only, if there is no other shell and we are
992 // the first explorer instance
993 // MS Explorer looks additionally into the registry entry HKCU\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon\shell,
994 // to decide wether it is currently configured as shell application.
995 startup_desktop
= !any_desktop_running
;
999 bool autostart
= !any_desktop_running
;
1001 // disable autostart if the SHIFT key is pressed
1002 if (GetAsyncKeyState(VK_SHIFT
) < 0)
1005 #ifdef _DEBUG //MF: disabled for debugging
1009 // If there is given the command line option "-desktop", create desktop window anyways
1010 if (_tcsstr(ext_options
,TEXT("-desktop")))
1011 startup_desktop
= TRUE
;
1013 else if (_tcsstr(ext_options
,TEXT("-nodesktop")))
1014 startup_desktop
= FALSE
;
1016 // Don't display cabinet window in desktop mode
1017 if (startup_desktop
&& !_tcsstr(ext_options
,TEXT("-explorer")))
1021 if (_tcsstr(ext_options
,TEXT("-noautostart")))
1023 else if (_tcsstr(ext_options
,TEXT("-autostart")))
1027 if (_tcsstr(ext_options
,TEXT("-console"))) {
1030 _dup2(_open_osfhandle((long)GetStdHandle(STD_INPUT_HANDLE
), _O_RDONLY
), 0);
1031 _dup2(_open_osfhandle((long)GetStdHandle(STD_OUTPUT_HANDLE
), 0), 1);
1032 _dup2(_open_osfhandle((long)GetStdHandle(STD_ERROR_HANDLE
), 0), 2);
1034 g_Globals
._log
= _fdopen(1, "w");
1035 setvbuf(g_Globals
._log
, 0, _IONBF
, 0);
1037 LOG(TEXT("starting explorer debug log\n"));
1042 if (startup_desktop
) {
1043 // hide the XP login screen (Credit to Nicolas Escuder)
1044 // another undocumented event: "Global\\msgina: ReturnToWelcome"
1045 if (!SetShellReadyEvent(TEXT("msgina: ShellReadyEvent")))
1046 SetShellReadyEvent(TEXT("Global\\msgina: ShellReadyEvent"));
1050 return 0; // no shell to launch, so exit immediatelly
1054 if (!any_desktop_running
) {
1055 // launch the shell DDE server
1056 if (g_SHDOCVW_ShellDDEInit
)
1057 (*g_SHDOCVW_ShellDDEInit
)(TRUE
);
1061 bool use_gdb_stub
= false; // !IsDebuggerPresent();
1063 if (_tcsstr(ext_options
,TEXT("-debug")))
1064 use_gdb_stub
= true;
1066 if (_tcsstr(ext_options
,TEXT("-break"))) {
1067 LOG(TEXT("debugger breakpoint"));
1075 // activate GDB remote debugging stub if no other debugger is running
1077 LOG(TEXT("waiting for debugger connection...\n"));
1079 initialize_gdb_stub();
1082 g_Globals
.init(hInstance
);
1084 // initialize COM and OLE before creating the desktop window
1087 // init common controls library
1088 CommonControlInit usingCmnCtrl
;
1090 g_Globals
.read_persistent();
1092 if (startup_desktop
) {
1095 g_Globals
._desktops
.init();
1097 g_Globals
._hwndDesktop
= DesktopWindow::Create();
1099 g_Globals
._desktops
.get_current_Desktop()->_hwndDesktop
= g_Globals
._hwndDesktop
;
1103 Thread
* pSSOThread
= NULL
;
1105 if (startup_desktop
) {
1106 // launch SSO thread to allow message processing independent from the explorer main thread
1107 pSSOThread
= new SSOThread
;
1108 pSSOThread
->Start();
1111 /**TODO launching autostart programs can be moved into a background thread. */
1113 char* argv
[] = {"", "s"}; // call startup routine in SESSION_START mode
1118 if (g_Globals
._hwndDesktop
)
1119 g_Globals
._desktop_mode
= true;
1123 int ret
= explorer_main(hInstance
, lpCmdLine
, nShowCmd
);
1126 // write configuration file
1127 g_Globals
.write_persistent();
1134 if (!any_desktop_running
) {
1135 // shutdown the shell DDE server
1136 if (g_SHDOCVW_ShellDDEInit
)
1137 (*g_SHDOCVW_ShellDDEInit
)(FALSE
);