Explorer-Style Hook Procedures

You can customize an Explorer-style Open or Save As dialog box by providing a hook procedure, a custom template, or both. If you provide a hook procedure for an Explorer-style dialog box, the system creates a dialog box that is a child of the default dialog box. The hook procedure acts as the dialog procedure for the child dialog box. This child dialog box is based on the custom template, or on a default template if none is provided. For more information, see Explorer-Style Custom Templates.To enable a hook procedure for an Explorer-style Open or Save As dialog box, use the OPENFILENAME structure when you create the dialog box. Set the OFN_ENABLEHOOK and OFN_EXPLORER flags in the Flags member and specify the address of an OFNHookProc hook procedure in the lpfnHook member. If you provide a hook procedure and omit the OFN_EXPLORER flag, you must use an OFNHookProcOldStyle hook procedure and you will get the old-style user-interface. For more information, see Customizing Old-Style Dialog Boxes.

An Explorer-style hook procedure receives a variety of messages while the dialog box is open. These include the following:

  • The WM_INITDIALOG message and other standard dialog box messages such as the WM_CTLCOLORDLG control color message.

  • A set of WM_NOTIFY notification messages indicating actions taken by the user or other dialog box events.

  • Messages for any additional controls that you defined by specifying a child dialog template.

In addition, there is a set of messages that you can send to an Explorer-style dialog box to get information or to control the behavior and appearance of the dialog box.

If you provide a hook procedure for an Explorer-style dialog box, the default dialog box procedure creates a child dialog box when the default dialog procedure is processing its WM_INITDIALOG message. The hook procedure acts as the dialog procedure for the child dialog box. At this time, the hook procedure receives its own WM_INITDIALOG message with the lParam parameter set to the address of the OPENFILENAME structure used to initialize the dialog box. After the child dialog finishes processing its own WM_INITDIALOG message, the default dialog procedure moves the standard controls, if necessary, to make room for any additional controls of the child dialog box. The default dialog procedure then sends the CDN_INITDONE notification message to the hook procedure.

The hook procedure receives WM_NOTIFY notification messages indicating actions taken by the user in the dialog box. You can use some of these messages to control the behavior of the dialog box. For example, the hook procedure receives the CDN_FILEOK message when the user chooses a filename and clicks the OK button. In response to this message, the hook procedure can use the SetWindowLong function to reject the selected name and force the dialog box to remain open.

The lParam parameter for each WM_NOTIFY message is a pointer to an OFNOTIFY structure that defines the action. The code member in the header for the OFNOTIFY structure contains one of the following notification codes.

CDN_FILEOK
The user clicked the OK button; the dialog box is about to close.
CDN_FOLDERCHANGE
The user opened a new folder or directory.
CDN_HELP
The user clicked the Help button.
CDN_INITDONE
The system has finished initializing the dialog box, and the dialog box has finished processing the WM_INITDIALOG message. Also, the system has finished arranging controls in the common dialog box to make room for the controls of the child dialog box (if any).
CDN_SELCHANGE
The user selected a new file or folder from the file list.
CDN_SHAREVIOLATION
The common dialog box encountered a sharing violation on the file about to be returned.
CDN_TYPECHANGE
The user selected a new file type from the list of file types.

These WM_NOTIFY messages supersede the FILEOKSTRING, LBSELCHSTRING, SHAREVISTRING, and HELPMSGSTRING registered messages used by previous versions of the Open and Save As dialog boxes. However, the hook procedure also receives the superseded message after the WM_NOTIFY message if the WM_NOTIFY processing does not use SetWindowLong to set a nonzero DWL_MSGRESULT value.

To retrieve information about the status of the dialog box or to control the behavior and appearance of the dialog box, the hook procedure can send the following messages to the dialog box.

CDM_GETFILEPATH
Retrieves the path and filename of the selected file.
CDM_GETFOLDERIDLIST
Retrieves the item identifier list corresponding to the current folder that the dialog box has open. For more information about item identifier lists, see Item Identifiers and Identifier Lists.
CDM_GETFOLDERPATH
Retrieves the path of the current folder or directory for the dialog box.
CDM_GETSPEC
Retrieves the filename (not including the path) of the file currently selected in the dialog box.
CDM_HIDECONTROL
Hides the specified control.
CDM_SETCONTROLTEXT
Sets the text in the specified control.
CDM_SETDEFEXT
Sets the default filename extension for the dialog box.

Software for developers
Delphi Components
.Net Components
Software for Android Developers
More information resources
MegaDetailed.Net
Unix Manual Pages
Delphi Examples
Databases for Amazon shops developers
Amazon Categories Database
Browse Nodes Database