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 -
- Added a edit control where the user can type in the path
- 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
- Setting the flag bShowFilesInDir to TRUE will result in all the files in the current folder to be displayed in the dialog
- 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
- Calling API SetTitle with the desired title will set the Title of the dialog. This API has to be invoked before DoModal is called
- 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());

Comments
Disable displayed files
Posted by pmurgai on 12/30/2005 03:52pmMy 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 ?
ReplyApplication crashed in VC.NET
Posted by Legacy on 06/09/2003 12:00amOriginally 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
Replywhen selecting c:\\winnt\fonts dir and exit dlg, it will result in error!
Posted by Legacy on 08/02/2002 12:00amOriginally posted by: liaohuanlin
as title
ReplyPath always created?
Posted by Legacy on 07/11/2002 12:00amOriginally posted by: Kevin Jackman
Reply
There have some leak of User objects
Posted by Legacy on 06/17/2002 12:00amOriginally posted by: David
show it , user objects will add and donn't release.
Replyhow to resolve it?
MakeSureDirectoryPathExists and unicode
Posted by Legacy on 02/06/2001 12:00amOriginally posted by: Alan
Does anyone know if a unicode version of this call exists ?
ReplyContext sensitive help
Posted by Legacy on 10/30/2000 12:00amOriginally 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?
ReplyCan't force folder to exist
Posted by Legacy on 08/16/2000 12:00amOriginally 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.
ReplyCan't select folders from the network
Posted by Legacy on 11/02/1999 12:00amOriginally 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!!!!!!!
ReplyCan't filter out Microsoft Shortcut Link files when selecting for directories only...
Posted by Legacy on 10/11/1999 12:00amOriginally posted by: Tuong Dam
I found some side effects on testing the CSelectFolderDialog for selecting only directory. The class works very well with all kind of file extensions except the Microsoft Shortcut Link files and files with double dots (very rare species).
ReplyI can fix the file filtering string "*..*" with double dots by adding more dots "*....*", but not too much luck on the Microsoft Shortcut Link files. Can anyone please try to help out? Thank You Beddy Much!
Loading, Please Wait ...