Click here to Skip to main content
11,477,625 members (73,093 online)
Click here to Skip to main content

Select Folder dialog with a difference

, 24 Aug 2000 CPOL 140K 1.6K 36
Rate this:
Please Sign up or sign in to vote.
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)

Share

About the Author

Sridhar Rao
Software Developer (Senior) Philips Electronics India Limited
India India
No Biography provided

Comments and Discussions

 
Questioncrash on visual studio 2010 Pin
kerfall1-Aug-11 4:16
memberkerfall1-Aug-11 4:16 
AnswerRe: crash on visual studio 2010 Pin
kerfall1-Aug-11 4:37
memberkerfall1-Aug-11 4:37 
GeneralGot an Exception when using SelectFolder dialog in visual c++ 2005 Pin
salimon24-Mar-10 6:55
membersalimon24-Mar-10 6:55 
GeneralRe: Got an Exception when using SelectFolder dialog in visual c++ 2005 Pin
Sridhar Rao13-Apr-10 23:30
memberSridhar Rao13-Apr-10 23:30 
GeneralReally useful! Pin
DTardio25-Sep-08 4:11
memberDTardio25-Sep-08 4:11 
QuestionException using in VS2005 [modified] Pin
David_Leikis7-Mar-07 7:26
memberDavid_Leikis7-Mar-07 7:26 
GeneralCan't use in a library Pin
David_Leikis16-Feb-06 6:47
memberDavid_Leikis16-Feb-06 6:47 
GeneralBug when creating wrong folder in the Edit box Pin
Veronique72211-Aug-05 12:13
memberVeronique72211-Aug-05 12:13 
GeneralRe: Bug when creating wrong folder in the Edit box Pin
Rail Jon Rogut22-Nov-05 10:26
memberRail Jon Rogut22-Nov-05 10:26 
GeneralCrashes on Windows XP Pin
Thorell25-Apr-03 2:02
memberThorell25-Apr-03 2:02 
GeneralRe: Crashes on Windows XP Pin
Rail Jon Rogut6-Jul-03 22:06
memberRail Jon Rogut6-Jul-03 22:06 
GeneralStandard dialog to browse folders Pin
Comet21-Jan-03 23:31
memberComet21-Jan-03 23:31 
GeneralRe: Standard dialog to browse folders Pin
Benny 67318-Mar-04 4:57
sussBenny 67318-Mar-04 4:57 
GeneralDisable Create-Folder. Pin
Thomas Moch14-Nov-02 4:03
sussThomas Moch14-Nov-02 4:03 
GeneralDon't work on VC7! Pin
Kondriks6-Jul-02 10:07
memberKondriks6-Jul-02 10:07 
Questionmultiple directory select? Pin
Juergen Klingler15-May-02 3:44
memberJuergen Klingler15-May-02 3:44 
GeneralFit a dialog in a View of a Window Pin
Anonymous17-Apr-02 9:47
memberAnonymous17-Apr-02 9:47 
Questionworking without mouse -- impossible? Pin
Anonymous14-Feb-02 19:17
memberAnonymous14-Feb-02 19:17 
Generalnetwork name compatibility Pin
Anonymous5-Jul-01 23:32
memberAnonymous5-Jul-01 23:32 
Generalanother little error ... Pin
thom_as3-Jul-02 5:15
memberthom_as3-Jul-02 5:15 
GeneralRe: another little error ... Pin
Ales Krajnc29-Aug-02 4:00
memberAles Krajnc29-Aug-02 4:00 
GeneralSmall Error Pin
Anonymous10-May-01 11:47
memberAnonymous10-May-01 11:47 
QuestionIs this OK on Win95/98/ME ? Pin
Jerry Evans4-Oct-00 9:28
sussJerry Evans4-Oct-00 9:28 
AnswerRe: Is this OK on Win95/98/ME ? Pin
Sridhar4-Oct-00 21:14
sussSridhar4-Oct-00 21:14 
GeneralRe: Is this OK on Win95/98/ME ? Pin
Jeremy Davis5-Oct-00 0:05
sussJeremy Davis5-Oct-00 0:05 
GeneralRe: Is this OK on Win95/98/ME ? Pin
Sridhar9-Oct-00 21:59
sussSridhar9-Oct-00 21:59 

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

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

| Advertise | Privacy | Terms of Use | Mobile
Web03 | 2.8.150520.1 | Last Updated 25 Aug 2000
Article Copyright 2000 by Sridhar Rao
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid