Click here to Skip to main content
6,595,444 members and growing! (19,856 online)
Email Password   helpLost your password?
Desktop Development » Dialogs and Windows » Windows Common dialogs     Intermediate

Select Folder dialog with a difference

By Sridhar Rao

The Windows 'Select Folder' dialog with some extra functionality.
VC6, Windows, MFC, Dev
Posted:24 Aug 2000
Views:111,700
Bookmarked:31 times
Announcements
Loading...
 
Search    
Advanced Search
Add to IE Search
printPrint   add Share
      Discuss Discuss   Broken Article?Report  
23 votes for this article.
Popularity: 5.45 Rating: 4.00 out of 5
2 votes, 14.3%
1

2
3 votes, 21.4%
3
2 votes, 14.3%
4
7 votes, 50.0%
5

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 has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

About the Author

Sridhar Rao


Member

Occupation: Software Developer (Senior)
Company: Philips Electronics India Limited
Location: India India

Other popular Dialogs and Windows articles:

Article Top
You must Sign In to use this message board.
FAQ FAQ 
 
Noise Tolerance  Layout  Per page   
 Msgs 1 to 22 of 22 (Total in Forum: 22) (Refresh)FirstPrevNext
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  
Generalmultiple directory select? PinmemberJuergen Klingler3:44 15 May '02  
GeneralFit a dialog in a View of a Window PinmemberAnonymous9:47 17 Apr '02  
Generalworking 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  
GeneralIs this OK on Win95/98/ME ? PinsussJerry Evans9:28 4 Oct '00  
GeneralRe: 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  
GeneralRe: Is this OK on Win95/98/ME ? PinsussSridhar21:59 9 Oct '00  

General General    News News    Question Question    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

PermaLink | Privacy | Terms of Use
Last Updated: 24 Aug 2000
Editor: Smitha Vijayan
Copyright 2000 by Sridhar Rao
Everything else Copyright © CodeProject, 1999-2009
Web22 | Advertise on the Code Project