Select Folder dialog | CodeGuru

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 […]

Written By
CodeGuru Staff
CodeGuru Staff
Jul 29, 1999
2 minute read
CodeGuru content and product recommendations are editorially independent. We may make money when you click on links to our partners. Learn More

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

CodeGuru Logo

CodeGuru covers topics related to Microsoft-related software development, mobile development, database management, and web application programming. In addition to tutorials and how-tos that teach programmers how to code in Microsoft-related languages and frameworks like C# and .Net, we also publish articles on software development tools, the latest in developer news, and advice for project managers. Cloud services such as Microsoft Azure and database options including SQL Server and MSSQL are also frequently covered.

Property of TechnologyAdvice. © 2026 TechnologyAdvice. All Rights Reserved

Advertiser Disclosure: Some of the products that appear on this site are from companies from which TechnologyAdvice receives compensation. This compensation may impact how and where products appear on this site including, for example, the order in which they appear. TechnologyAdvice does not include all companies or all types of products available in the marketplace.