Imitating Windows Explorer


Desktop-as-a-Service Designed for Any Cloud ? Nutanix Frame

I wandered 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_TERMINATEWM_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 so we could use it correctly.  In the MSDN they state, "You do not implement this interface directly. IShellBrowser is implemented by Windows Explorer and by the Windows File Open common dialog box." 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:


Sample for enumerating/navigating folders/files (comes with PSDK) I have it under
C:\Program Files\Microsoft Platform SDK\Samples\WinUI\Shell

Q157247 - PRB: IShellFolder::CreateViewObject() Causes Access Violation




Comments in the Shell Object Header File (shlobj.h) are useful.


Explorer.zip - 14.2K


  • events and class wizard

    Posted by Legacy on 06/06/2001 07:00am

    Originally posted by: HotRod

    since the class wizard will not work with a WTL project, do you have to write all the notify event handlers yourself?

  • thanx leon....another question

    Posted by Legacy on 06/06/2001 07:00am

    Originally posted by: HotRod

    what i'm trying to do is allow the user to change the label of a tree item. after it's been selected, another click will put the label into edit mode. you can make changes, but when you hit enter, the label reverts back to what it was. i think i need to handle the TVN_ENDLABELEDIT event, but i can't seem to set it up right.
    i don't think the method you described in your last post will work because the tree view control doesn't exist at design time.

    this is what i've tried:

    LRESULT OnEndLabelEdit(NMHDR* pNMHDR, LRESULT* pResult) ;





    it tells me that OnEndLabelEdit doesn't take 3 parameters, even though i've only got 2.

    any thoughts?

  • How to detect folder open...

    Posted by Legacy on 05/29/2001 07:00am

    Originally posted by: Andy Marks

    I implemented a multi-pane Explorer (essentially
    just File Manager with Win95 GUI) using these methods.

    Anyway, if you implement ICommDlgBrowser, you can
    tell when the user has selected to open a folder because
    the OnDefaultCommand method is called. But using
    ICommDlgBrowser isn't so good because you don't get some
    UI features because the namespace thinks you are a dialog.

    Another way, which I used, was to implement a ShellExecute
    hook (IShellExecuteHook) in a separate DLL. Explorer
    calls ShellExecute() to open new folders, so you can tell
    when your app is supposed open a new folder, cancel the
    ShellExecute call, and do it yourself. What my
    hook does is get the top most window of the current process
    and then sends it a custom Windows message, also passing
    the address of the SHELLEXECUTEINFO struct. I then have
    a handler for this message in my app, which returns a
    certain value so that the hook can look at the return value and then determine whether or not to cancel the ShellExecute.

  • explorer

    Posted by Legacy on 05/27/2001 07:00am

    Originally posted by: sheraz

    where is the .DSw file

  • Help me where is atlres.h ?

    Posted by Legacy on 05/24/2001 07:00am

    Originally posted by: NguyenZ

    I can not compile project because of missing "atlres.h".
    Please help me.

  • You must have javascript enabled in order to post comments.

Leave a Comment
  • Your email address will not be published. All fields are required.

Most Popular Programming Stories

More for Developers

RSS Feeds

Thanks for your registration, follow us on our social networks to keep up-to-date