Introduction
Searching across the net, I was not able to find any clear examples on how to use CFolderPickerDialog
. Therefore, I thought I would share the following example with you.
Background
Being comfortable using CFileDialog
will help, but it is not essential.
Using the Code
The code can be copied and pasted from the section below. The code was used in VS 2013 Community Edition in a MFC dialog based application.
CFolderPickerDialog m_dlg;
CString m_Folder;
m_dlg.m_ofn.lpstrTitle = _T("Put your title here");
m_dlg.m_ofn.lpstrInitialDir = _T("C:\\");
if (m_dlg.DoModal() == IDOK) {
m_Folder = m_dlg.GetPathName();
m_Folder += _T("\\");
UpdateData(FALSE);
TRACE("\n%S", m_Folder);
}
Points of Interest
Previously, I thought OFN had to be declared and used separately, whereas now it appears to be part of the dialog object. Maybe I’m thinking too far back as I last used VC++ 6.0 and have only recently moved to the VS2013 Community.
History
- 1.0 Initial release
- 1.1 Corrected HTML translation typos in the example code