4 * Copyright 2004 CodeWeavers, Mike Hearn
5 * Copyright 2005,2006 CodeWeavers, Aric Stewart
6 * Copyright 2011 Jay Yang
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
25 #include "wine/unicode.h"
26 #include "wine/debug.h"
27 #include "wine/heap.h"
28 #include "explorer_private.h"
37 #include <commoncontrols.h>
40 WINE_DEFAULT_DEBUG_CHANNEL(explorer
);
42 #define EXPLORER_INFO_INDEX 0
44 #define NAV_TOOLBAR_HEIGHT 30
45 #define PATHBOX_HEIGHT 24
46 static int nav_toolbar_height
;
47 static int pathbox_height
;
49 #define DEFAULT_WIDTH 640
50 #define DEFAULT_HEIGHT 480
51 static int default_width
;
52 static int default_height
;
55 static const WCHAR EXPLORER_CLASS
[] = {'E','x','p','l','o','r','e','r','W','C','l','a','s','s',0};
56 static const WCHAR PATH_BOX_NAME
[] = {'\0'};
58 HINSTANCE explorer_hInstance
;
60 typedef struct parametersTAG
{
63 WCHAR selection
[MAX_PATH
];
68 IExplorerBrowser
*browser
;
69 HWND main_window
,path_box
;
72 IImageList
*icon_list
;
78 BACK_BUTTON
,FORWARD_BUTTON
,UP_BUTTON
83 IExplorerBrowserEvents IExplorerBrowserEvents_iface
;
86 } IExplorerBrowserEventsImpl
;
88 static IExplorerBrowserEventsImpl
*impl_from_IExplorerBrowserEvents(IExplorerBrowserEvents
*iface
)
90 return CONTAINING_RECORD(iface
, IExplorerBrowserEventsImpl
, IExplorerBrowserEvents_iface
);
93 static HRESULT WINAPI
IExplorerBrowserEventsImpl_fnQueryInterface(IExplorerBrowserEvents
*iface
, REFIID riid
, void **ppvObject
)
98 static ULONG WINAPI
IExplorerBrowserEventsImpl_fnAddRef(IExplorerBrowserEvents
*iface
)
100 IExplorerBrowserEventsImpl
*This
= impl_from_IExplorerBrowserEvents(iface
);
101 return InterlockedIncrement(&This
->ref
);
104 static ULONG WINAPI
IExplorerBrowserEventsImpl_fnRelease(IExplorerBrowserEvents
*iface
)
106 IExplorerBrowserEventsImpl
*This
= impl_from_IExplorerBrowserEvents(iface
);
107 ULONG ref
= InterlockedDecrement(&This
->ref
);
109 HeapFree(GetProcessHeap(),0,This
);
113 static BOOL
create_combobox_item(IShellFolder
*folder
, LPCITEMIDLIST child_pidl
, IImageList
*icon_list
, COMBOBOXEXITEMW
*item
)
117 PIDLIST_ABSOLUTE parent_pidl
, pidl
;
121 strret
.uType
=STRRET_WSTR
;
122 hres
= IShellFolder_GetDisplayNameOf( folder
, child_pidl
, SHGDN_FORADDRESSBAR
, &strret
);
124 hres
= StrRetToStrW(&strret
, child_pidl
, &item
->pszText
);
127 WINE_WARN("Could not get name for pidl\n");
131 item
->mask
&= ~CBEIF_IMAGE
;
132 hres
= SHGetIDListFromObject( (IUnknown
*)folder
, &parent_pidl
);
133 if (FAILED(hres
)) return FALSE
;
135 pidl
= ILCombine( parent_pidl
, child_pidl
);
138 list
= (IImageList
*)SHGetFileInfoW( (WCHAR
*)pidl
, 0, &info
, sizeof(info
),
139 SHGFI_PIDL
| SHGFI_SMALLICON
| SHGFI_SYSICONINDEX
);
142 IImageList_Release( list
);
143 item
->iImage
= info
.iIcon
;
144 item
->mask
|= CBEIF_IMAGE
;
148 ILFree( parent_pidl
);
153 static void update_path_box(explorer_info
*info
)
155 COMBOBOXEXITEMW item
;
156 COMBOBOXEXITEMW main_item
;
157 IShellFolder
*desktop
;
158 IPersistFolder2
*persist
;
159 LPITEMIDLIST desktop_pidl
;
162 SendMessageW(info
->path_box
,CB_RESETCONTENT
,0,0);
163 SHGetDesktopFolder(&desktop
);
164 IShellFolder_QueryInterface(desktop
,&IID_IPersistFolder2
,(void**)&persist
);
165 IPersistFolder2_GetCurFolder(persist
,&desktop_pidl
);
166 IPersistFolder2_Release(persist
);
170 item
.mask
= CBEIF_TEXT
| CBEIF_INDENT
| CBEIF_LPARAM
;
172 create_combobox_item(desktop
,desktop_pidl
,info
->icon_list
,&item
);
173 item
.lParam
= (LPARAM
)desktop_pidl
;
174 SendMessageW(info
->path_box
,CBEM_INSERTITEMW
,0,(LPARAM
)&item
);
175 if(ILIsEqual(info
->pidl
,desktop_pidl
))
178 CoTaskMemFree(item
.pszText
);
179 /*Add all direct subfolders of Desktop*/
180 if(SUCCEEDED(IShellFolder_EnumObjects(desktop
,NULL
,SHCONTF_FOLDERS
,&ids
))
183 LPITEMIDLIST curr_pidl
=NULL
;
191 hres
= IEnumIDList_Next(ids
,1,&curr_pidl
,NULL
);
192 if(FAILED(hres
) || hres
== S_FALSE
)
194 if(!create_combobox_item(desktop
,curr_pidl
,info
->icon_list
,&item
))
195 WINE_WARN("Could not create a combobox item\n");
198 LPITEMIDLIST full_pidl
= ILCombine(desktop_pidl
,curr_pidl
);
199 item
.lParam
= (LPARAM
)full_pidl
;
200 SendMessageW(info
->path_box
,CBEM_INSERTITEMW
,0,(LPARAM
)&item
);
201 if(ILIsEqual(full_pidl
,info
->pidl
))
203 else if(ILIsParent(full_pidl
,info
->pidl
,FALSE
))
205 /*add all parents of the pidl passed in*/
206 LPITEMIDLIST next_pidl
= ILFindChild(full_pidl
,info
->pidl
);
207 IShellFolder
*curr_folder
= NULL
, *temp
;
208 hres
= IShellFolder_BindToObject(desktop
,curr_pidl
,NULL
,
210 (void**)&curr_folder
);
212 WINE_WARN("Could not get an IShellFolder\n");
213 while(!ILIsEmpty(next_pidl
))
215 LPITEMIDLIST first
= ILCloneFirst(next_pidl
);
216 CoTaskMemFree(item
.pszText
);
217 if(!create_combobox_item(curr_folder
,first
,
218 info
->icon_list
,&item
))
220 WINE_WARN("Could not create a combobox item\n");
224 full_pidl
= ILCombine(full_pidl
,first
);
225 item
.lParam
= (LPARAM
)full_pidl
;
226 SendMessageW(info
->path_box
,CBEM_INSERTITEMW
,0,(LPARAM
)&item
);
228 hres
= IShellFolder_BindToObject(curr_folder
,first
,NULL
,
233 WINE_WARN("Could not get an IShellFolder\n");
236 IShellFolder_Release(curr_folder
);
240 next_pidl
= ILGetNext(next_pidl
);
242 memcpy(&main_item
,&item
,sizeof(item
));
244 IShellFolder_Release(curr_folder
);
248 CoTaskMemFree(item
.pszText
);
252 IEnumIDList_Release(ids
);
255 WINE_WARN("Could not enumerate the desktop\n");
256 SendMessageW(info
->path_box
,CBEM_SETITEMW
,0,(LPARAM
)&main_item
);
257 CoTaskMemFree(main_item
.pszText
);
260 static HRESULT WINAPI
IExplorerBrowserEventsImpl_fnOnNavigationComplete(IExplorerBrowserEvents
*iface
, PCIDLIST_ABSOLUTE pidl
)
262 IExplorerBrowserEventsImpl
*This
= impl_from_IExplorerBrowserEvents(iface
);
263 IShellFolder
*parent
;
264 PCUITEMID_CHILD child_pidl
;
269 ILFree(This
->info
->pidl
);
270 This
->info
->pidl
= ILClone(pidl
);
271 update_path_box(This
->info
);
273 hres
= SHBindToParent(pidl
, &IID_IShellFolder
, (void **)&parent
, &child_pidl
);
276 hres
= IShellFolder_GetDisplayNameOf(parent
, child_pidl
, SHGDN_FORADDRESSBAR
, &strret
);
278 hres
= StrRetToStrW(&strret
, child_pidl
, &name
);
281 SetWindowTextW(This
->info
->main_window
, name
);
285 IShellFolder_Release(parent
);
291 static HRESULT WINAPI
IExplorerBrowserEventsImpl_fnOnNavigationFailed(IExplorerBrowserEvents
*iface
, PCIDLIST_ABSOLUTE pidl
)
296 static HRESULT WINAPI
IExplorerBrowserEventsImpl_fnOnNavigationPending(IExplorerBrowserEvents
*iface
, PCIDLIST_ABSOLUTE pidl
)
301 static HRESULT WINAPI
IExplorerBrowserEventsImpl_fnOnViewCreated(IExplorerBrowserEvents
*iface
, IShellView
*psv
)
306 static IExplorerBrowserEventsVtbl vt_IExplorerBrowserEvents
=
308 IExplorerBrowserEventsImpl_fnQueryInterface
,
309 IExplorerBrowserEventsImpl_fnAddRef
,
310 IExplorerBrowserEventsImpl_fnRelease
,
311 IExplorerBrowserEventsImpl_fnOnNavigationPending
,
312 IExplorerBrowserEventsImpl_fnOnViewCreated
,
313 IExplorerBrowserEventsImpl_fnOnNavigationComplete
,
314 IExplorerBrowserEventsImpl_fnOnNavigationFailed
317 static IExplorerBrowserEvents
*make_explorer_events(explorer_info
*info
)
319 IExplorerBrowserEventsImpl
*ret
320 = HeapAlloc(GetProcessHeap(), 0, sizeof(IExplorerBrowserEventsImpl
));
321 ret
->IExplorerBrowserEvents_iface
.lpVtbl
= &vt_IExplorerBrowserEvents
;
324 SHGetImageList(SHIL_SMALL
,&IID_IImageList
,(void**)&(ret
->info
->icon_list
));
325 SendMessageW(info
->path_box
,CBEM_SETIMAGELIST
,0,(LPARAM
)ret
->info
->icon_list
);
326 return &ret
->IExplorerBrowserEvents_iface
;
329 static void make_explorer_window(IShellFolder
* startFolder
)
332 HWND rebar
,nav_toolbar
;
334 IExplorerBrowserEvents
*events
;
337 WCHAR explorer_title
[100];
338 WCHAR pathbox_label
[50];
339 TBADDBITMAP bitmap_info
;
340 TBBUTTON nav_buttons
[3];
341 int hist_offset
,view_offset
;
342 REBARBANDINFOW band_info
;
346 memset(nav_buttons
,0,sizeof(nav_buttons
));
348 LoadStringW(explorer_hInstance
,IDS_EXPLORER_TITLE
,explorer_title
, ARRAY_SIZE( explorer_title
));
349 LoadStringW(explorer_hInstance
,IDS_PATHBOX_LABEL
,pathbox_label
, ARRAY_SIZE( pathbox_label
));
352 dpix
= GetDeviceCaps(hdc
, LOGPIXELSX
);
353 dpiy
= GetDeviceCaps(hdc
, LOGPIXELSY
);
355 nav_toolbar_height
= MulDiv(NAV_TOOLBAR_HEIGHT
, dpiy
, USER_DEFAULT_SCREEN_DPI
);
356 pathbox_height
= MulDiv(PATHBOX_HEIGHT
, dpiy
, USER_DEFAULT_SCREEN_DPI
);
357 default_width
= MulDiv(DEFAULT_WIDTH
, dpix
, USER_DEFAULT_SCREEN_DPI
);
358 default_height
= MulDiv(DEFAULT_HEIGHT
, dpiy
, USER_DEFAULT_SCREEN_DPI
);
360 info
= HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY
,sizeof(explorer_info
));
363 WINE_ERR("Could not allocate an explorer_info struct\n");
366 hres
= CoCreateInstance(&CLSID_ExplorerBrowser
,NULL
,CLSCTX_INPROC_SERVER
,
367 &IID_IExplorerBrowser
,(LPVOID
*)&info
->browser
);
370 WINE_ERR("Could not obtain an instance of IExplorerBrowser\n");
371 HeapFree(GetProcessHeap(),0,info
);
374 info
->rebar_height
=0;
376 = CreateWindowW(EXPLORER_CLASS
,explorer_title
,WS_OVERLAPPEDWINDOW
,
377 CW_USEDEFAULT
,CW_USEDEFAULT
,default_width
,
378 default_height
,NULL
,NULL
,explorer_hInstance
,NULL
);
380 fs
.ViewMode
= FVM_DETAILS
;
381 fs
.fFlags
= FWF_AUTOARRANGE
;
383 SetRect(&rect
, 0, 0, default_width
, default_height
);
384 IExplorerBrowser_Initialize(info
->browser
,info
->main_window
,&rect
,&fs
);
385 IExplorerBrowser_SetOptions(info
->browser
,EBO_SHOWFRAMES
);
386 SetWindowLongPtrW(info
->main_window
,EXPLORER_INFO_INDEX
,(LONG_PTR
)info
);
389 rebar
= CreateWindowExW(WS_EX_TOOLWINDOW
,REBARCLASSNAMEW
,NULL
,
390 WS_CHILD
|WS_VISIBLE
|RBS_VARHEIGHT
|CCS_TOP
|CCS_NODIVIDER
,
391 0,0,0,0,info
->main_window
,NULL
,explorer_hInstance
,NULL
);
393 = CreateWindowExW(TBSTYLE_EX_MIXEDBUTTONS
,TOOLBARCLASSNAMEW
,NULL
,
394 WS_CHILD
|WS_VISIBLE
|TBSTYLE_FLAT
,0,0,0,0,rebar
,NULL
,
395 explorer_hInstance
,NULL
);
397 bitmap_info
.hInst
= HINST_COMMCTRL
;
398 bitmap_info
.nID
= IDB_HIST_LARGE_COLOR
;
399 hist_offset
= SendMessageW(nav_toolbar
,TB_ADDBITMAP
,0,(LPARAM
)&bitmap_info
);
400 bitmap_info
.nID
= IDB_VIEW_LARGE_COLOR
;
401 view_offset
= SendMessageW(nav_toolbar
,TB_ADDBITMAP
,0,(LPARAM
)&bitmap_info
);
403 nav_buttons
[0].iBitmap
=hist_offset
+HIST_BACK
;
404 nav_buttons
[0].idCommand
=BACK_BUTTON
;
405 nav_buttons
[0].fsState
=TBSTATE_ENABLED
;
406 nav_buttons
[0].fsStyle
=BTNS_BUTTON
|BTNS_AUTOSIZE
;
407 nav_buttons
[1].iBitmap
=hist_offset
+HIST_FORWARD
;
408 nav_buttons
[1].idCommand
=FORWARD_BUTTON
;
409 nav_buttons
[1].fsState
=TBSTATE_ENABLED
;
410 nav_buttons
[1].fsStyle
=BTNS_BUTTON
|BTNS_AUTOSIZE
;
411 nav_buttons
[2].iBitmap
=view_offset
+VIEW_PARENTFOLDER
;
412 nav_buttons
[2].idCommand
=UP_BUTTON
;
413 nav_buttons
[2].fsState
=TBSTATE_ENABLED
;
414 nav_buttons
[2].fsStyle
=BTNS_BUTTON
|BTNS_AUTOSIZE
;
415 SendMessageW(nav_toolbar
,TB_BUTTONSTRUCTSIZE
,sizeof(TBBUTTON
),0);
416 SendMessageW(nav_toolbar
,TB_ADDBUTTONSW
,ARRAY_SIZE( nav_buttons
),(LPARAM
)nav_buttons
);
418 band_info
.cbSize
= sizeof(band_info
);
419 band_info
.fMask
= RBBIM_STYLE
|RBBIM_CHILD
|RBBIM_CHILDSIZE
|RBBIM_SIZE
;
420 band_info
.hwndChild
= nav_toolbar
;
421 band_info
.fStyle
=RBBS_GRIPPERALWAYS
|RBBS_CHILDEDGE
;
422 band_info
.cyChild
=nav_toolbar_height
;
424 band_info
.cyMinChild
=nav_toolbar_height
;
425 band_info
.cxMinChild
=0;
426 SendMessageW(rebar
,RB_INSERTBANDW
,-1,(LPARAM
)&band_info
);
427 info
->path_box
= CreateWindowW(WC_COMBOBOXEXW
,PATH_BOX_NAME
,
428 WS_CHILD
| WS_VISIBLE
| CBS_DROPDOWN
,
429 0,0,default_width
,pathbox_height
,rebar
,NULL
,
430 explorer_hInstance
,NULL
);
431 GetWindowRect(info
->path_box
, &rect
);
432 band_info
.cyChild
= rect
.bottom
- rect
.top
;
434 band_info
.cyMinChild
= rect
.bottom
- rect
.top
;
435 band_info
.cxMinChild
=0;
436 band_info
.fMask
|=RBBIM_TEXT
;
437 band_info
.lpText
=pathbox_label
;
438 band_info
.fStyle
|=RBBS_BREAK
;
439 band_info
.hwndChild
=info
->path_box
;
440 SendMessageW(rebar
,RB_INSERTBANDW
,-1,(LPARAM
)&band_info
);
441 events
= make_explorer_events(info
);
442 IExplorerBrowser_Advise(info
->browser
,events
,&info
->advise_cookie
);
443 IExplorerBrowser_BrowseToObject(info
->browser
,(IUnknown
*)startFolder
,
445 ShowWindow(info
->main_window
,SW_SHOWDEFAULT
);
446 UpdateWindow(info
->main_window
);
447 IExplorerBrowserEvents_Release(events
);
450 static void update_window_size(explorer_info
*info
, int height
, int width
)
454 new_rect
.top
= info
->rebar_height
;
455 new_rect
.right
= width
;
456 new_rect
.bottom
= height
;
457 IExplorerBrowser_SetRect(info
->browser
,NULL
,new_rect
);
460 static void do_exit(int code
)
466 static LRESULT
explorer_on_end_edit(explorer_info
*info
,NMCBEENDEDITW
*edit_info
)
468 LPITEMIDLIST pidl
= NULL
;
470 WINE_TRACE("iWhy=%x\n",edit_info
->iWhy
);
471 switch(edit_info
->iWhy
)
474 if(edit_info
->iNewSelection
!=CB_ERR
)
475 pidl
= (LPITEMIDLIST
)SendMessageW(edit_info
->hdr
.hwndFrom
,
477 edit_info
->iNewSelection
,0);
481 WCHAR path
[MAX_PATH
];
482 HWND edit_ctrl
= (HWND
)SendMessageW(edit_info
->hdr
.hwndFrom
,
483 CBEM_GETEDITCONTROL
,0,0);
484 *((WORD
*)path
)=MAX_PATH
;
485 SendMessageW(edit_ctrl
,EM_GETLINE
,0,(LPARAM
)path
);
486 pidl
= ILCreateFromPathW(path
);
490 /*make sure the that the path box resets*/
491 update_path_box(info
);
497 IExplorerBrowser_BrowseToIDList(info
->browser
,pidl
,SBSP_ABSOLUTE
);
498 if(edit_info
->iWhy
==CBENF_RETURN
)
503 static LRESULT
update_rebar_size(explorer_info
* info
,NMRBAUTOSIZE
*size_info
)
507 info
->rebar_height
= size_info
->rcTarget
.bottom
-size_info
->rcTarget
.top
;
508 GetWindowRect(info
->main_window
,&window_rect
);
510 new_rect
.top
= info
->rebar_height
;
511 new_rect
.right
= window_rect
.right
-window_rect
.left
;
512 new_rect
.bottom
= window_rect
.bottom
-window_rect
.top
;
513 IExplorerBrowser_SetRect(info
->browser
,NULL
,new_rect
);
517 static LRESULT
explorer_on_notify(explorer_info
* info
,NMHDR
* notification
)
519 WINE_TRACE("code=%i\n",notification
->code
);
520 switch(notification
->code
)
524 WCHAR path
[MAX_PATH
];
525 HWND edit_ctrl
= (HWND
)SendMessageW(notification
->hwndFrom
,
526 CBEM_GETEDITCONTROL
,0,0);
527 SHGetPathFromIDListW(info
->pidl
,path
);
528 SetWindowTextW(edit_ctrl
,path
);
533 NMCBEENDEDITA
*edit_info_a
= (NMCBEENDEDITA
*)notification
;
534 NMCBEENDEDITW edit_info_w
;
535 edit_info_w
.hdr
= edit_info_a
->hdr
;
536 edit_info_w
.fChanged
= edit_info_a
->fChanged
;
537 edit_info_w
.iNewSelection
= edit_info_a
->iNewSelection
;
538 MultiByteToWideChar(CP_ACP
,0,edit_info_a
->szText
,-1,
539 edit_info_w
.szText
,CBEMAXSTRLEN
);
540 edit_info_w
.iWhy
= edit_info_a
->iWhy
;
541 return explorer_on_end_edit(info
,&edit_info_w
);
544 return explorer_on_end_edit(info
,(NMCBEENDEDITW
*)notification
);
545 case CBEN_DELETEITEM
:
547 NMCOMBOBOXEXW
*entry
= (NMCOMBOBOXEXW
*)notification
;
548 if(entry
->ceItem
.lParam
)
549 ILFree((LPITEMIDLIST
)entry
->ceItem
.lParam
);
553 return update_rebar_size(info
,(NMRBAUTOSIZE
*)notification
);
560 static LRESULT CALLBACK
explorer_wnd_proc(HWND hwnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
563 = (explorer_info
*)GetWindowLongPtrW(hwnd
,EXPLORER_INFO_INDEX
);
564 IExplorerBrowser
*browser
= NULL
;
566 WINE_TRACE("(hwnd=%p,uMsg=%u,wParam=%lx,lParam=%lx)\n",hwnd
,uMsg
,wParam
,lParam
);
568 browser
= info
->browser
;
572 IExplorerBrowser_Unadvise(browser
,info
->advise_cookie
);
573 IExplorerBrowser_Destroy(browser
);
574 IExplorerBrowser_Release(browser
);
576 IImageList_Release(info
->icon_list
);
577 HeapFree(GetProcessHeap(),0,info
);
578 SetWindowLongPtrW(hwnd
,EXPLORER_INFO_INDEX
,0);
584 return explorer_on_notify(info
,(NMHDR
*)lParam
);
586 if(HIWORD(wParam
)==BN_CLICKED
)
588 switch(LOWORD(wParam
))
591 IExplorerBrowser_BrowseToObject(browser
,NULL
,SBSP_NAVIGATEBACK
);
594 IExplorerBrowser_BrowseToObject(browser
,NULL
,SBSP_NAVIGATEFORWARD
);
597 IExplorerBrowser_BrowseToObject(browser
,NULL
,SBSP_PARENT
);
603 update_window_size(info
,HIWORD(lParam
),LOWORD(lParam
));
606 return DefWindowProcW(hwnd
,uMsg
,wParam
,lParam
);
611 static void register_explorer_window_class(void)
613 WNDCLASSEXW window_class
;
614 window_class
.cbSize
= sizeof(WNDCLASSEXW
);
615 window_class
.style
= 0;
616 window_class
.cbClsExtra
= 0;
617 window_class
.cbWndExtra
= sizeof(LONG_PTR
);
618 window_class
.lpfnWndProc
= explorer_wnd_proc
;
619 window_class
.hInstance
= explorer_hInstance
;
620 window_class
.hIcon
= NULL
;
621 window_class
.hCursor
= NULL
;
622 window_class
.hbrBackground
= (HBRUSH
)COLOR_BACKGROUND
;
623 window_class
.lpszMenuName
= NULL
;
624 window_class
.lpszClassName
= EXPLORER_CLASS
;
625 window_class
.hIconSm
= NULL
;
626 RegisterClassExW(&window_class
);
629 static IShellFolder
* get_starting_shell_folder(parameters_struct
* params
)
631 IShellFolder
* desktop
,*folder
;
632 LPITEMIDLIST root_pidl
;
633 WCHAR
*fullpath
= NULL
;
637 SHGetDesktopFolder(&desktop
);
638 if (!params
->root
[0])
643 size
= GetFullPathNameW(params
->root
, 0, fullpath
, NULL
);
646 fullpath
= heap_alloc(size
* sizeof(WCHAR
));
647 GetFullPathNameW(params
->root
, size
, fullpath
, NULL
);
649 hres
= IShellFolder_ParseDisplayName(desktop
,NULL
,NULL
,
658 hres
= IShellFolder_BindToObject(desktop
,root_pidl
,NULL
,
666 IShellFolder_Release(desktop
);
670 static WCHAR
*copy_path_string(WCHAR
*target
, WCHAR
*source
)
674 while (isspaceW(*source
)) source
++;
679 while (*source
&& *source
!= '\"') target
[i
++] = *source
++;
681 if (*source
) source
++;
685 while (*source
&& *source
!= ',') target
[i
++] = *source
++;
688 PathRemoveBackslashW(target
);
693 static void copy_path_root(LPWSTR root
, LPWSTR path
)
702 while (*p
!='\\' && p
> path
)
719 * Command Line parameters are:
720 * [/n] Opens in single-paned view for each selected items. This is default
721 * [/e,] Uses Windows Explorer View
722 * [/root,object] Specifies the root level of the view
723 * [/select,object] parent folder is opened and specified object is selected
725 static void parse_command_line(LPWSTR commandline
,parameters_struct
*parameters
)
727 static const WCHAR arg_n
[] = {'/','n'};
728 static const WCHAR arg_e
[] = {'/','e',','};
729 static const WCHAR arg_root
[] = {'/','r','o','o','t',','};
730 static const WCHAR arg_select
[] = {'/','s','e','l','e','c','t',','};
731 static const WCHAR arg_desktop
[] = {'/','d','e','s','k','t','o','p'};
732 static const WCHAR arg_desktop_quotes
[] = {'"','/','d','e','s','k','t','o','p'};
734 LPWSTR p
= commandline
;
738 while (isspaceW(*p
)) p
++;
739 if (strncmpW(p
, arg_n
, ARRAY_SIZE( arg_n
))==0)
741 parameters
->explorer_mode
= FALSE
;
742 p
+= ARRAY_SIZE( arg_n
);
744 else if (strncmpW(p
, arg_e
, ARRAY_SIZE( arg_e
))==0)
746 parameters
->explorer_mode
= TRUE
;
747 p
+= ARRAY_SIZE( arg_e
);
749 else if (strncmpW(p
, arg_root
, ARRAY_SIZE( arg_root
))==0)
751 p
+= ARRAY_SIZE( arg_root
);
752 p
= copy_path_string(parameters
->root
,p
);
754 else if (strncmpW(p
, arg_select
, ARRAY_SIZE( arg_select
))==0)
756 p
+= ARRAY_SIZE( arg_select
);
757 p
= copy_path_string(parameters
->selection
,p
);
758 if (!parameters
->root
[0])
759 copy_path_root(parameters
->root
,
760 parameters
->selection
);
762 else if (strncmpW(p
, arg_desktop
, ARRAY_SIZE( arg_desktop
))==0)
764 p
+= ARRAY_SIZE( arg_desktop
);
765 manage_desktop( p
); /* the rest of the command line is handled by desktop mode */
767 /* workaround for Worms Armageddon that hardcodes a /desktop option with quotes */
768 else if (strncmpW(p
, arg_desktop_quotes
, ARRAY_SIZE( arg_desktop_quotes
))==0)
770 p
+= ARRAY_SIZE( arg_desktop_quotes
);
771 manage_desktop( p
); /* the rest of the command line is handled by desktop mode */
775 /* left over command line is generally the path to be opened */
776 copy_path_string(parameters
->root
,p
);
782 int WINAPI
wWinMain(HINSTANCE hinstance
,
783 HINSTANCE previnstance
,
788 parameters_struct parameters
;
791 IShellFolder
*folder
;
792 INITCOMMONCONTROLSEX init_info
;
794 memset(¶meters
,0,sizeof(parameters
));
795 explorer_hInstance
= hinstance
;
796 parse_command_line(cmdline
,¶meters
);
797 hres
= OleInitialize(NULL
);
800 WINE_ERR("Could not initialize COM\n");
801 ExitProcess(EXIT_FAILURE
);
803 if(parameters
.root
[0] && !PathIsDirectoryW(parameters
.root
))
804 if(ShellExecuteW(NULL
,NULL
,parameters
.root
,NULL
,NULL
,SW_SHOWDEFAULT
) > (HINSTANCE
)32)
805 ExitProcess(EXIT_SUCCESS
);
806 init_info
.dwSize
= sizeof(INITCOMMONCONTROLSEX
);
807 init_info
.dwICC
= ICC_USEREX_CLASSES
| ICC_BAR_CLASSES
| ICC_COOL_CLASSES
;
808 if(!InitCommonControlsEx(&init_info
))
810 WINE_ERR("Could not initialize Comctl\n");
811 ExitProcess(EXIT_FAILURE
);
813 register_explorer_window_class();
814 folder
= get_starting_shell_folder(¶meters
);
815 make_explorer_window(folder
);
816 IShellFolder_Release(folder
);
817 while(GetMessageW( &msg
, NULL
, 0, 0 ) != 0)
819 TranslateMessage(&msg
);
820 DispatchMessageW(&msg
);