Click here to Skip to main content
15,901,426 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 322.7K   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

 
GeneralRe: missing atlapp.h file Pin
vneumann9-Mar-04 0:13
vneumann9-Mar-04 0:13 
GeneralHelp me to get Folder PIDL when Click in Explorer Pin
sumiselva16-Oct-03 9:07
sumiselva16-Oct-03 9:07 
GeneralRe: Help me to get Folder PIDL when Click in Explorer Pin
Leon Finker22-Oct-03 6:26
Leon Finker22-Oct-03 6:26 
GeneralRe: Help me to get Folder PIDL when Click in Explorer Pin
CabbageMonster15-Jul-04 8:34
CabbageMonster15-Jul-04 8:34 
GeneralI want to know... Pin
raobo755-Sep-03 6:08
raobo755-Sep-03 6:08 
GeneralRe: I want to know... Pin
Leon Finker5-Sep-03 6:37
Leon Finker5-Sep-03 6:37 
GeneralRe: I want to know... Pin
raobo6-Sep-03 21:17
raobo6-Sep-03 21:17 
GeneralRe: I want to know... Pin
Leon Finker7-Sep-03 15:32
Leon Finker7-Sep-03 15:32 
Hello,

It's not that simple to create the example,
because you have to implement IShellBrowser interface
and if needed ICommDlgBrowser.

class IShellBrowserImpl : public IShellBrowser, public ICommDlgBrowser
{
...
};

This instance of IShellBrowser class has to be passed to CreateViewWindow
for the 3rd parameter.

If you want your statusbar to get the info messages about the selected files
you have to provide your statusbar hwnd also in one of the override methods.

Then you also have to respond differently to WM_GETISHELLBROWSER in your parent window
when it's dialog or simple window.

These are basic steps.

Maybe you can tell me what error you're getting with wtl and I can help you with that.

For WTL7 you need to download:
http://www.microsoft.com/downloads/details.aspx?familyid=128E26EE-2112-4CF7-B28E-7727D9A1F288&displaylang=en

Then just set the VC's include path to where you installed wtl7. For example, [X:\YourPath\]wtl7\Include

If you don't have VS.NET, you need to download Platform SDK:
http://www.microsoft.com/msdownload/platformsdk/sdkupdate/

After that, the project should build without any errors.

Another way to provide similar GUI is by hosting WebBrowser ActiveX control.
Here is a complete example with source code:

http://support.microsoft.com/default.aspx?scid=189634


GeneralRe: I want to know... Pin
raobo8-Sep-03 1:18
raobo8-Sep-03 1:18 
QuestionHow to notice folder changing? Pin
Member 7414517-Aug-03 7:52
Member 7414517-Aug-03 7:52 
AnswerRe: How to notice folder changing? Pin
Leon Finker17-Aug-03 8:27
Leon Finker17-Aug-03 8:27 
GeneralRe: How to notice folder changing? Pin
Member 7414518-Aug-03 5:08
Member 7414518-Aug-03 5:08 
GeneralDetails listview seems to work only with FVM_DETAILS and FWF_SNAPTOGRID combination Pin
leok7v8-Nov-02 8:44
leok7v8-Nov-02 8:44 
GeneralRe: Details listview seems to work only with FVM_DETAILS and FWF_SNAPTOGRID combination Pin
Leon Finker11-Nov-02 8:25
Leon Finker11-Nov-02 8:25 
Generalthumbnail display isn't kept Pin
luc218-Sep-02 3:53
luc218-Sep-02 3:53 
GeneralRe: thumbnail display isn't kept Pin
Anonymous26-Sep-02 11:55
Anonymous26-Sep-02 11:55 
GeneralRe: thumbnail display isn't kept Pin
rling7-Aug-03 20:43
rling7-Aug-03 20:43 
GeneralRe: thumbnail display isn't kept Pin
Anonymous5-Feb-04 1:15
Anonymous5-Feb-04 1:15 
GeneralRe: thumbnail display isn't kept Pin
Huang Wei22-Aug-04 22:19
Huang Wei22-Aug-04 22:19 
Questionwandered? Pin
Anonymous17-Jul-02 6:41
Anonymous17-Jul-02 6:41 
GeneralOpens New Window to display Sub folder instead of displaying it in the List View Pin
3-Oct-01 22:23
suss3-Oct-01 22:23 
GeneralRe: Opens New Window to display Sub folder instead of displaying it in the List View Pin
Leon Finker4-Oct-01 4:19
Leon Finker4-Oct-01 4:19 
GeneralOpening new Window Pin
3-Oct-01 21:52
suss3-Oct-01 21:52 
Questionwhere is the ENUMDESK sample ? Pin
3-Jul-01 21:30
suss3-Jul-01 21:30 
AnswerRe: where is the ENUMDESK sample ? Pin
Leon Finker4-Jul-01 5:20
Leon Finker4-Jul-01 5:20 

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.