| Centering the Select Directory dialog | |||||||||||||||||||||
| Here's how to take the full control over the SHBrowseForFolder API call. Find out how to implement an application-defined callback function that the browse dialog calls, to notify the caller about its events. | |||||||||||||||||||||
In Windows, there are several ways to display directory structure of a computer. Most Delphi programmers know how to use the TOpenDialog component to allow the user to browse for folders and files to open.
By encapsulating the SHBrowseForFolder Windows API function we can invoke a Windows system dialog used to browse for files and folders on users hard drive as well as network computers and printers. In either of the two cases, the dialog that is displayed tends to appear at a random position on the screen. Our task in this article is to see how to tak ethe full control over the SHBrowseForFolder call.
Recall, that the SHBrowseForFolder API function accepts only one, rather complicated, TBrowseInfo parameter - to initialize and customize the Browse For Folder dialog box.
Another interesting parameter is the lpfn flag. This parameter is of a TFNBFFCallBack type, the lpfn can be used to assign an application-defined function that the dialog box calls when events occur. This function is a callback function, and can be used to control and update the dialog box as the user interacts with it.
Below, you'll find an example usege of the TFNBFFCallBack function type. The idea is to center the browse dialog on the work area of the screen (using the WorkAreaRect property of the global TScreen object)...
![]()
Sample usage:
|
|||||||||||||||||||||

