Posted by: Christian Wimmer in: JEDI Windows API Headers
Maybe you know this version of a folder browser dialog box that can be created by SHBrowseForFolder.
For standard users or users who just put everything in one folder, is this dialog very good to use. However there are also users out there who have a deep directory structure and hate such dialogs, because you cannot add directly a folder path as a string to select the folder directly. Many applications also show the folder path in a custom edit box, but do not allow to edit them directly.
So why isn’t there an edit box like shown below?
This dialog was created by a Delphi-Praxis member and is free to download from this DP article.
Fortunately the people from Microsoft adapted ShellExecute so it allows to enter a folder path directly. This feature is available in shell32.dll version 5.0 or later (Windows 2000 or later).
You can even change the size of the dialog. Unfortunately there is no simple way to set the initial folder of the BrowserDialog, so this has to be done in a Callback function (I will not bother your with details).
This task is accomplished by setting the flags in the browse info structure.
Version 5.0. Use the new user interface. Setting this flag provides the user with a larger dialog box that can be resized. The dialog box has several new capabilities, including: drag-and-drop capability within the dialog box, reordering, shortcut menus, new folders, delete, and other shortcut menu commands
Since using ShellExecute needs a lot of work, I just print the necessary helper function BrowseForFolder. The original function was developed by Brian Cryer. You can download it from here. However I did some improvements.
The function declaration can be seen here.
The parameter names should be meaningful enough. The function returns true, if the user clicked the OK button; otherwise it returns false. If you needn’t an initial folder just leave it empty.
The whole source code as a sample project can be downloaded here.
What units are used:
How to compile and use the source:
Tell me how you liked this blog entry by adding a comment.