Fog Creek Software
Discussion Board




Open Folder Dialog for Windows

Is there an Open Folder Dialog for Win32? It seems everyone is making their own - and I'm just about to do myself, but would prefere to use something like the Open File Dialog...

Daren Thomas
Tuesday, September 09, 2003

There is a lot examples out there.

Here is an example for ms-access:

http://www.mvps.org/access/api/api0002.htm

Albert D. Kallal
Edmonton, Alberta Canada
kallal@msn.com
http://www.attcanada.net/~kallal.msn

Albert D. kallal
Tuesday, September 09, 2003

In short, use SHBrowseForFolder(). Setting the initially selected folder is a bit of a pain -- you have to provide a callback function.

Frederik Slijkerman
Tuesday, September 09, 2003

If you're working in .NET they've added a select folder common dialog control with VS 2003 / Framework 1.1.

  --Josh

JWA
Tuesday, September 09, 2003

That SHBrowseForFolder() API function is really limited, though.  For instance, it doesn't allow you to browse above the root folder, so it's next to impossible to start the user in some folder but also allow them to browse up above that folder.  Roll your own.

bob dog
Tuesday, September 09, 2003

If you dowload the wtl library for VC++, there's a neat wrapper class for SHBrowseForFolder() that makes setting the initial directory and all the other options somewhat simpler. The link is as follows:

http://www.microsoft.com/downloads/details.aspx?FamilyID=128e26ee-2112-4cf7-b28e-7727d9a1f288&DisplayLang=en

John C
Tuesday, September 09, 2003

If you do roll your own, PLEASE make sure it allows the user to create a new folder if that's ever a desirable action in the context of the program. I get terribly annoyed whenever I run into an open folder dialog that assumes I want to put something in an existing folder and won't let me create a new one...

John C.
Tuesday, September 09, 2003

A quick google on SHBrowseForFolder() revealed this wrapper class:

http://www.codeproject.com/shell/cxsbrowsefolder.asp

Looks decent.

Nick
Tuesday, September 09, 2003

SHBrowseForFolder isn't that hard to use or limited unless you want to do some really wacky things.  I think people are scared off because it involves a callback to do anything beyond the basic and some COM (though COM isn't really needed except for freeing some memory). 

Most of the roll-your-own folder dialogs I've seen are awful.  For one thing, they usually don't have the New Folder button that has been mentioned.  For another, they typically aren't resizable.  The big kicker is that they never have things like Desktop or My Documents, making the user browse through the lengthy "Documents and Settings" hierarchy to get to these (assuming the user even knows how to get to the physical location of these -- not likely).  Annoying a user due to a programmer's mental laziness or inflated ego is generally not a good idea. 

My advice for using SHBrowseForFolder is to definitely wrap it (or use one of the existing wrappers).  Most of it is boilerplate code that you probably don't want to have to rewrite or relearn.  Don't be afraid of the callback -- start out assuming you'll need the callback (unless you're really going for basic functionality).  Don't forget to free the pidl using SHGetMalloc and to release the IMalloc pointer returned by SHGetMalloc. 

SomeBody
Tuesday, September 09, 2003

It's worth pointing out that this API was enhanced in later versions of Windows so that the New Folder button and window resizing functionality was added and probably some other stuff too.

John Topley (www.johntopley.com)
Tuesday, September 09, 2003

Thanx everyone.
I did find SHBrowseForFolder and I am now tidying up some crap VB wrapper I found... Will check for a better wrapper tomorrow, also make it into a ActiveX-DLL, as I want to add this functionality to my VBShell application (still in developement, will plug when ready), a Shell-Like utility for running VBScript and Bat files interactively...

ActiveX-DLL would make the callback less mucky, as I can then hide a module (as opposed to making the class module dependend of the module containing callback - yuck!)

Daren Thomas
Tuesday, September 09, 2003

Use GetOpenFileName which has all those side buttons and looks better. That SHBrowse thing is too plain...

Rick
Wednesday, September 10, 2003

Does GetOpenFileName let you browse for a folder?

John Topley (www.johntopley.com)
Wednesday, September 10, 2003

"Does GetOpenFileName let you browse for a folder?"

No.

Brad Wilson (dotnetguy.techieswithcats.com)
Wednesday, September 10, 2003

...Thought not. Therefore Rick's suggestion is invalid.

John Topley (www.johntopley.com)
Wednesday, September 10, 2003

You can specify a callback and either track the CDN_FOLDERCHANGE message, or on the OK button press event send a CDM_GETFOLDERPATH to get the selected path... invalidating your invalidation!

Rick
Wednesday, September 10, 2003

And can you write code to invalidate the user expectation of how the UI should work?

Brad Wilson (dotnetguy.techieswithcats.com)
Wednesday, September 10, 2003

I can out-GUI you any day, pal! Bring it on!!

Rick
Wednesday, September 10, 2003

*  Recent Topics

*  Fog Creek Home