2 * Copyright 2003, 2004, 2005, 2006 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 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_file(_cfg_path
)) {
97 if (!_cfg
._errors
.empty())
98 MessageBox(_hwndDesktop
, _cfg
._errors
.str(),
99 TEXT("ROS Explorer - reading user settings"), MB_OK
);
101 _cfg
.read_file(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_file(_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
;
231 if (entry
->_display_name
!= entry
->_data
.cFileName
)
232 free(entry
->_display_name
);
234 entry
->_display_name
= (LPTSTR
) malloc((len
+1)*sizeof(TCHAR
));
235 lstrcpyn(entry
->_display_name
, entry
->_data
.cFileName
, len
+ 1);
238 if (is_exe_file(ext
))
239 entry
->_data
.dwFileAttributes
|= ATTRIBUTE_EXECUTABLE
;
253 Icon::Icon(ICON_ID id
, UINT nid
) //, int cx, int cy
256 _hicon(ResIcon(nid
)) // ResIconEx(nid, cx, cy)
260 Icon::Icon(ICON_ID id
, UINT nid
, int icon_size
)
263 _hicon(ResIconEx(nid
, icon_size
, icon_size
))
267 Icon::Icon(ICON_TYPE itype
, int id
, HICON hIcon
)
274 Icon::Icon(ICON_TYPE itype
, int id
, int sys_idx
)
281 void Icon::draw(HDC hdc
, int x
, int y
, int cx
, int cy
, COLORREF bk_color
, HBRUSH bk_brush
) const
283 if (_itype
== IT_SYSCACHE
)
284 ImageList_DrawEx(g_Globals
._icon_cache
.get_sys_imagelist(), _sys_idx
, hdc
, x
, y
, cx
, cy
, bk_color
, CLR_DEFAULT
, ILD_NORMAL
);
286 DrawIconEx(hdc
, x
, y
, _hicon
, cx
, cy
, 0, bk_brush
, DI_NORMAL
);
289 HBITMAP
Icon::create_bitmap(COLORREF bk_color
, HBRUSH hbrBkgnd
, HDC hdc_wnd
) const
291 if (_itype
== IT_SYSCACHE
) {
292 HIMAGELIST himl
= g_Globals
._icon_cache
.get_sys_imagelist();
295 ImageList_GetIconSize(himl
, &cx
, &cy
);
297 HBITMAP hbmp
= CreateCompatibleBitmap(hdc_wnd
, cx
, cy
);
298 HDC hdc
= CreateCompatibleDC(hdc_wnd
);
299 HBITMAP hbmp_old
= SelectBitmap(hdc
, hbmp
);
300 ImageList_DrawEx(himl
, _sys_idx
, hdc
, 0, 0, cx
, cy
, bk_color
, CLR_DEFAULT
, ILD_NORMAL
);
301 SelectBitmap(hdc
, hbmp_old
);
306 return create_bitmap_from_icon(_hicon
, hbrBkgnd
, hdc_wnd
);
310 int Icon::add_to_imagelist(HIMAGELIST himl
, HDC hdc_wnd
, COLORREF bk_color
, HBRUSH bk_brush
) const
314 if (_itype
== IT_SYSCACHE
) {
315 HIMAGELIST himl
= g_Globals
._icon_cache
.get_sys_imagelist();
318 ImageList_GetIconSize(himl
, &cx
, &cy
);
320 HBITMAP hbmp
= CreateCompatibleBitmap(hdc_wnd
, cx
, cy
);
321 HDC hdc
= CreateCompatibleDC(hdc_wnd
);
322 HBITMAP hbmp_old
= SelectBitmap(hdc
, hbmp
);
323 ImageList_DrawEx(himl
, _sys_idx
, hdc
, 0, 0, cx
, cy
, bk_color
, CLR_DEFAULT
, ILD_NORMAL
);
324 SelectBitmap(hdc
, hbmp_old
);
327 ret
= ImageList_Add(himl
, hbmp
, 0);
331 ret
= ImageList_AddAlphaIcon(himl
, _hicon
, bk_brush
, hdc_wnd
);
336 HBITMAP
create_bitmap_from_icon(HICON hIcon
, HBRUSH hbrush_bkgnd
, HDC hdc_wnd
/*, int icon_size*/)
338 int cx
= ICON_SIZE_SMALL
;
339 int cy
= ICON_SIZE_SMALL
;
340 HBITMAP hbmp
= CreateCompatibleBitmap(hdc_wnd
, cx
, cy
);
343 BitmapSelection
sel(canvas
, hbmp
);
345 RECT rect
= {0, 0, cx
, cy
};
346 FillRect(canvas
, &rect
, hbrush_bkgnd
);
348 DrawIconEx(canvas
, 0, 0, hIcon
, cx
, cy
, 0, hbrush_bkgnd
, DI_NORMAL
);
353 HBITMAP
create_small_bitmap_from_icon(HICON hIcon
, HBRUSH hbrush_bkgnd
, HDC hdc_wnd
)
355 int cx
= GetSystemMetrics(SM_CXSMICON
);
356 int cy
= GetSystemMetrics(SM_CYSMICON
);
357 HBITMAP hbmp
= CreateCompatibleBitmap(hdc_wnd
, cx
, cy
);
360 BitmapSelection
sel(canvas
, hbmp
);
362 RECT rect
= {0, 0, cx
, cy
};
363 FillRect(canvas
, &rect
, hbrush_bkgnd
);
365 DrawIconEx(canvas
, 0, 0, hIcon
, cx
, cy
, 0, hbrush_bkgnd
, DI_NORMAL
);
370 int ImageList_AddAlphaIcon(HIMAGELIST himl
, HICON hIcon
, HBRUSH hbrush_bkgnd
, HDC hdc_wnd
)
372 HBITMAP hbmp
= create_bitmap_from_icon(hIcon
, hbrush_bkgnd
, hdc_wnd
);
374 int ret
= ImageList_Add(himl
, hbmp
, 0);
382 int IconCache::s_next_id
= ICID_DYNAMIC
;
385 void IconCache::init()
387 int icon_size
= STARTMENUROOT_ICON_SIZE
;
389 _icons
[ICID_NONE
] = Icon(IT_STATIC
, ICID_NONE
, (HICON
)0);
391 _icons
[ICID_FOLDER
] = Icon(ICID_FOLDER
, IDI_FOLDER
);
392 //_icons[ICID_DOCUMENT] = Icon(ICID_DOCUMENT, IDI_DOCUMENT);
393 _icons
[ICID_EXPLORER
] = Icon(ICID_EXPLORER
, IDI_EXPLORER
);
394 // _icons[ICID_APP] = Icon(ICID_APP, IDI_APPICON);
396 _icons
[ICID_CONFIG
] = Icon(ICID_CONFIG
, IDI_CONFIG
, icon_size
);
397 _icons
[ICID_DOCUMENTS
] = Icon(ICID_DOCUMENTS
, IDI_DOCUMENTS
, icon_size
);
398 _icons
[ICID_FAVORITES
] = Icon(ICID_FAVORITES
, IDI_FAVORITES
, icon_size
);
399 _icons
[ICID_INFO
] = Icon(ICID_INFO
, IDI_INFO
, icon_size
);
400 _icons
[ICID_APPS
] = Icon(ICID_APPS
, IDI_APPS
, icon_size
);
401 _icons
[ICID_SEARCH
] = Icon(ICID_SEARCH
, IDI_SEARCH
, icon_size
);
402 _icons
[ICID_ACTION
] = Icon(ICID_ACTION
, IDI_ACTION
, icon_size
);
403 _icons
[ICID_SEARCH_DOC
] = Icon(ICID_SEARCH_DOC
, IDI_SEARCH_DOC
, icon_size
);
404 _icons
[ICID_PRINTER
] = Icon(ICID_PRINTER
, IDI_PRINTER
, icon_size
);
405 _icons
[ICID_NETWORK
] = Icon(ICID_NETWORK
, IDI_NETWORK
, icon_size
);
406 _icons
[ICID_COMPUTER
] = Icon(ICID_COMPUTER
, IDI_COMPUTER
, icon_size
);
407 _icons
[ICID_LOGOFF
] = Icon(ICID_LOGOFF
, IDI_LOGOFF
, icon_size
);
408 _icons
[ICID_SHUTDOWN
] = Icon(ICID_SHUTDOWN
, IDI_SHUTDOWN
, icon_size
);
409 _icons
[ICID_RESTART
] = Icon(ICID_RESTART
, IDI_RESTART
, icon_size
);
410 _icons
[ICID_BOOKMARK
] = Icon(ICID_BOOKMARK
, IDI_DOT_TRANS
, icon_size
);
411 _icons
[ICID_MINIMIZE
] = Icon(ICID_MINIMIZE
, IDI_MINIMIZE
, icon_size
);
412 _icons
[ICID_CONTROLPAN
] = Icon(ICID_CONTROLPAN
, IDI_CONTROLPAN
, icon_size
);
413 _icons
[ICID_DESKSETTING
]= Icon(ICID_DESKSETTING
,IDI_DESKSETTING
,icon_size
);
414 _icons
[ICID_NETCONNS
] = Icon(ICID_NETCONNS
, IDI_NETCONNS
, icon_size
);
415 _icons
[ICID_ADMIN
] = Icon(ICID_ADMIN
, IDI_ADMIN
, icon_size
);
416 _icons
[ICID_RECENT
] = Icon(ICID_RECENT
, IDI_RECENT
, icon_size
);
420 const Icon
& IconCache::extract(LPCTSTR path
, ICONCACHE_FLAGS flags
)
422 // search for matching icon with unchanged flags in the cache
423 CacheKey
mapkey(path
, flags
);
424 PathCacheMap::iterator found
= _pathCache
.find(mapkey
);
426 if (found
!= _pathCache
.end())
427 return _icons
[found
->second
];
429 // search for matching icon with handle
430 CacheKey
mapkey_hicon(path
, flags
|ICF_HICON
);
431 if (flags
!= mapkey_hicon
.second
) {
432 found
= _pathCache
.find(mapkey_hicon
);
434 if (found
!= _pathCache
.end())
435 return _icons
[found
->second
];
438 // search for matching icon in the system image list cache
439 CacheKey
mapkey_syscache(path
, flags
|ICF_SYSCACHE
);
440 if (flags
!= mapkey_syscache
.second
) {
441 found
= _pathCache
.find(mapkey_syscache
);
443 if (found
!= _pathCache
.end())
444 return _icons
[found
->second
];
451 if (flags
& ICF_OPEN
)
452 shgfi_flags
|= SHGFI_OPENICON
;
454 if ((flags
&(ICF_LARGE
|ICF_MIDDLE
|ICF_OVERLAYS
|ICF_HICON
)) && !(flags
&ICF_SYSCACHE
)) {
455 shgfi_flags
|= SHGFI_ICON
;
457 if (!(flags
& (ICF_LARGE
|ICF_MIDDLE
)))
458 shgfi_flags
|= SHGFI_SMALLICON
;
460 if (flags
& ICF_OVERLAYS
)
461 shgfi_flags
|= SHGFI_ADDOVERLAYS
;
463 // get small/big icons with/without overlays
464 if (SHGetFileInfo(path
, 0, &sfi
, sizeof(sfi
), shgfi_flags
)) {
465 const Icon
& icon
= add(sfi
.hIcon
, IT_CACHED
);
467 ///@todo limit cache size
468 _pathCache
[mapkey_hicon
] = icon
;
473 assert(!(flags
&ICF_OVERLAYS
));
475 shgfi_flags
|= SHGFI_SYSICONINDEX
|SHGFI_SMALLICON
;
477 // use system image list - the "search program dialog" needs it
478 HIMAGELIST himlSys_small
= (HIMAGELIST
) SHGetFileInfo(path
, 0, &sfi
, sizeof(sfi
), shgfi_flags
);
481 _himlSys_small
= himlSys_small
;
483 const Icon
& icon
= add(sfi
.iIcon
/*, IT_SYSCACHE*/);
485 ///@todo limit cache size
486 _pathCache
[mapkey_syscache
] = icon
;
492 return _icons
[ICID_NONE
];
495 const Icon
& IconCache::extract(LPCTSTR path
, int icon_idx
, ICONCACHE_FLAGS flags
)
497 IdxCacheKey
key(path
, make_pair(icon_idx
, (flags
|ICF_HICON
)&~ICF_SYSCACHE
));
501 IdxCacheMap::iterator found
= _idxCache
.find(key
);
503 if (found
!= _idxCache
.end())
504 return _icons
[found
->second
];
508 if ((int)ExtractIconEx(path
, icon_idx
, NULL
, &hIcon
, 1) > 0) {
509 const Icon
& icon
= add(hIcon
, IT_CACHED
);
511 _idxCache
[key
] = icon
;
516 ///@todo retreive "http://.../favicon.ico" format icons
518 return _icons
[ICID_NONE
];
522 const Icon
& IconCache::extract(IExtractIcon
* pExtract
, LPCTSTR path
, int icon_idx
, ICONCACHE_FLAGS flags
)
524 HICON hIconLarge
= 0;
527 int icon_size
= ICON_SIZE_FROM_ICF(flags
);
528 HRESULT hr
= pExtract
->Extract(path
, icon_idx
, &hIconLarge
, &hIcon
, MAKELONG(GetSystemMetrics(SM_CXICON
), icon_size
));
530 if (hr
== NOERROR
) { //@@ oder SUCCEEDED(hr) ?
531 if (icon_size
> ICON_SIZE_SMALL
) { //@@ OK?
538 DestroyIcon(hIconLarge
);
542 return add(hIcon
); //@@ When do we want not to free this icons?
545 return _icons
[ICID_NONE
];
548 const Icon
& IconCache::extract(LPCITEMIDLIST pidl
, ICONCACHE_FLAGS flags
)
550 // search for matching icon with unchanged flags in the cache
551 PidlCacheKey
mapkey(pidl
, flags
);
552 PidlCacheMap::iterator found
= _pidlcache
.find(mapkey
);
554 if (found
!= _pidlcache
.end())
555 return _icons
[found
->second
];
557 // search for matching icon with handle
558 PidlCacheKey
mapkey_hicon(pidl
, flags
|ICF_HICON
);
559 if (flags
!= mapkey_hicon
.second
) {
560 found
= _pidlcache
.find(mapkey_hicon
);
562 if (found
!= _pidlcache
.end())
563 return _icons
[found
->second
];
566 // search for matching icon in the system image list cache
567 PidlCacheKey
mapkey_syscache(pidl
, flags
|ICF_SYSCACHE
);
568 if (flags
!= mapkey_syscache
.second
) {
569 found
= _pidlcache
.find(mapkey_syscache
);
571 if (found
!= _pidlcache
.end())
572 return _icons
[found
->second
];
577 int shgfi_flags
= SHGFI_PIDL
;
579 if (!(flags
& (ICF_LARGE
|ICF_MIDDLE
)))
580 shgfi_flags
|= SHGFI_SMALLICON
;
582 if (flags
& ICF_OPEN
)
583 shgfi_flags
|= SHGFI_OPENICON
;
585 if (flags
& ICF_SYSCACHE
) {
586 assert(!(flags
&ICF_OVERLAYS
));
588 HIMAGELIST himlSys
= (HIMAGELIST
) SHGetFileInfo((LPCTSTR
)pidl
, 0, &sfi
, sizeof(sfi
), SHGFI_SYSICONINDEX
|shgfi_flags
);
590 const Icon
& icon
= add(sfi
.iIcon
/*, IT_SYSCACHE*/);
592 ///@todo limit cache size
593 _pidlcache
[mapkey_syscache
] = icon
;
598 if (flags
& ICF_OVERLAYS
)
599 shgfi_flags
|= SHGFI_ADDOVERLAYS
;
601 if (SHGetFileInfo((LPCTSTR
)pidl
, 0, &sfi
, sizeof(sfi
), SHGFI_ICON
|shgfi_flags
)) {
602 const Icon
& icon
= add(sfi
.hIcon
, IT_CACHED
);
604 ///@todo limit cache size
605 _pidlcache
[mapkey_hicon
] = icon
;
611 return _icons
[ICID_NONE
];
615 const Icon
& IconCache::add(HICON hIcon
, ICON_TYPE type
)
617 int id
= ++s_next_id
;
619 return _icons
[id
] = Icon(type
, id
, hIcon
);
622 const Icon
& IconCache::add(int sys_idx
/*, ICON_TYPE type=IT_SYSCACHE*/)
624 int id
= ++s_next_id
;
626 return _icons
[id
] = SysCacheIcon(id
, sys_idx
);
629 const Icon
& IconCache::get_icon(int id
)
634 IconCache::~IconCache()
636 /* We don't need to free cached resources - they are automatically freed at process termination
637 for (int index = s_next_id; index >= 0; index--) {
638 IconMap::iterator found = _icons.find(index);
640 if (found != _icons.end()) {
641 Icon& icon = found->second;
643 if ((icon.get_icontype() == IT_DYNAMIC) ||
644 (icon.get_icontype() == IT_CACHED))
646 DestroyIcon(icon.get_hicon());
654 void IconCache::free_icon(int icon_id
)
656 IconMap::iterator found
= _icons
.find(icon_id
);
658 if (found
!= _icons
.end()) {
659 Icon
& icon
= found
->second
;
667 ResString::ResString(UINT nid
)
669 TCHAR buffer
[BUFFER_LEN
];
671 int len
= LoadString(g_Globals
._hInstance
, nid
, buffer
, sizeof(buffer
)/sizeof(TCHAR
));
673 super::assign(buffer
, len
);
677 ResIcon::ResIcon(UINT nid
)
679 _hicon
= LoadIcon(g_Globals
._hInstance
, MAKEINTRESOURCE(nid
));
682 SmallIcon::SmallIcon(UINT nid
)
684 _hicon
= (HICON
)LoadImage(g_Globals
._hInstance
, MAKEINTRESOURCE(nid
), IMAGE_ICON
, GetSystemMetrics(SM_CXSMICON
), GetSystemMetrics(SM_CYSMICON
), LR_SHARED
);
687 ResIconEx::ResIconEx(UINT nid
, int w
, int h
)
689 _hicon
= (HICON
)LoadImage(g_Globals
._hInstance
, MAKEINTRESOURCE(nid
), IMAGE_ICON
, w
, h
, LR_SHARED
);
693 void SetWindowIcon(HWND hwnd
, UINT nid
)
695 HICON hIcon
= ResIcon(nid
);
696 (void)Window_SetIcon(hwnd
, ICON_BIG
, hIcon
);
698 HICON hIconSmall
= SmallIcon(nid
);
699 (void)Window_SetIcon(hwnd
, ICON_SMALL
, hIconSmall
);
703 ResBitmap::ResBitmap(UINT nid
)
705 _hBmp
= LoadBitmap(g_Globals
._hInstance
, MAKEINTRESOURCE(nid
));
711 void explorer_show_frame(int cmdShow
, LPTSTR lpCmdLine
)
715 if (g_Globals
._hMainWnd
) {
716 if (IsIconic(g_Globals
._hMainWnd
))
717 ShowWindow(g_Globals
._hMainWnd
, SW_RESTORE
);
719 SetForegroundWindow(g_Globals
._hMainWnd
);
724 g_Globals
._prescan_nodes
= false;
727 cmd
._cmdShow
= cmdShow
;
729 // parse command line options, which may overwrite the MDI flag
731 cmd
.ParseCmdLine(lpCmdLine
);
733 // create main window
734 MainFrameBase::Create(cmd
);
737 bool ExplorerCmd::ParseCmdLine(LPCTSTR lpCmdLine
)
741 LPCTSTR b
= lpCmdLine
;
745 // remove leading space
746 while(_istspace((unsigned)*b
))
753 // options are separated by ','
755 if (*p
== '"') // Quote characters may appear at any position in the command line.
757 else if (*p
==',' && !quote
)
764 // remove trailing space
765 while(l
>0 && _istspace((unsigned)b
[l
-1]))
768 if (!EvaluateOption(String(b
, l
)))
781 bool ExplorerCmd::EvaluateOption(LPCTSTR option
)
785 // Remove quote characters, as they are evaluated at this point.
786 for(; *option
; ++option
)
792 if (option
[0] == '/') {
795 // option /e for windows in explorer mode
796 if (!_tcsicmp(option
, TEXT("e")))
797 _flags
|= OWM_EXPLORE
;
798 // option /root for rooted explorer windows
799 else if (!_tcsicmp(option
, TEXT("root")))
800 _flags
|= OWM_ROOTED
;
801 // non-standard options: /mdi, /sdi
802 else if (!_tcsicmp(option
, TEXT("mdi")))
804 else if (!_tcsicmp(option
, TEXT("sdi")))
818 bool ExplorerCmd::IsValidPath() const
820 if (!_path
.empty()) {
821 DWORD attribs
= GetFileAttributes(_path
);
823 if (attribs
!=INVALID_FILE_ATTRIBUTES
&& (attribs
&FILE_ATTRIBUTE_DIRECTORY
))
824 return true; // file system path
825 else if (*_path
==':' && _path
.at(1)==':')
826 return true; // text encoded IDL
834 void explorer_show_frame(int cmdShow
, LPTSTR lpCmdLine
)
837 lpCmdLine
= TEXT("explorer.exe");
839 launch_file(GetDesktopWindow(), lpCmdLine
, cmdShow
);
845 PopupMenu::PopupMenu(UINT nid
)
847 HMENU hMenu
= LoadMenu(g_Globals
._hInstance
, MAKEINTRESOURCE(nid
));
848 _hmenu
= GetSubMenu(hMenu
, 0);
849 RemoveMenu(hMenu
, 0, MF_BYPOSITION
);
854 /// "About Explorer" Dialog
855 struct ExplorerAboutDlg
: public
857 OwnerDrawParent
<Dialog
>
860 typedef CtlColorParent
<
861 OwnerDrawParent
<Dialog
>
864 ExplorerAboutDlg(HWND hwnd
)
867 SetWindowIcon(hwnd
, IDI_REACTOS
);
869 new FlatButton(hwnd
, IDOK
);
871 _hfont
= CreateFont(20, 0, 0, 0, FW_BOLD
, TRUE
, 0, 0, 0, 0, 0, 0, 0, TEXT("Sans Serif"));
872 new ColorStatic(hwnd
, IDC_ROS_EXPLORER
, RGB(32,32,128), 0, _hfont
);
874 new HyperlinkCtrl(hwnd
, IDC_WWW
);
876 FmtString
ver_txt(ResString(IDS_EXPLORER_VERSION_STR
), (LPCTSTR
)ResString(IDS_VERSION_STR
));
877 SetWindowText(GetDlgItem(hwnd
, IDC_VERSION_TXT
), ver_txt
);
879 HWND hwnd_winver
= GetDlgItem(hwnd
, IDC_WIN_VERSION
);
880 SetWindowText(hwnd_winver
, get_windows_version_str());
881 SetWindowFont(hwnd_winver
, GetStockFont(DEFAULT_GUI_FONT
), FALSE
);
888 DeleteObject(_hfont
);
891 LRESULT
WndProc(UINT nmsg
, WPARAM wparam
, LPARAM lparam
)
899 return super::WndProc(nmsg
, wparam
, lparam
);
907 PaintCanvas
canvas(_hwnd
);
909 HICON hicon
= (HICON
) LoadImage(g_Globals
._hInstance
, MAKEINTRESOURCE(IDI_REACTOS_BIG
), IMAGE_ICON
, 0, 0, LR_SHARED
);
911 DrawIconEx(canvas
, 20, 10, hicon
, 0, 0, 0, 0, DI_NORMAL
);
918 void explorer_about(HWND hwndParent
)
920 Dialog::DoModal(IDD_ABOUT_EXPLORER
, WINDOW_CREATOR(ExplorerAboutDlg
), hwndParent
);
924 static void InitInstance(HINSTANCE hInstance
)
926 CONTEXT("InitInstance");
928 setlocale(LC_COLLATE
, ""); // set collating rules to local settings for compareName
931 // register frame window class
932 g_Globals
._hframeClass
= IconWindowClass(CLASSNAME_FRAME
,IDI_EXPLORER
);
934 // register child window class
935 WindowClass(CLASSNAME_CHILDWND
, CS_CLASSDC
|CS_DBLCLKS
|CS_VREDRAW
).Register();
937 // register tree window class
938 WindowClass(CLASSNAME_WINEFILETREE
, CS_CLASSDC
|CS_DBLCLKS
|CS_VREDRAW
).Register();
941 g_Globals
._cfStrFName
= RegisterClipboardFormat(CFSTR_FILENAME
);
945 int explorer_main(HINSTANCE hInstance
, LPTSTR lpCmdLine
, int cmdShow
)
947 CONTEXT("explorer_main");
949 // initialize Common Controls library
950 CommonControlInit usingCmnCtrl
;
953 InitInstance(hInstance
);
954 } catch(COMException
& e
) {
955 HandleException(e
, GetDesktopWindow());
960 if (cmdShow
!= SW_HIDE
) {
961 /* // don't maximize if being called from the ROS desktop
962 if (cmdShow == SW_SHOWNORMAL)
963 ///@todo read window placement from registry
964 cmdShow = SW_MAXIMIZE;
967 explorer_show_frame(cmdShow
, lpCmdLine
);
971 return Window::MessageLoop();
975 // MinGW does not provide a Unicode startup routine, so we have to implement an own.
976 #if defined(__MINGW32__) && defined(UNICODE)
978 #define _tWinMain wWinMain
979 int WINAPI
wWinMain(HINSTANCE
, HINSTANCE
, LPWSTR
, int);
981 int main(int argc
, char* argv
[])
985 STARTUPINFO startupinfo
;
986 int nShowCmd
= SW_SHOWNORMAL
;
988 GetStartupInfo(&startupinfo
);
990 if (startupinfo
.dwFlags
& STARTF_USESHOWWINDOW
)
991 nShowCmd
= startupinfo
.wShowWindow
;
993 LPWSTR cmdline
= GetCommandLineW();
995 while(*cmdline
&& !_istspace((unsigned)*cmdline
))
998 while(_istspace((unsigned)*cmdline
))
1001 return wWinMain(GetModuleHandle(NULL
), 0, cmdline
, nShowCmd
);
1004 #endif // __MINGW && UNICODE
1007 static bool SetShellReadyEvent(LPCTSTR evtName
)
1009 HANDLE hEvent
= OpenEvent(EVENT_MODIFY_STATE
, FALSE
, evtName
);
1014 CloseHandle(hEvent
);
1020 int WINAPI
_tWinMain(HINSTANCE hInstance
, HINSTANCE hPrevInstance
, LPTSTR lpCmdLine
, int nShowCmd
)
1022 CONTEXT("WinMain()");
1024 BOOL any_desktop_running
= IsAnyDesktopRunning();
1026 BOOL startup_desktop
;
1028 // strip extended options from the front of the command line
1031 while(*lpCmdLine
== '-') {
1032 while(*lpCmdLine
&& !_istspace((unsigned)*lpCmdLine
))
1033 ext_options
+= *lpCmdLine
++;
1035 while(_istspace((unsigned)*lpCmdLine
))
1039 // command line option "-install" to replace previous shell application with ROS Explorer
1040 if (_tcsstr(ext_options
,TEXT("-install"))) {
1041 // install ROS Explorer into the registry
1042 TCHAR path
[MAX_PATH
];
1044 int l
= GetModuleFileName(0, path
, COUNTOF(path
));
1048 if (!RegOpenKey(HKEY_LOCAL_MACHINE
, TEXT("SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Winlogon"), &hkey
)) {
1050 ///@todo save previous shell application in config file
1052 RegSetValueEx(hkey
, TEXT("Shell"), 0, REG_SZ
, (LPBYTE
)path
, l
*sizeof(TCHAR
));
1056 if (!RegOpenKey(HKEY_CURRENT_USER
, TEXT("SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Winlogon"), &hkey
)) {
1058 ///@todo save previous shell application in config file
1060 RegSetValueEx(hkey
, TEXT("Shell"), 0, REG_SZ
, (LPBYTE
)TEXT(""), l
*sizeof(TCHAR
));
1065 HWND shellWindow
= GetShellWindow();
1070 // terminate shell process for NT like systems
1071 GetWindowThreadProcessId(shellWindow
, &pid
);
1072 HANDLE hProcess
= OpenProcess(PROCESS_ALL_ACCESS
, FALSE
, pid
);
1074 // On Win 9x it's sufficient to destroy the shell window.
1075 DestroyWindow(shellWindow
);
1077 if (TerminateProcess(hProcess
, 0))
1078 WaitForSingleObject(hProcess
, INFINITE
);
1080 CloseHandle(hProcess
);
1083 startup_desktop
= TRUE
;
1085 // create desktop window and task bar only, if there is no other shell and we are
1086 // the first explorer instance
1087 // MS Explorer looks additionally into the registry entry HKCU\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon\shell,
1088 // to decide wether it is currently configured as shell application.
1089 startup_desktop
= !any_desktop_running
;
1093 bool autostart
= !any_desktop_running
;
1095 // disable autostart if the SHIFT key is pressed
1096 if (GetAsyncKeyState(VK_SHIFT
) < 0)
1099 #ifdef _DEBUG //MF: disabled for debugging
1103 // If there is given the command line option "-desktop", create desktop window anyways
1104 if (_tcsstr(ext_options
,TEXT("-desktop")))
1105 startup_desktop
= TRUE
;
1107 else if (_tcsstr(ext_options
,TEXT("-nodesktop")))
1108 startup_desktop
= FALSE
;
1110 // Don't display cabinet window in desktop mode
1111 if (startup_desktop
&& !_tcsstr(ext_options
,TEXT("-explorer")))
1115 if (_tcsstr(ext_options
,TEXT("-noautostart")))
1117 else if (_tcsstr(ext_options
,TEXT("-autostart")))
1121 if (_tcsstr(ext_options
,TEXT("-console"))) {
1124 _dup2(_open_osfhandle((long)GetStdHandle(STD_INPUT_HANDLE
), _O_RDONLY
), 0);
1125 _dup2(_open_osfhandle((long)GetStdHandle(STD_OUTPUT_HANDLE
), 0), 1);
1126 _dup2(_open_osfhandle((long)GetStdHandle(STD_ERROR_HANDLE
), 0), 2);
1128 g_Globals
._log
= _fdopen(1, "w");
1129 setvbuf(g_Globals
._log
, 0, _IONBF
, 0);
1131 LOG(TEXT("starting explorer debug log\n"));
1136 if (startup_desktop
) {
1137 // hide the XP login screen (Credit to Nicolas Escuder)
1138 // another undocumented event: "Global\\msgina: ReturnToWelcome"
1139 if (!SetShellReadyEvent(TEXT("msgina: ShellReadyEvent")))
1140 SetShellReadyEvent(TEXT("Global\\msgina: ShellReadyEvent"));
1144 return 0; // no shell to launch, so exit immediatelly
1148 if (!any_desktop_running
) {
1149 // launch the shell DDE server
1150 if (g_SHDOCVW_ShellDDEInit
)
1151 (*g_SHDOCVW_ShellDDEInit
)(TRUE
);
1155 bool use_gdb_stub
= false; // !IsDebuggerPresent();
1157 if (_tcsstr(ext_options
,TEXT("-debug")))
1158 use_gdb_stub
= true;
1160 if (_tcsstr(ext_options
,TEXT("-break"))) {
1161 LOG(TEXT("debugger breakpoint"));
1169 // activate GDB remote debugging stub if no other debugger is running
1171 LOG(TEXT("waiting for debugger connection...\n"));
1173 initialize_gdb_stub();
1176 g_Globals
.init(hInstance
);
1178 // initialize COM and OLE before creating the desktop window
1181 // init common controls library
1182 CommonControlInit usingCmnCtrl
;
1184 g_Globals
.read_persistent();
1186 if (startup_desktop
) {
1189 g_Globals
._desktops
.init();
1191 g_Globals
._hwndDesktop
= DesktopWindow::Create();
1193 g_Globals
._desktops
.get_current_Desktop()->_hwndDesktop
= g_Globals
._hwndDesktop
;
1197 if (_tcsstr(ext_options
,TEXT("-?"))) {
1198 MessageBoxA(g_Globals
._hwndDesktop
,
1199 "/e open cabinet window in explorer mode\r\n"
1200 "/root open cabinet window in rooted mode\r\n"
1201 "/mdi open cabinet window in MDI mode\r\n"
1202 "/sdi open cabinet window in SDI mode\r\n"
1204 "-? display command line options\r\n"
1206 "-desktop start in desktop mode regardless of an already running shell\r\n"
1207 "-nodesktop disable desktop mode\r\n"
1208 "-explorer display cabinet window regardless of enabled desktop mode\r\n"
1210 "-install replace previous shell application with ROS Explorer\r\n"
1212 "-noautostart disable autostarts\r\n"
1213 "-autostart enable autostarts regardless of debug build\r\n"
1215 "-console open debug console\r\n"
1217 "-debug activate GDB remote debugging stub\r\n"
1218 "-break activate debugger breakpoint\r\n",
1219 "ROS Explorer - command line options", MB_OK
);
1222 Thread
* pSSOThread
= NULL
;
1224 if (startup_desktop
) {
1225 // launch SSO thread to allow message processing independent from the explorer main thread
1226 pSSOThread
= new SSOThread
;
1227 pSSOThread
->Start();
1230 /**TODO launching autostart programs can be moved into a background thread. */
1232 const char* argv
[] = {"", "s"}; // call startup routine in SESSION_START mode
1237 if (g_Globals
._hwndDesktop
)
1238 g_Globals
._desktop_mode
= true;
1242 int ret
= explorer_main(hInstance
, lpCmdLine
, nShowCmd
);
1245 // write configuration file
1246 g_Globals
.write_persistent();
1253 if (!any_desktop_running
) {
1254 // shutdown the shell DDE server
1255 if (g_SHDOCVW_ShellDDEInit
)
1256 (*g_SHDOCVW_ShellDDEInit
)(FALSE
);