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
24 #define NONAMELESSUNION
26 #include "wine/unicode.h"
27 #include "wine/debug.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
47 #define DEFAULT_WIDTH 640
48 #define DEFAULT_HEIGHT 480
51 static const WCHAR EXPLORER_CLASS
[] = {'W','I','N','E','_','E','X','P','L','O','R','E','R','\0'};
52 static const WCHAR PATH_BOX_NAME
[] = {'\0'};
54 HINSTANCE explorer_hInstance
;
56 typedef struct parametersTAG
{
59 WCHAR selection
[MAX_PATH
];
64 IExplorerBrowser
*browser
;
65 HWND main_window
,path_box
;
68 IImageList
*icon_list
;
74 BACK_BUTTON
,FORWARD_BUTTON
,UP_BUTTON
79 IExplorerBrowserEvents IExplorerBrowserEvents_iface
;
82 } IExplorerBrowserEventsImpl
;
84 static IExplorerBrowserEventsImpl
*impl_from_IExplorerBrowserEvents(IExplorerBrowserEvents
*iface
)
86 return CONTAINING_RECORD(iface
, IExplorerBrowserEventsImpl
, IExplorerBrowserEvents_iface
);
89 static HRESULT WINAPI
IExplorerBrowserEventsImpl_fnQueryInterface(IExplorerBrowserEvents
*iface
, REFIID riid
, void **ppvObject
)
94 static ULONG WINAPI
IExplorerBrowserEventsImpl_fnAddRef(IExplorerBrowserEvents
*iface
)
96 IExplorerBrowserEventsImpl
*This
= impl_from_IExplorerBrowserEvents(iface
);
97 return InterlockedIncrement(&This
->ref
);
100 static ULONG WINAPI
IExplorerBrowserEventsImpl_fnRelease(IExplorerBrowserEvents
*iface
)
102 IExplorerBrowserEventsImpl
*This
= impl_from_IExplorerBrowserEvents(iface
);
103 ULONG ref
= InterlockedDecrement(&This
->ref
);
105 HeapFree(GetProcessHeap(),0,This
);
109 static BOOL
create_combobox_item(IShellFolder
*folder
, LPCITEMIDLIST pidl
, IImageList
*icon_list
, COMBOBOXEXITEMW
*item
)
113 IExtractIconW
*extract_icon
;
115 WCHAR icon_file
[MAX_PATH
];
119 strret
.uType
=STRRET_WSTR
;
120 hres
= IShellFolder_GetDisplayNameOf(folder
,pidl
,SHGDN_FORADDRESSBAR
,&strret
);
123 WINE_WARN("Could not get name for pidl\n");
129 item
->pszText
= strret
.u
.pOleStr
;
132 WINE_FIXME("Unimplemented STRRET type:%u\n",strret
.uType
);
135 hres
= IShellFolder_GetUIObjectOf(folder
,NULL
,1,&pidl
,&IID_IExtractIconW
,
136 &reserved
,(void**)&extract_icon
);
139 item
->mask
|= CBEIF_IMAGE
;
140 IExtractIconW_GetIconLocation(extract_icon
,GIL_FORSHELL
,icon_file
,
141 sizeof(icon_file
)/sizeof(WCHAR
),
142 &icon_index
,&icon_flags
);
143 IExtractIconW_Extract(extract_icon
,icon_file
,icon_index
,NULL
,&icon
,20);
144 item
->iImage
= ImageList_AddIcon((HIMAGELIST
)icon_list
,icon
);
145 IExtractIconW_Release(extract_icon
);
149 item
->mask
&= ~CBEIF_IMAGE
;
150 WINE_WARN("Could not get an icon for %s\n",wine_dbgstr_w(item
->pszText
));
155 static void update_path_box(explorer_info
*info
)
157 COMBOBOXEXITEMW item
;
158 COMBOBOXEXITEMW main_item
;
159 IShellFolder
*desktop
;
160 IPersistFolder2
*persist
;
161 LPITEMIDLIST desktop_pidl
;
164 ImageList_Remove((HIMAGELIST
)info
->icon_list
,-1);
165 SendMessageW(info
->path_box
,CB_RESETCONTENT
,0,0);
166 SHGetDesktopFolder(&desktop
);
167 IShellFolder_QueryInterface(desktop
,&IID_IPersistFolder2
,(void**)&persist
);
168 IPersistFolder2_GetCurFolder(persist
,&desktop_pidl
);
169 IPersistFolder2_Release(persist
);
173 item
.mask
= CBEIF_TEXT
| CBEIF_INDENT
| CBEIF_LPARAM
;
175 create_combobox_item(desktop
,desktop_pidl
,info
->icon_list
,&item
);
176 item
.lParam
= (LPARAM
)desktop_pidl
;
177 SendMessageW(info
->path_box
,CBEM_INSERTITEMW
,0,(LPARAM
)&item
);
178 if(ILIsEqual(info
->pidl
,desktop_pidl
))
181 CoTaskMemFree(item
.pszText
);
182 /*Add all direct subfolders of Desktop*/
183 if(SUCCEEDED(IShellFolder_EnumObjects(desktop
,NULL
,SHCONTF_FOLDERS
,&ids
))
186 LPITEMIDLIST curr_pidl
=NULL
;
194 hres
= IEnumIDList_Next(ids
,1,&curr_pidl
,NULL
);
195 if(FAILED(hres
) || hres
== S_FALSE
)
197 if(!create_combobox_item(desktop
,curr_pidl
,info
->icon_list
,&item
))
198 WINE_WARN("Could not create a combobox item\n");
201 LPITEMIDLIST full_pidl
= ILCombine(desktop_pidl
,curr_pidl
);
202 item
.lParam
= (LPARAM
)full_pidl
;
203 SendMessageW(info
->path_box
,CBEM_INSERTITEMW
,0,(LPARAM
)&item
);
204 if(ILIsEqual(full_pidl
,info
->pidl
))
206 else if(ILIsParent(full_pidl
,info
->pidl
,FALSE
))
208 /*add all parents of the pidl passed in*/
209 LPITEMIDLIST next_pidl
= ILFindChild(full_pidl
,info
->pidl
);
210 IShellFolder
*curr_folder
= NULL
, *temp
;
211 hres
= IShellFolder_BindToObject(desktop
,curr_pidl
,NULL
,
213 (void**)&curr_folder
);
215 WINE_WARN("Could not get an IShellFolder\n");
216 while(!ILIsEmpty(next_pidl
))
218 LPITEMIDLIST first
= ILCloneFirst(next_pidl
);
219 CoTaskMemFree(item
.pszText
);
220 if(!create_combobox_item(curr_folder
,first
,
221 info
->icon_list
,&item
))
223 WINE_WARN("Could not create a combobox item\n");
227 full_pidl
= ILCombine(full_pidl
,first
);
228 item
.lParam
= (LPARAM
)full_pidl
;
229 SendMessageW(info
->path_box
,CBEM_INSERTITEMW
,0,(LPARAM
)&item
);
231 hres
= IShellFolder_BindToObject(curr_folder
,first
,NULL
,
236 WINE_WARN("Could not get an IShellFolder\n");
239 IShellFolder_Release(curr_folder
);
243 next_pidl
= ILGetNext(next_pidl
);
245 memcpy(&main_item
,&item
,sizeof(item
));
247 IShellFolder_Release(curr_folder
);
251 CoTaskMemFree(item
.pszText
);
255 IEnumIDList_Release(ids
);
258 WINE_WARN("Could not enumerate the desktop\n");
259 SendMessageW(info
->path_box
,CBEM_SETITEMW
,0,(LPARAM
)&main_item
);
260 CoTaskMemFree(main_item
.pszText
);
263 static HRESULT WINAPI
IExplorerBrowserEventsImpl_fnOnNavigationComplete(IExplorerBrowserEvents
*iface
, PCIDLIST_ABSOLUTE pidl
)
265 IExplorerBrowserEventsImpl
*This
= impl_from_IExplorerBrowserEvents(iface
);
266 ILFree(This
->info
->pidl
);
267 This
->info
->pidl
= ILClone(pidl
);
268 update_path_box(This
->info
);
272 static HRESULT WINAPI
IExplorerBrowserEventsImpl_fnOnNavigationFailed(IExplorerBrowserEvents
*iface
, PCIDLIST_ABSOLUTE pidl
)
277 static HRESULT WINAPI
IExplorerBrowserEventsImpl_fnOnNavigationPending(IExplorerBrowserEvents
*iface
, PCIDLIST_ABSOLUTE pidl
)
282 static HRESULT WINAPI
IExplorerBrowserEventsImpl_fnOnViewCreated(IExplorerBrowserEvents
*iface
, IShellView
*psv
)
287 static IExplorerBrowserEventsVtbl vt_IExplorerBrowserEvents
=
289 IExplorerBrowserEventsImpl_fnQueryInterface
,
290 IExplorerBrowserEventsImpl_fnAddRef
,
291 IExplorerBrowserEventsImpl_fnRelease
,
292 IExplorerBrowserEventsImpl_fnOnNavigationPending
,
293 IExplorerBrowserEventsImpl_fnOnViewCreated
,
294 IExplorerBrowserEventsImpl_fnOnNavigationComplete
,
295 IExplorerBrowserEventsImpl_fnOnNavigationFailed
298 static IExplorerBrowserEvents
*make_explorer_events(explorer_info
*info
)
300 IExplorerBrowserEventsImpl
*ret
301 = HeapAlloc(GetProcessHeap(), 0, sizeof(IExplorerBrowserEventsImpl
));
302 ret
->IExplorerBrowserEvents_iface
.lpVtbl
= &vt_IExplorerBrowserEvents
;
305 SHGetImageList(SHIL_SMALL
,&IID_IImageList
,(void**)&(ret
->info
->icon_list
));
306 SendMessageW(info
->path_box
,CBEM_SETIMAGELIST
,0,(LPARAM
)ret
->info
->icon_list
);
307 return &ret
->IExplorerBrowserEvents_iface
;
310 static void make_explorer_window(IShellFolder
* startFolder
)
313 HWND rebar
,nav_toolbar
;
315 IExplorerBrowserEvents
*events
;
318 WCHAR explorer_title
[100];
319 WCHAR pathbox_label
[50];
320 TBADDBITMAP bitmap_info
;
321 TBBUTTON nav_buttons
[3];
322 int hist_offset
,view_offset
;
323 REBARBANDINFOW band_info
;
324 memset(nav_buttons
,0,sizeof(nav_buttons
));
325 LoadStringW(explorer_hInstance
,IDS_EXPLORER_TITLE
,explorer_title
,
326 sizeof(explorer_title
)/sizeof(WCHAR
));
327 LoadStringW(explorer_hInstance
,IDS_PATHBOX_LABEL
,pathbox_label
,
328 sizeof(pathbox_label
)/sizeof(WCHAR
));
329 info
= HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY
,sizeof(explorer_info
));
332 WINE_ERR("Could not allocate a explorer_info struct\n");
335 hres
= CoCreateInstance(&CLSID_ExplorerBrowser
,NULL
,CLSCTX_INPROC_SERVER
,
336 &IID_IExplorerBrowser
,(LPVOID
*)&info
->browser
);
339 WINE_ERR("Could not obtain an instance of IExplorerBrowser\n");
340 HeapFree(GetProcessHeap(),0,info
);
343 info
->rebar_height
=0;
345 = CreateWindowW(EXPLORER_CLASS
,explorer_title
,WS_OVERLAPPEDWINDOW
,
346 CW_USEDEFAULT
,CW_USEDEFAULT
,DEFAULT_WIDTH
,
347 DEFAULT_HEIGHT
,NULL
,NULL
,explorer_hInstance
,NULL
);
349 fs
.ViewMode
= FVM_DETAILS
;
350 fs
.fFlags
= FWF_AUTOARRANGE
;
351 explorerRect
.left
= 0;
352 explorerRect
.top
= 0;
353 explorerRect
.right
= DEFAULT_WIDTH
;
354 explorerRect
.bottom
= DEFAULT_HEIGHT
;
356 IExplorerBrowser_Initialize(info
->browser
,info
->main_window
,&explorerRect
,&fs
);
357 IExplorerBrowser_SetOptions(info
->browser
,EBO_SHOWFRAMES
);
358 SetWindowLongPtrW(info
->main_window
,EXPLORER_INFO_INDEX
,(LONG_PTR
)info
);
361 rebar
= CreateWindowExW(WS_EX_TOOLWINDOW
,REBARCLASSNAMEW
,NULL
,
362 WS_CHILD
|WS_VISIBLE
|RBS_VARHEIGHT
|CCS_TOP
|CCS_NODIVIDER
,
363 0,0,0,0,info
->main_window
,NULL
,explorer_hInstance
,NULL
);
365 = CreateWindowExW(TBSTYLE_EX_MIXEDBUTTONS
,TOOLBARCLASSNAMEW
,NULL
,
366 WS_CHILD
|WS_VISIBLE
|TBSTYLE_FLAT
,0,0,0,0,rebar
,NULL
,
367 explorer_hInstance
,NULL
);
369 bitmap_info
.hInst
= HINST_COMMCTRL
;
370 bitmap_info
.nID
= IDB_HIST_LARGE_COLOR
;
371 hist_offset
= SendMessageW(nav_toolbar
,TB_ADDBITMAP
,0,(LPARAM
)&bitmap_info
);
372 bitmap_info
.nID
= IDB_VIEW_LARGE_COLOR
;
373 view_offset
= SendMessageW(nav_toolbar
,TB_ADDBITMAP
,0,(LPARAM
)&bitmap_info
);
375 nav_buttons
[0].iBitmap
=hist_offset
+HIST_BACK
;
376 nav_buttons
[0].idCommand
=BACK_BUTTON
;
377 nav_buttons
[0].fsState
=TBSTATE_ENABLED
;
378 nav_buttons
[0].fsStyle
=BTNS_BUTTON
|BTNS_AUTOSIZE
;
379 nav_buttons
[1].iBitmap
=hist_offset
+HIST_FORWARD
;
380 nav_buttons
[1].idCommand
=FORWARD_BUTTON
;
381 nav_buttons
[1].fsState
=TBSTATE_ENABLED
;
382 nav_buttons
[1].fsStyle
=BTNS_BUTTON
|BTNS_AUTOSIZE
;
383 nav_buttons
[2].iBitmap
=view_offset
+VIEW_PARENTFOLDER
;
384 nav_buttons
[2].idCommand
=UP_BUTTON
;
385 nav_buttons
[2].fsState
=TBSTATE_ENABLED
;
386 nav_buttons
[2].fsStyle
=BTNS_BUTTON
|BTNS_AUTOSIZE
;
387 SendMessageW(nav_toolbar
,TB_BUTTONSTRUCTSIZE
,sizeof(TBBUTTON
),0);
388 SendMessageW(nav_toolbar
,TB_ADDBUTTONSW
,sizeof(nav_buttons
)/sizeof(TBBUTTON
),(LPARAM
)nav_buttons
);
390 band_info
.cbSize
= sizeof(band_info
);
391 band_info
.fMask
= RBBIM_STYLE
|RBBIM_CHILD
|RBBIM_CHILDSIZE
|RBBIM_SIZE
;
392 band_info
.hwndChild
= nav_toolbar
;
393 band_info
.fStyle
=RBBS_GRIPPERALWAYS
|RBBS_CHILDEDGE
;
394 band_info
.cyChild
=NAV_TOOLBAR_HEIGHT
;
396 band_info
.cyMinChild
=NAV_TOOLBAR_HEIGHT
;
397 band_info
.cxMinChild
=0;
398 SendMessageW(rebar
,RB_INSERTBANDW
,-1,(LPARAM
)&band_info
);
399 info
->path_box
= CreateWindowW(WC_COMBOBOXEXW
,PATH_BOX_NAME
,
400 WS_CHILD
| WS_VISIBLE
| CBS_DROPDOWN
,
401 0,0,DEFAULT_WIDTH
,PATHBOX_HEIGHT
,rebar
,NULL
,
402 explorer_hInstance
,NULL
);
403 band_info
.cyChild
=PATHBOX_HEIGHT
;
405 band_info
.cyMinChild
=PATHBOX_HEIGHT
;
406 band_info
.cxMinChild
=0;
407 band_info
.fMask
|=RBBIM_TEXT
;
408 band_info
.lpText
=pathbox_label
;
409 band_info
.fStyle
|=RBBS_BREAK
;
410 band_info
.hwndChild
=info
->path_box
;
411 SendMessageW(rebar
,RB_INSERTBANDW
,-1,(LPARAM
)&band_info
);
412 events
= make_explorer_events(info
);
413 IExplorerBrowser_Advise(info
->browser
,events
,&info
->advise_cookie
);
414 IExplorerBrowser_BrowseToObject(info
->browser
,(IUnknown
*)startFolder
,
416 ShowWindow(info
->main_window
,SW_SHOWDEFAULT
);
417 UpdateWindow(info
->main_window
);
418 IExplorerBrowserEvents_Release(events
);
421 static void update_window_size(explorer_info
*info
, int height
, int width
)
425 new_rect
.top
= info
->rebar_height
;
426 new_rect
.right
= width
;
427 new_rect
.bottom
= height
;
428 IExplorerBrowser_SetRect(info
->browser
,NULL
,new_rect
);
431 static void do_exit(int code
)
437 static LRESULT
explorer_on_end_edit(explorer_info
*info
,NMCBEENDEDITW
*edit_info
)
439 LPITEMIDLIST pidl
= NULL
;
441 WINE_TRACE("iWhy=%x\n",edit_info
->iWhy
);
442 switch(edit_info
->iWhy
)
445 if(edit_info
->iNewSelection
!=CB_ERR
)
446 pidl
= (LPITEMIDLIST
)SendMessageW(edit_info
->hdr
.hwndFrom
,
448 edit_info
->iNewSelection
,0);
452 WCHAR path
[MAX_PATH
];
453 HWND edit_ctrl
= (HWND
)SendMessageW(edit_info
->hdr
.hwndFrom
,
454 CBEM_GETEDITCONTROL
,0,0);
455 *((WORD
*)path
)=MAX_PATH
;
456 SendMessageW(edit_ctrl
,EM_GETLINE
,0,(LPARAM
)path
);
457 pidl
= ILCreateFromPathW(path
);
461 /*make sure the that the path box resets*/
462 update_path_box(info
);
468 IExplorerBrowser_BrowseToIDList(info
->browser
,pidl
,SBSP_ABSOLUTE
);
469 if(edit_info
->iWhy
==CBENF_RETURN
)
474 static LRESULT
update_rebar_size(explorer_info
* info
,NMRBAUTOSIZE
*size_info
)
478 info
->rebar_height
= size_info
->rcTarget
.bottom
-size_info
->rcTarget
.top
;
479 GetWindowRect(info
->main_window
,&window_rect
);
481 new_rect
.top
= info
->rebar_height
;
482 new_rect
.right
= window_rect
.right
-window_rect
.left
;
483 new_rect
.bottom
= window_rect
.bottom
-window_rect
.top
;
484 IExplorerBrowser_SetRect(info
->browser
,NULL
,new_rect
);
488 static LRESULT
explorer_on_notify(explorer_info
* info
,NMHDR
* notification
)
490 WINE_TRACE("code=%i\n",notification
->code
);
491 switch(notification
->code
)
495 WCHAR path
[MAX_PATH
];
496 HWND edit_ctrl
= (HWND
)SendMessageW(notification
->hwndFrom
,
497 CBEM_GETEDITCONTROL
,0,0);
498 SHGetPathFromIDListW(info
->pidl
,path
);
499 SetWindowTextW(edit_ctrl
,path
);
504 NMCBEENDEDITA
*edit_info_a
= (NMCBEENDEDITA
*)notification
;
505 NMCBEENDEDITW edit_info_w
;
506 edit_info_w
.hdr
= edit_info_a
->hdr
;
507 edit_info_w
.fChanged
= edit_info_a
->fChanged
;
508 edit_info_w
.iNewSelection
= edit_info_a
->iNewSelection
;
509 MultiByteToWideChar(CP_ACP
,0,edit_info_a
->szText
,-1,
510 edit_info_w
.szText
,CBEMAXSTRLEN
);
511 edit_info_w
.iWhy
= edit_info_a
->iWhy
;
512 return explorer_on_end_edit(info
,&edit_info_w
);
515 return explorer_on_end_edit(info
,(NMCBEENDEDITW
*)notification
);
516 case CBEN_DELETEITEM
:
518 NMCOMBOBOXEXW
*entry
= (NMCOMBOBOXEXW
*)notification
;
519 if(entry
->ceItem
.lParam
)
520 ILFree((LPITEMIDLIST
)entry
->ceItem
.lParam
);
524 return update_rebar_size(info
,(NMRBAUTOSIZE
*)notification
);
531 static LRESULT CALLBACK
explorer_wnd_proc(HWND hwnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
534 = (explorer_info
*)GetWindowLongPtrW(hwnd
,EXPLORER_INFO_INDEX
);
535 IExplorerBrowser
*browser
= NULL
;
537 WINE_TRACE("(hwnd=%p,uMsg=%u,wParam=%lx,lParam=%lx)\n",hwnd
,uMsg
,wParam
,lParam
);
539 browser
= info
->browser
;
543 IExplorerBrowser_Unadvise(browser
,info
->advise_cookie
);
544 IExplorerBrowser_Destroy(browser
);
545 IExplorerBrowser_Release(browser
);
547 IImageList_Release(info
->icon_list
);
548 HeapFree(GetProcessHeap(),0,info
);
549 SetWindowLongPtrW(hwnd
,EXPLORER_INFO_INDEX
,0);
555 return explorer_on_notify(info
,(NMHDR
*)lParam
);
557 if(HIWORD(wParam
)==BN_CLICKED
)
559 switch(LOWORD(wParam
))
562 IExplorerBrowser_BrowseToObject(browser
,NULL
,SBSP_NAVIGATEBACK
);
565 IExplorerBrowser_BrowseToObject(browser
,NULL
,SBSP_NAVIGATEFORWARD
);
568 IExplorerBrowser_BrowseToObject(browser
,NULL
,SBSP_PARENT
);
574 update_window_size(info
,HIWORD(lParam
),LOWORD(lParam
));
577 return DefWindowProcW(hwnd
,uMsg
,wParam
,lParam
);
582 static void register_explorer_window_class(void)
584 WNDCLASSEXW window_class
;
585 window_class
.cbSize
= sizeof(WNDCLASSEXW
);
586 window_class
.style
= 0;
587 window_class
.cbClsExtra
= 0;
588 window_class
.cbWndExtra
= sizeof(LONG_PTR
);
589 window_class
.lpfnWndProc
= explorer_wnd_proc
;
590 window_class
.hInstance
= explorer_hInstance
;
591 window_class
.hIcon
= NULL
;
592 window_class
.hCursor
= NULL
;
593 window_class
.hbrBackground
= (HBRUSH
)COLOR_BACKGROUND
;
594 window_class
.lpszMenuName
= NULL
;
595 window_class
.lpszClassName
= EXPLORER_CLASS
;
596 window_class
.hIconSm
= NULL
;
597 RegisterClassExW(&window_class
);
600 static IShellFolder
* get_starting_shell_folder(parameters_struct
* params
)
602 IShellFolder
* desktop
,*folder
;
603 LPITEMIDLIST root_pidl
;
606 SHGetDesktopFolder(&desktop
);
607 if (!params
->root
[0])
611 hres
= IShellFolder_ParseDisplayName(desktop
,NULL
,NULL
,
619 hres
= IShellFolder_BindToObject(desktop
,root_pidl
,NULL
,
626 IShellFolder_Release(desktop
);
630 static int copy_path_string(LPWSTR target
, LPWSTR source
)
634 while (isspaceW(*source
)) source
++;
639 while (*source
!= '\"') target
[i
++] = *source
++;
646 while (*source
&& !isspaceW(*source
)) target
[i
++] = *source
++;
653 static void copy_path_root(LPWSTR root
, LPWSTR path
)
662 while (*p
!='\\' && p
> path
)
679 * Command Line parameters are:
680 * [/n] Opens in single-paned view for each selected items. This is default
681 * [/e,] Uses Windows Explorer View
682 * [/root,object] Specifies the root level of the view
683 * [/select,object] parent folder is opened and specified object is selected
685 static void parse_command_line(LPWSTR commandline
,parameters_struct
*parameters
)
687 static const WCHAR arg_n
[] = {'/','n'};
688 static const WCHAR arg_e
[] = {'/','e',','};
689 static const WCHAR arg_root
[] = {'/','r','o','o','t',','};
690 static const WCHAR arg_select
[] = {'/','s','e','l','e','c','t',','};
691 static const WCHAR arg_desktop
[] = {'/','d','e','s','k','t','o','p'};
696 p
= strchrW(commandline
,'/');
699 if (strncmpW(p
, arg_n
, sizeof(arg_n
)/sizeof(WCHAR
))==0)
701 parameters
->explorer_mode
= FALSE
;
702 p
+= sizeof(arg_n
)/sizeof(WCHAR
);
704 else if (strncmpW(p
, arg_e
, sizeof(arg_e
)/sizeof(WCHAR
))==0)
706 parameters
->explorer_mode
= TRUE
;
707 p
+= sizeof(arg_e
)/sizeof(WCHAR
);
709 else if (strncmpW(p
, arg_root
, sizeof(arg_root
)/sizeof(WCHAR
))==0)
711 p
+= sizeof(arg_root
)/sizeof(WCHAR
);
712 p
+=copy_path_string(parameters
->root
,p
);
714 else if (strncmpW(p
, arg_select
, sizeof(arg_select
)/sizeof(WCHAR
))==0)
716 p
+= sizeof(arg_select
)/sizeof(WCHAR
);
717 p
+=copy_path_string(parameters
->selection
,p
);
718 if (!parameters
->root
[0])
719 copy_path_root(parameters
->root
,
720 parameters
->selection
);
722 else if (strncmpW(p
, arg_desktop
, sizeof(arg_desktop
)/sizeof(WCHAR
))==0)
724 p
+= sizeof(arg_desktop
)/sizeof(WCHAR
);
725 manage_desktop( p
); /* the rest of the command line is handled by desktop mode */
734 /* left over command line is generally the path to be opened */
735 copy_path_string(parameters
->root
,p2
);
739 int WINAPI
wWinMain(HINSTANCE hinstance
,
740 HINSTANCE previnstance
,
745 parameters_struct parameters
;
748 IShellFolder
*folder
;
749 INITCOMMONCONTROLSEX init_info
;
751 memset(¶meters
,0,sizeof(parameters
));
752 explorer_hInstance
= hinstance
;
753 parse_command_line(cmdline
,¶meters
);
754 hres
= OleInitialize(NULL
);
757 WINE_ERR("Could not initialize COM\n");
758 ExitProcess(EXIT_FAILURE
);
760 if(parameters
.root
[0] && !PathIsDirectoryW(parameters
.root
))
761 if(ShellExecuteW(NULL
,NULL
,parameters
.root
,NULL
,NULL
,SW_SHOWDEFAULT
) > (HINSTANCE
)32)
762 ExitProcess(EXIT_SUCCESS
);
763 init_info
.dwSize
= sizeof(INITCOMMONCONTROLSEX
);
764 init_info
.dwICC
= ICC_USEREX_CLASSES
| ICC_BAR_CLASSES
| ICC_COOL_CLASSES
;
765 if(!InitCommonControlsEx(&init_info
))
767 WINE_ERR("Could not initialize Comctl\n");
768 ExitProcess(EXIT_FAILURE
);
770 register_explorer_window_class();
771 folder
= get_starting_shell_folder(¶meters
);
772 make_explorer_window(folder
);
773 IShellFolder_Release(folder
);
774 while(GetMessageW( &msg
, NULL
, 0, 0 ) != 0)
776 TranslateMessage(&msg
);
777 DispatchMessageW(&msg
);