Click here to Skip to main content
15,915,019 members
Articles / Desktop Programming / MFC
Article

Select Folder dialog with a difference

Rate me:
Please Sign up or sign in to vote.
4.22/5 (14 votes)
24 Aug 2000CPOL 170.4K   1.8K   38   26
The Windows 'Select Folder' dialog with some extra functionality.

Sample Image - SelectFolder.gif

Introduction

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 -

  1. Added an edit control where the user can type in the path
  2. If the path typed in the edit control does not exist then the user will be prompted 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);

Here's 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());

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer (Senior) Philips Electronics India Limited
India India
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
GeneralRe: Is this OK on Win95/98/ME ? Pin
sridhar9-Oct-00 20:59
sridhar9-Oct-00 20:59 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.