In-Place Shell Navigation with the WebBrowser Control on Windows 7

Because the WebBrowser Control (WebOC) can be used to display a wide range of content (HTML, Office Documents, PDFs, the local file-system, etc) it is often integrated into applications as a somewhat generic object hosting surface. For Windows 7, a small change was made that will impact applications that use the WebOC to allow the user to explore the local file system.

By way of example, here’s a trivial little WebOC host which displays the Windows folder:

Web Browser control showing C:\Windows folder

On Windows Vista and below, the user may double-click on a folder to navigate the WebOC to that folder, like so:

Web Browser control showing C:\Windows\AppPatch subfolder

However, on Windows 7, double-clicking on the folder will open a Windows Explorer window instead:

Windows Explorer launched by WebOC

The change in behavior exists because of a small change made in the Windows 7 Shell. Specifically, the filesystem viewing object will not navigate in-place unless the host container supports SID_SInPlaceBrowser, which is defined in the Windows 7 SDK (see shlguid.h). By default, the WebBrowser control’s QueryService implementation does not support SID_SInPlaceBrowser, so the filesystem viewing object will launch a new Windows Explorer instance when the user double-clicks on a folder in the WebOC.

For WebOC-hosting applications that are impacted by this change, two workarounds are available.

Windows Vista’s Shell introduced a new control which implements the IExplorerBrowser interface; this is the recommended method of hosting a Windows Shell filesystem view within your application. Developers building applications using .NET can use the wrapped version of the ExplorerBrowser control available in the Windows API CodePack for .NET.

Please note that this interface is only available on Windows Vista and later. If your application needs to run on earlier Windows versions, you will need to fallback to the old WebOC implementation on those platforms.

Workaround #2: Handle SID_SInPlaceBrowser

As noted in the previous section, using the ExplorerBrowser control is the supported and recommended method for hosting a filesystem view within your application.

Having said that, you may be able to make a small change to your application to enable the filesystem object to navigate in-place within the WebOC when running on Windows 7. To do so, your hosting application will implement the IServiceProvider interface, and hand back the WebBrowser control’s SID_SShellBrowser when asked for SID_SInPlaceBrowser:

    1: // IServiceProvider
    2: IFACEMETHODIMP QueryService(__in REFGUID guidService, __in REFIID riid, __deref_out void **ppv)
    3: {
    4:     *ppv = NULL;
    5:     HRESULT hr = E_NOINTERFACE;
    6:     if (guidService == SID_SInPlaceBrowser)
    7:     {
    8:         hr = IUnknown_QueryService(_spBrowser, SID_SShellBrowser, riid, ppv);
    9:     }
   10:     return hr;
   11: }

By doing this, the filesystem viewer object will believe its host supports SID_SInPlaceBrowser and will navigate in place as the user double-clicks on folders.

Happy New Year, and thanks for reading! IEInternals is now just over seven months old, and this is post #63. I’m confident that next year, I’ll have even more to share. :-D

-Eric

Update 3/14/2011: Workaround #3: Install IE9 on the affected client. IE9 RC included a fix for this issue (basically, Workaround #2 is built into IE itself).