Thursday, December 31, 2009

Local file system browsing, WebBrowser control, Windows 7 and in-place navigation? Don’t. Use Windows API Code Pack / Explorer Browser control instead

EricLaw's IEInternals - 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:

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.

Workaround #1: Switch to use the ExplorerBrowser object (recommended)

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…

image

…”

MSDN Code Gallery - Windows® API Code Pack for Microsoft® .NET Framework

“…

The individual features supported in this version (v1.0.1) of the library are:

  • Windows 7 Taskbar
    • Jump Lists, Icon Overlay, Progress Bar, Tabbed Thumbnails, and Thumbnail Toolbars
  • Windows Shell
    • Windows 7 Libraries
    • Windows Shell Search API support
    • Explorer Browser Control
    • A hierarchy of Shell Namespace entities
    • Windows Shell property system
    • Drag and Drop for Shell Objects
    • Windows Vista and Windows 7 Common File Dialogs, including custom controls
    • Known Folders and non-file system containers

Video Demo of Explorer Browser

…”

I love learning something every day. The joy of growth and discovery is what make this job so darn cool…

I’ve of course known about the Windows API Code Pack for forever (since it was known as the Vista Bridge) but I’m still feel like a newbe and it seems that a week doesn’t go by where I don’t learn more about it. I’ve been focused on the sexy features like multi-touch, etc and the Bowser Control just didn’t register.

Well thanks to Eric’s post, that’s been taken care of.

The Explorer Browser is a pretty cool looking control that I can see using in a number of ways…

 

Here’s a snap of the Explorer Browser sample included with the Windows API Code Pack source;

image

 

Related Past Post XRef:
More Windows Code Pack and Windows 7 developing delightfulness
Windows 7, VS2010, WPF all mixed together DevX article style
Windows 7 for Dev’s – One getting started page to rule them all?
Channel 9 makes you smart(er) - Channel 9 Learning Center opens with VS2010/.Net 4 and Windows 7 courses (free of course)
More Windows 7 Dev Help, Information, Training and such – Windows 7 Training Kit for Developers and Windows 7 SDK
Windows 7 Code Pack v1.0 Released – Managed code to help get at the yummy Windows 7 filling…
Bridging to Managed Windows 7 Development – Vista Bridge to Windows Code Pack
Vista Bridge v1.4 Released – Now with custom controls for Common File Dialogs, BreadCrumb control and Aero Glass
Vista Bridge (v1.3) available on MSDN Code Gallery
It’s the Bridge to… Vista – Getting and installing Vista Bridge Sample Library

No comments: