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

  • U.S. companies are desperately trying to recruit and hire skilled software engineers and developers, but there is simply not enough quality talent to go around. Tiempo Development is a nearshore software development company. Our headquarters are in AZ, but we are a pioneer and leader in outsourcing to Mexico, based on our three software development centers there. We have a proven process and we are experts at providing our customers with powerful solutions. We transform ideas into reality.

  • When individual departments procure cloud service for their own use, they usually don't consider the hazardous organization-wide implications. Read this paper to learn best practices for setting up an internal, IT-based cloud brokerage function that service the entire organization. Find out how this approach enables you to retain top-down visibility and control of network security and manage the impact of cloud traffic on your WAN.

Most Popular Programming Stories

More for Developers

RSS Feeds

Thanks for your registration, follow us on our social networks to keep up-to-date