GetFolder : Shell Extension Folder Browser Function | CodeGuru

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 […]

Written By
CodeGuru Staff
CodeGuru Staff
Feb 13, 2001
2 minute read
CodeGuru content and product recommendations are editorially independent. We may make money when you click on links to our partners. Learn More



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.

Advertisement

Downloads

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

CodeGuru Logo

CodeGuru covers topics related to Microsoft-related software development, mobile development, database management, and web application programming. In addition to tutorials and how-tos that teach programmers how to code in Microsoft-related languages and frameworks like C# and .Net, we also publish articles on software development tools, the latest in developer news, and advice for project managers. Cloud services such as Microsoft Azure and database options including SQL Server and MSSQL are also frequently covered.

Property of TechnologyAdvice. © 2026 TechnologyAdvice. All Rights Reserved

Advertiser Disclosure: Some of the products that appear on this site are from companies from which TechnologyAdvice receives compensation. This compensation may impact how and where products appear on this site including, for example, the order in which they appear. TechnologyAdvice does not include all companies or all types of products available in the marketplace.