Custom Templates

Common dialog boxes have default templates that define the number, type, and position of the standard controls in the dialog box. You can define a custom template to give users access to additional controls that are unique to your application.

For all common dialog boxes except the Explorer-style Open and Save As dialog boxes, you modify the default template to create a custom template that replaces the default template. The custom template defines the type and position of the standard controls as well as any additional controls.

When you create a custom dialog box template by modifying the default dialog box template, make sure the identifiers for any added controls are unique and do not conflict with the identifiers of the standard controls. The following table lists the name of the default template file and include file for each of the common dialog box types.

Dialog box type Template file Include file
Color COLOR.DLG COLORDLG.H
Find FINDTEXT.DLG DLGS.H
Font FONT.DLG DLGS.H
Open (multiple selection) FILEOPEN.DLG DLGS.H
Open (single selection) FILEOPEN.DLG DLGS.H
Page Setup PRNSETUP.DLG DLGS.H
Print PRNSETUP.DLG DLGS.H
Print Setup (obsolete) PRNSETUP.DLG DLGS.H
Replace FINDTEXT.DLG DLGS.H

To enable a custom template, you must set a flag in the Flags member of the corresponding structure for the dialog box. If the template is a resource in an application or dynamic-link library, set an ENABLETEMPLATE flag in the Flags member, and use the hInstance and lpTemplateName members of the structure to identify the module and resource name. If the template is already in memory, set an ENABLETEMPLATEHANDLE flag in the Flags member, and use the hInstance member to identify the memory object that contains the template.

In most cases, you must also enable a hook procedure for the dialog box to support and process input for the additional controls in your custom template.

For the Explorer-style Open and Save As dialog boxes, the default templates are not available for modification. Instead, your custom template defines a child dialog box that includes only the items to be added to the standard dialog box. The custom template can also define a static control that specifies the location of the cluster of standard controls in the child dialog box. For more information, see Explorer-Style Custom Templates.