
Introduction
File browsing in MFC is easy due to the included CFileDialog
class. CFolderDlg
wraps the SDK's SHBrowseForFolder
function and makes folder browsing as easy as file browsing.
Features
The programmer can specify an initial folder. The user can create new folders. The dialog is resizable.
Using the code
You can get the name of a user selected folder in three lines of code:
CFolderDlg dlg(TRUE, m_folder, this);
if (dlg.DoModal() == IDCANCEL) return;
m_folder = dlg.GetFolderName();
If you want to give some extra information to the user, you can add the following line:
dlg.SetTitle("Any instructions...");
The CFolderDlg
constructor looks like this:
CFolderDlg(BOOL HideNewFolderButton,
const CString& InitialFolder, CWnd* pParent);
Points of Interest
If you are using Microsoft Visual C++ 6.0 (as I am), you will have to upgrade your Software Development Kit (SDK):
- Download the ISO version.
- Use DAEMON Tools to install the SDK.
- Replace your include folders:
out:
- ...\MICROSOFT VISUAL STUDIO\VC98\<any>
in:
- ...\MICROSOFT PLATFORM SDK\INCLUDE
- ...\MICROSOFT PLATFORM SDK\INCLUDE\MFC
- ...\MICROSOFT PLATFORM SDK\INCLUDE\ATL
- ...\MICROSOFT PLATFORM SDK\INCLUDE\CRT
If your compiler can't find CoInitializeEx()
, add #define _WIN32_DCOM
to your stdafx.h.
History
Version 1.0
Added:
- The programmer can specify an initial folder.
- The user can create new folders.
- The dialog is resizable.