Click here to Skip to main content
Licence CPOL
First Posted 24 Aug 2000
Views 127,855
Downloads 1,401
Bookmarked 35 times

Select Folder dialog with a difference

By Sridhar Rao | 24 Aug 2000
The Windows 'Select Folder' dialog with some extra functionality.
2 votes, 14.3%
1

2
3 votes, 21.4%
3
2 votes, 14.3%
4
7 votes, 50.0%
5
4.22/5 - 23 votes
2 removed
μ 4.00, σa 2.56 [?]

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)

About the Author

Sridhar Rao

Software Developer (Senior)
Philips Electronics India Limited
India India

Member


Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page   
  Refresh
Questioncrash on visual studio 2010 Pinmemberkerfall4:16 1 Aug '11  
AnswerRe: crash on visual studio 2010 Pinmemberkerfall4:37 1 Aug '11  
GeneralGot an Exception when using SelectFolder dialog in visual c++ 2005 Pinmembersalimon6:55 24 Mar '10  
GeneralRe: Got an Exception when using SelectFolder dialog in visual c++ 2005 PinmemberSridhar Rao23:30 13 Apr '10  
GeneralReally useful! PinmemberDTardio4:11 25 Sep '08  
QuestionException using in VS2005 [modified] PinmemberDavid_Leikis7:26 7 Mar '07  
GeneralCan't use in a library PinmemberDavid_Leikis6:47 16 Feb '06  
GeneralBug when creating wrong folder in the Edit box PinmemberVeronique72212:13 11 Aug '05  
GeneralRe: Bug when creating wrong folder in the Edit box PinmemberRail Jon Rogut10:26 22 Nov '05  
GeneralCrashes on Windows XP PinmemberThorell2:02 25 Apr '03  
GeneralRe: Crashes on Windows XP PinmemberRail Jon Rogut22:06 6 Jul '03  
GeneralStandard dialog to browse folders PinmemberComet23:31 21 Jan '03  
GeneralRe: Standard dialog to browse folders PinsussBenny 6734:57 18 Mar '04  
GeneralDisable Create-Folder. PinsussThomas Moch4:03 14 Nov '02  
GeneralDon't work on VC7! PinmemberKondriks10:07 6 Jul '02  
Questionmultiple directory select? PinmemberJuergen Klingler3:44 15 May '02  
GeneralFit a dialog in a View of a Window PinmemberAnonymous9:47 17 Apr '02  
Questionworking without mouse -- impossible? PinmemberAnonymous19:17 14 Feb '02  
Generalnetwork name compatibility PinmemberAnonymous23:32 5 Jul '01  
Generalanother little error ... Pinmemberthom_as5:15 3 Jul '02  
GeneralRe: another little error ... PinmemberAles Krajnc4:00 29 Aug '02  
GeneralSmall Error PinmemberAnonymous11:47 10 May '01  
QuestionIs this OK on Win95/98/ME ? PinsussJerry Evans9:28 4 Oct '00  
AnswerRe: Is this OK on Win95/98/ME ? PinsussSridhar21:14 4 Oct '00  
GeneralRe: Is this OK on Win95/98/ME ? PinsussJeremy Davis0:05 5 Oct '00  

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.

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