The Unofficial Newsletter of Delphi Users - by Robert Vivrette


Opening the "Find Files..." Dialog Using Delphi.

by Eddie Shipman - eshipman@inetport.com

I received an e-mail asking how to programatically open the "Find Files..." dialog.  I scratched my head and wondered how it was done. So, the trek began to find out how to accomplish this using Delphi.

To begin you need to know how Windows actually does it. Windows uses the lpVerb parameter of the SHELLEXECUTEINFO structure in a ShellExecuteEx call to accomplish this. In Delphi, the structure is called TShellExecuteInfo and it is defined in ShellAPI.PAS like this:

These units are required in your uses clause: ShlObj, ShellAPI, ActiveX.

In our case we only need a few of the parameters. To open the "Find Files..." dialog on a specific Drive, you must pass the path to the drive via the lpFile parameter. The record will be defined like this to open the dialog on drive C:

The lpVerb parameter set to 'find' instructs the call to ShellExecuteEX to open the "Find Files..." dialog. The nShow parameter defaults to SW_SHOWNORMAL so it is not really needed.

This is the entire call to open with a Drive selected from a DriveComboBox:

Now, suppose you wanted to open with "My Computer" as the stating place? You will have to do things a little different. Here's how: As you can see, we are using two new parameters for the SHELLEXECUTEINFO record. The first thing the needs to be done is to fill the pidl ItemIdList with a call to SHGetSpecialFolderLocation. The parameter CSIDL_DRIVES tells the function to return the info for "My Computer", which is actually just a list of drives accessable to your computer. The parameter fMask set to SEE_MASK_INVOKEIDLIST instructs ShellExecuteEX to use the lpIDList parameter. This must be set correctly for the dialog to open.

So, now you can give your users access to the "Find Files..." dialog without them having to open Explorer or moving to the Start Menu.

Here is the complete code to the project:

Here is the DFM: