Click here to Skip to main content
15,867,834 members
Articles / Desktop Programming / WTL
Article

Implementing IShellBrowser to host IShellView

Rate me:
Please Sign up or sign in to vote.
4.84/5 (23 votes)
4 Jun 2001CPOL2 min read 320.9K   4.4K   66   71
Imitating the Windows Explorer

Sample Image - screen.gif

Introduction

I wondered how I can simulate the Windows explorer listview of files. Here is what I found. It might be useful to someone. If you create a simple listview control and populate it with files/folders, you'll notice that you can't:

  • Easily detect changes to files (rename, delete, copy/move...etc) while user is viewing the list
  • Send To menu is not populated if you try to use the shell's menu for your items
  • There doesn't seem to be a way of getting the column names used in shellview (filename, size, owner, times, and many others)

I found that Windows explorer and File Open dialog expose IShellBrowser, which is used by IShellFolder/IShellView to create the listview of files. So, I created a simple app with WTL. Implemented basic IShellBrowser methods and exposed it to IShellView through IShellFolder::CreateViewObject. Finally, to create the listview I called IShellView::CreateViewWindow. I didn't try to merge the menus.
Things I couldn't get to work:

  • Toolbar buttons (they were added to my toolbar, but bitmaps were messed up). They do function however.
  • The most important one for me was that I couldn't easily detect when user wanted to open/explore/search the selected folder so I could sync the file tree.

The IShellBrowser::BrowseObject was never even called, so I didn't implement it, but it should be implemented because most NSEs use this method. I did find that the shellview sends WM_DDE* messages and if you respond properly you'll get the info about the action user taken. The needed messages are WM_DDE_INITIATE, WM_DDE_EXECUTE, WM_DDE_TERMINATE. WM_DDE_EXECUTE will give you string such as
"[ViewFolder("C:\Documents and Settings\leon\Desktop\billing", :428:780, 1)]". I have no idea what the 428:780 stand for. But action would be ViewFolder/ExploreFolder/FindFolder. It would be nice if Microsoft documented this stuff then we could use it. But as things stand now they even say in the MSDN:

"You do not implement this interface directly. IShellBrowser is implemented by Windows Explorer and by the Windows File Open common dialog box."

But then why did they tell us about WM_GETISHELLBROWSER? Anyway, maybe it would be useful to someone, so here it is.

Some useful points:

  • To get drag drop functioning in shellview, call OleInitialize/OleUninitialize
  • Make sure you respond properly to WM_GETISHELLBROWSER or CreateView might crash
  • Details listview seems to work only with FVM_DETAILS and FWF_SNAPTOGRID combination
  • ICommDlgBrowser can be supported to have a simple listview like in common file dialog boxes (without webview)
  • Don't name your executable as explorer.exe or unpleasant things will happen

Useful links

Disclaimer: THIS CODE AND INFORMATION IS PROVIDED 'AS IS' WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
United States United States
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
GeneralShowing only folders in tree Pin
Member 2362230-Oct-10 23:49
Member 2362230-Oct-10 23:49 
GeneralAwesome code! Pin
T800G10-Oct-09 1:43
T800G10-Oct-09 1:43 
QuestionContext Menu Problem Pin
rImrose29-May-09 6:40
rImrose29-May-09 6:40 
QuestionHow can I embed the whole Explorer window in my window Pin
Javed Akhtar Ansari3-Oct-08 0:55
Javed Akhtar Ansari3-Oct-08 0:55 
GeneralrIt wasn't worked Pin
jalalymm15-Apr-07 1:56
jalalymm15-Apr-07 1:56 
QuestionHow to get thumbnail from windown Explorer? Pin
An Phung Nguyen16-Oct-06 22:13
An Phung Nguyen16-Oct-06 22:13 
Generalerror Pin
kiranin10-Sep-06 21:21
kiranin10-Sep-06 21:21 
QuestionIs there any solution to implement this project on a dailog-based application? Pin
Aki Wang19-Jul-06 15:28
Aki Wang19-Jul-06 15:28 
GeneralNever ending dialog pops up Pin
R.D.H.2-May-06 6:24
R.D.H.2-May-06 6:24 
QuestionHow to get the path for each icon in the Desktop folder Pin
giftsana22-Mar-06 15:27
giftsana22-Mar-06 15:27 
AnswerRe: How to get the path for each icon in the Desktop folder Pin
giftsana27-Mar-06 19:18
giftsana27-Mar-06 19:18 
GeneralSetting the path Pin
cowtongue215-Feb-06 17:06
cowtongue215-Feb-06 17:06 
Questionwhy cannot use "delete" key to delete file? Pin
tianzuo3-Nov-05 21:36
tianzuo3-Nov-05 21:36 
GeneralStatus bar messages and Multi Thread Pin
Guybrush19-Mar-05 11:55
Guybrush19-Mar-05 11:55 
GeneralWM_DDE* messages seems are not sent Pin
alerma19-Oct-04 9:15
alerma19-Oct-04 9:15 
GeneralRe: WM_DDE* messages seems are not sent Pin
RickyV19-Oct-04 14:09
RickyV19-Oct-04 14:09 
GeneralRe: WM_DDE* messages seems are not sent Pin
alerma20-Oct-04 1:35
alerma20-Oct-04 1:35 
GeneralRe: WM_DDE* messages seems are not sent Pin
RickyV20-Oct-04 14:12
RickyV20-Oct-04 14:12 
I am facing the same problem as you do. I am still looking for solution to this problem. From my understanding, the only time any WM_DDE_* is sent is when 2 programs need to exchange data. For example, when you double click on a folder in ishellview, a WM_DDE_INITIATE will be send to Windows Explorer(W.E). the W.E will open up the folder and display it.
GeneralRe: WM_DDE* messages seems are not sent Pin
Leon Finker20-Oct-04 14:40
Leon Finker20-Oct-04 14:40 
GeneralDetecting cut/paste operations Pin
orangerobin1-Oct-04 2:41
orangerobin1-Oct-04 2:41 
Generalusing the same ishellview Pin
RickyV20-Sep-04 21:27
RickyV20-Sep-04 21:27 
GeneralRe: using the same ishellview Pin
Leon Finker21-Sep-04 13:55
Leon Finker21-Sep-04 13:55 
GeneralRe: using the same ishellview Pin
RickyV21-Sep-04 15:03
RickyV21-Sep-04 15:03 
GeneralBrowseObject Pin
quinthar13-Nov-04 22:21
quinthar13-Nov-04 22:21 
GeneralRe: BrowseObject Pin
RickyV28-Nov-04 20:21
RickyV28-Nov-04 20:21 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.