Is there an MFC class for an open directory dialog box, similar to CFileDialog? I can't seem to find one anywhere.
If there isn't, what is the best way to do such a box?
This is a discussion on MFC Open directory dialog box within the Windows Programming forums, part of the Platform Specific Boards category; Is there an MFC class for an open directory dialog box, similar to CFileDialog? I can't seem to find one ...
Is there an MFC class for an open directory dialog box, similar to CFileDialog? I can't seem to find one anywhere.
If there isn't, what is the best way to do such a box?
benforbes@optusnet.com.au
Microsoft Visual Studio .NET 2003 Enterprise Architect
Windows XP Pro
Code Tags
Programming FAQ
Tutorials
Here is an api version:
Code:static int CALLBACK BrowseCallbackProc(HWND hwnd,UINT uMsg, LPARAM lParam, LPARAM lpData) { // If the BFFM_INITIALIZED message is received // set the path to the start path. switch (uMsg) { case BFFM_INITIALIZED: { if (NULL != lpData) { SendMessage(hwnd, BFFM_SETSELECTION, TRUE, lpData); } } } return 0; // The function should always return 0. } // HWND is the parent window. // szCurrent is an optional start folder. Can be NULL. // szPath receives the selected path on success. Must be MAX_PATH characters in length. BOOL BrowseForFolder(HWND hwnd, LPCTSTR szCurrent, LPTSTR szPath) { BROWSEINFO bi = { 0 }; LPITEMIDLIST pidl; TCHAR szDisplay[MAX_PATH]; BOOL retval; CoInitialize(); bi.hwndOwner = hwnd; bi.pszDisplayName = szDisplay; bi.lpszTitle = TEXT("Please choose a folder."); bi.ulFlags = BIF_RETURNONLYFSDIRS | BIF_NEWDIALOGSTYLE; bi.lpfn = BrowseCallbackProc; bi.lParam = (LPARAM) szCurrent; pidl = SHBrowseForFolder(&bi); if (NULL != pidl) { retval = SHGetPathFromIDList(pidl, szPath); CoTaskMemFree(pidl); } else { retval = FALSE; } if (!retval) { szPath[0] = TEXT('\0'); } CoUninitialize(); return retval; }
Last edited by anonytmouse; 06-01-2004 at 05:13 AM.
Cool, thanks. I might chuck together a class and post it, if I can be bothered.
benforbes@optusnet.com.au
Microsoft Visual Studio .NET 2003 Enterprise Architect
Windows XP Pro
Code Tags
Programming FAQ
Tutorials