Select Folder dialog
Posted
by S. Sridhar
on July 29th, 1999
The SelectFolder.zip file contains the SelectFolder.exe whose output is shown in the above picture. The "Options of Select Folder dialog" dialog shown in the above picture, shows the capabilities of the CSelectFolder class
This Select Folder dialog was originally done by Mihai Filimon. I have added the following features -
- Added a edit control where the user can type in the path
- If the path typed in the edit ctrl does not exist then the user will be propmted as to whether he/she wants the path to be created
- Setting the flag bShowFilesInDir to TRUE will result in all the files in the current folder to be displayed in the dialog
- If you don't want to display all the files then you can use the file filter to display the file types you want to display
Some more additional features
- Calling API SetTitle with the desired title will set the Title of the dialog. This API has to be invoked before DoModal is called
- User can pass the Initial Folder to be displayed in the constructor of CSelectFolder
Constructor
CSelectFolderDialog(BOOL bShowFilesInDir = FALSE, LPCSTR lpcstrInitialDir = NULL, DWORD dwFlags = OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,LPCTSTR lpszFilter = NULL, CWnd* pParentWnd = NULL);
Usage Examples
- CSelectFolderDialog oSelectFolderDialog(FALSE, NULL,OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,NULL, NULL);
- CSelectFolderDialog oSelectFolderDialog(FALSE, "c:\\my documents",OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,NULL, NULL);
- CSelectFolderDialog oSelectFolderDialog(TRUE, "c:\\my documents",OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,NULL, NULL);
- CSelectFolderDialog oSelectFolderDialog(TRUE, "c:\\my documents",OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,"Microsoft Word Documents (*.doc)|*.doc|Microsoft Excel Worksheets (*.xls)|*.xls|", NULL);
- CSelectFolderDialog oSelectFolderDialog(TRUE, "c:\\my documents",OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,"HTML Files (*.html, *.htm)|*.html;*.htm||", NULL);
Heres a complete example on how i got the select folder dialog shown in the above picture
CSelectFolderDialog oSelectFolderDialog(TRUE, "C:\WINNT", OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT, "Microsoft Word Documents (*.doc)|*.doc|Microsoft Excel Worksheets (*.xls)|*.xls|", this); if (oSelectFolderDialog.DoModal() == IDOK) AfxMessageBox(oSelectFolderDialog.GetSelectedPath());
Downloads
Download demo project - 27 Kb