The Wayback Machine - https://web.archive.org/web/20140823164758/http://www.codeguru.com:80/cpp/w-p/files/browserfunctionsdialogs/article.php/c4465/GetFolder--Shell-Extension-Folder-Browser-Function.htm

GetFolder : Shell Extension Folder Browser Function


Folder browser dialog - also enumerates network drives...


...demo application shows how easy it is to display dialog and retrieve user-selected folder.

Overview

This is a very standard technique used to retrieve folder information from Windows using the Shell extension functions SHBrowseForFolderA, SHGetPathFromIDList and SHGetDesktopFolder.

The Code

All you need to do is to call my function GetFolder. However, for the more curious among you that want to know more of the details, there are only two functions used here: one to cause the display of the standard folder browser dialog and a callback function that handles the processing of events while the dialog is being displayed). Here are the basic steps in my code.

GetFolder Steps

  1. Call SHGetDesktopFolder to get the IShellFolder interface for the desktop folder
  2. Call the IShellFolder.ParseDisplayName to get the identifier list
  3. Allocate and fill out a BROWSEINFOA structure with the desired parameters (e.g., pidl from the IShellFolder.ParseDisplayName, callback function that the shell will call with the folder names, etc.). The callback function is called BrowseCallbackProc.
  4. Call SHBrowseForFolderA to display the folder browse dialog (passing it the BROWSEINFOA structure which defines how that dialog should appear)
  5. Upon return from the SHBrowseForFolderA function, I then call the SHGetPathFromIDList function in order to retrieve the name of the user-selected folder.

BrowseCallbackProc Function

In this function I only need to handle the BFFM_INITIALIZED and the BFFM_SELCHANGED messages. Even then, all I'm doing is updating a field on the dialog to reflect the currently selected folder. This is the text that I retrieve in the last step of the GetFolder function.

Downloads

Download source and demo (including release build) - 18 Kb


Comments

Top White Papers and Webcasts

  • Live Event Date: September 10, 2014 @ 11:00 a.m. ET / 8:00 a.m. PT Modern mobile applications connect systems-of-engagement (mobile apps) with systems-of-record (traditional IT) to deliver new and innovative business value. But the lifecycle for development of mobile apps is also new and different. Emerging trends in mobile development call for faster delivery of incremental features, coupled with feedback from the users of the app "in the wild". This loop of continuous delivery and continuous feedback is …

  • As everyone scrambles to protect customers and consumers from the Heartbleed virus, there will be a variety of mitigating solutions offered up to address this pesky bug. There are a variety of points within the data path where solutions could be put into place to mitigate this (and similar) vulnerabilities and customers must choose the most strategic point in the network at which to deploy their selected mitigation. Read this white paper to learn the ins and outs of mitigating the risk of Heartbleed and the …

Most Popular Programming Stories

More for Developers

Latest Developer Headlines

RSS Feeds