Select Folder dialog

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

Environment: Visual C++5, Windows NT 4 (SP3)

This Select Folder dialog was originally done by Mihai Filimon. I have added the following features -

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

Heres 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());

Downloads

Download demo project - 27 Kb



Comments

  • CSelectFolderDialog not working in VS2010

    Posted by Rinky on 01/22/2014 04:18am

    Please post the classes if they are updated for the selected folder dialog.

    Reply
  • Disable displayed files

    Posted by pmurgai on 12/30/2005 03:52pm

    My requirement is that the user should be able to select only folders and not the files. Is there a way to show files as disabled (grayed out) in the listbox so that the only option is to select folders ?

    Reply
  • Application crashed in VC.NET

    Posted by Legacy on 06/09/2003 12:00am

    Originally posted by: Dennis

    After clicking on the 'Show Dialog' button, the application crashes on the line

    pFD->GetDlgItem(edt1)->GetWindowRect(rectCurrFolderEB);

    It looks like the pFD->GetDlgItem(edt1) return a NULL pointer.

    This does not happen in VC6.0. Any idea on how to resolve this?

    Dennis

    Reply
  • when selecting c:\\winnt\fonts dir and exit dlg, it will result in error!

    Posted by Legacy on 08/02/2002 12:00am

    Originally posted by: liaohuanlin

    as title

    Reply
  • Path always created?

    Posted by Legacy on 07/11/2002 12:00am

    Originally posted by: Kevin Jackman

    When the "This path does not exist, do you want to create it?" dialog appears, selecting 'NO' creates it anyway.
    
    

    Adding 'else return NULL' seems to fix it

    if(AfxMessageBox(cstrPath + _T("\n") + _T("\n") +_T("This path does not exist. Do you want to create it?"),
    MB_YESNO | MB_ICONQUESTION) == IDYES)
    {
    .....
    }
    else return NULL; // this line has been added

    I have inherited this code from a colleague,so I apologise if this comment is inaccurate.

    Reply
  • There have some leak of User objects

    Posted by Legacy on 06/17/2002 12:00am

    Originally posted by: David

    show it , user objects will add and donn't release.
    how to resolve it?

    Reply
  • MakeSureDirectoryPathExists and unicode

    Posted by Legacy on 02/06/2001 12:00am

    Originally posted by: Alan

    Does anyone know if a unicode version of this call exists ?

    Reply
  • Context sensitive help

    Posted by Legacy on 10/30/2000 12:00am

    Originally posted by: Rick Bogard

    I noticed that when you use the "?" button to get help, that the "Select" button displays the help for an "Open" button. Is there any way to change this behavior?

    Reply
  • Can't force folder to exist

    Posted by Legacy on 08/16/2000 12:00am

    Originally posted by: Carnegie

    Is it possible to force the user to select an existing directory?
    I've tried using both OFN_FILEMUSTEXIST and OFN_PATHMUSTEXIST, but neither changes the behaviour of the dialog box if a nonexistant path is entered in the text box - the 'Path does not exist, do you wish to create it' message is still displayed.

    I want the user to be able to type the path as well as select it with the mouse, so I can't just set the edit box to Read Only.

    Still a great piece of code though.

    Reply
  • Can't select folders from the network

    Posted by Legacy on 11/02/1999 12:00am

    Originally posted by: Shirly Armin

    Hi,

    I use this class and it's very cool , BUTTT -->
    When trying to select a folder from the network :
    for example : "\\websql\student\" ,
    an Error Message Box ""Invalid Folder" is displayed.
    I'v found your remark in the source :

    //If the user has entered something like
    "c:\\windows\\\\system"
    //this is invalid but _access returns valid if this string is passed to
    //it. So before giving it to _access validate it.

    So, This is A Problem!!!!!!!

    Reply
  • Loading, Please Wait ...

Leave a Comment
  • Your email address will not be published. All fields are required.

Top White Papers and Webcasts

  • Live Event Date: November 20, 2014 @ 2:00 p.m. ET / 11:00 a.m. PT Are you wanting to target two or more platforms such as iOS, Android, and/or Windows? You are not alone. 90% of enterprises today are targeting two or more platforms. Attend this eSeminar to discover how mobile app developers can rely on one IDE to create applications across platforms and approaches (web, native, and/or hybrid), saving time, money, and effort and introducing apps to market faster. You'll learn the trade-offs for gaining long …

  • IBM Worklight is a mobile application development platform that lets you extend your business to mobile devices. It is designed to provide an open, comprehensive platform to build, run and manage HTML5, hybrid and native mobile apps.

Most Popular Programming Stories

More for Developers

Latest Developer Headlines

RSS Feeds