Select Folder dialog

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

Environment: Visual C++5, Windows NT 4 (SP3)

This Select Folder dialog was originally done by

Mihai Filimon
. I have added the following features –

  1. Added a edit control where the user can type in the path
  2. 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
  3. Setting the flag bShowFilesInDir to TRUE will result in
    all the files in the current folder to be displayed in
    the dialog
  4. 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

  1. Calling API SetTitle with the desired title will set the
    Title of the dialog. This API has to be invoked before
    DoModal is called
  2. 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

More by Author

Get the Free Newsletter!

Subscribe to Developer Insider for top news, trends & analysis

Must Read