Click here to Skip to main content
Click here to Skip to main content

Select Folder dialog with a difference

, 24 Aug 2000 CPOL
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 Pinmemberkerfall1-Aug-11 4:16 
AnswerRe: crash on visual studio 2010 Pinmemberkerfall1-Aug-11 4:37 
GeneralGot an Exception when using SelectFolder dialog in visual c++ 2005 Pinmembersalimon24-Mar-10 6:55 
GeneralRe: Got an Exception when using SelectFolder dialog in visual c++ 2005 PinmemberSridhar Rao13-Apr-10 23:30 
GeneralReally useful! PinmemberDTardio25-Sep-08 4:11 
QuestionException using in VS2005 [modified] PinmemberDavid_Leikis7-Mar-07 7:26 
GeneralCan't use in a library PinmemberDavid_Leikis16-Feb-06 6:47 
GeneralBug when creating wrong folder in the Edit box PinmemberVeronique72211-Aug-05 12:13 
GeneralRe: Bug when creating wrong folder in the Edit box PinmemberRail Jon Rogut22-Nov-05 10:26 
GeneralCrashes on Windows XP PinmemberThorell25-Apr-03 2:02 
GeneralRe: Crashes on Windows XP PinmemberRail Jon Rogut6-Jul-03 22:06 
GeneralStandard dialog to browse folders PinmemberComet21-Jan-03 23:31 
GeneralRe: Standard dialog to browse folders PinsussBenny 67318-Mar-04 4:57 
GeneralDisable Create-Folder. PinsussThomas Moch14-Nov-02 4:03 
GeneralDon't work on VC7! PinmemberKondriks6-Jul-02 10:07 
Questionmultiple directory select? PinmemberJuergen Klingler15-May-02 3:44 
GeneralFit a dialog in a View of a Window PinmemberAnonymous17-Apr-02 9:47 
Questionworking without mouse -- impossible? PinmemberAnonymous14-Feb-02 19:17 
Generalnetwork name compatibility PinmemberAnonymous5-Jul-01 23:32 
Generalanother little error ... Pinmemberthom_as3-Jul-02 5:15 
GeneralRe: another little error ... PinmemberAles Krajnc29-Aug-02 4:00 
GeneralSmall Error PinmemberAnonymous10-May-01 11:47 
QuestionIs this OK on Win95/98/ME ? PinsussJerry Evans4-Oct-00 9:28 
AnswerRe: Is this OK on Win95/98/ME ? PinsussSridhar4-Oct-00 21:14 
GeneralRe: Is this OK on Win95/98/ME ? PinsussJeremy Davis5-Oct-00 0:05 
GeneralRe: Is this OK on Win95/98/ME ? PinsussSridhar9-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
Web01 | 2.8.141220.1 | Last Updated 25 Aug 2000
Article Copyright 2000 by Sridhar Rao
Everything else Copyright © CodeProject, 1999-2014
Layout: fixed | fluid