CFolderDialog is an MFC based class that encapsulates the Windows Shell function for browsing folders, ::ShBrowseForFolder.
To use it, you create an instance of
CFolderDialog and call the
Upon return, the method
GetPathName can be used to retrieve the path to the user selected folder.
The constructor allows you to specify an optional initial folder, flags specific to the shell function (see the description of the
ulFlags field of the
BROWSEINFO structure in the help for Visual Studio or the Windows Shell API) and a pointer to the parent window’s
CWnd. All of these arguments are optional.
You may override the two virtual methods
OnSelChanged in a derived class to customize their behavior.
The default behavior of
OnInitDialog is to call
SetStatusText with the folder name provided in the constructor.
The default version of
OnSelChanged places the new path into the status text area of the dialog.
The class provides utility functions for 1) enabling or disabling the OK button (
EnableOK), 2) setting the status text that appears above the folder list box in the browser folder dialog box (
SetStatusText) and 3) setting the current selection (
MyFolderDialog.h, included in the zip file, shows an example of a derived class which uses
For advanced users, the
BROWSEINFO structure is available via the
m_bi member variable.
This structure is initialized by the constructor and any changes should be made before the call to DoModal.
See the help for Visual Studio or the Windows Shell API for more information on the
The zip file also contains the source for CMyFolderDialog, a class derived from CFolderDialog to show how to take advantage of some of the advanced features.
December 29, 1998Added the CMyFolderDialog source code the version available on the codeguru site.
June 23, 1998Fixed a problem in EnableOK. The documenation for the SHBrowseForFolder call back incorrectly states that it is the wParam on the BFFM_ENABLEOK message which controls the enabling/disabling of the OK button.
However, It is actually the lParam. Thanks to Langis Pitre for finding this one. April 5, 1998Changed the way status text is handled:
- The constructor now forces the
BIF_STATUSTEXTflag to be set
- Changed the base
OnInitDialogmethod to display the initial folder in the status text.
- Changed the base
OnSelChangedmethod to update the contents of m_strFinalFolderName and display the new folder in the status text area.
- Removed the
MyFolderDialog.hfile from the zip.
Bugs And Suggestions
Please send suggestions and/or bugs to [email protected].
Ken Reed Download source code - 6 KB
Date Last Updated: February 3, 1999
- Another feature -> Function to set the root path - Jose Insa (2000/02/22)
- Just what I needed - Glenn (1999/12/12)
- Is it free to use? - Magnus Zakrisson (1999/11/26)
- MFC Wrapper for SHBrowseForFolder - Adina Milston (1999/08/16)
- let's simplify this a bit folks... - I can do that in 5 lines! (1999/03/03)
- Name of dialog... - Nicola Fagan (1999/02/19)
- Where's the code? - Chuck Messenger (1999/02/10)
- A minor enhancement to the Folder Browser Dialog - Kent S Kapitan (1999/01/07)