#include <commdlg.h>
typedef struct tagPD { /* pd */
DWORD lStructSize;
HWND hwndOwner;
HGLOBAL hDevMode;
HGLOBAL hDevNames;
HDC hDC;
DWORD Flags;
UINT nFromPage;
UINT nToPage;
UINT nMinPage;
UINT nMaxPage;
UINT nCopies;
HINSTANCE hInstance;
LPARAM lCustData;
UINT (CALLBACK* lpfnPrintHook)(HWND, UINT, WPARAM, LPARAM);
UINT (CALLBACK* lpfnSetupHook)(HWND, UINT, WPARAM, LPARAM);
LPCSTR lpPrintTemplateName;
LPCSTR lpSetupTemplateName;
HGLOBAL hPrintTemplate;
HGLOBAL hSetupTemplate;
} PRINTDLG;
The PRINTDLG structure contains information that the system uses to initialize the system-defined Print dialog box. After the user chooses the OK button to close the dialog box, the system returns information about the user's selections in this structure.
lStructSize
Specifies the length of the structure, in bytes. This member is filled on input.
hwndOwner
Identifies the window that owns the dialog box. This member can be any valid window handle, or it should be NULL if the dialog box is to have no owner.
If the PD_SHOWHELP flag is set, hwndOwner must identify the window that owns the dialog box. The window procedure for this owner window receives a notification message when the user chooses the Help button. (The identifier for the notification message is the value returned by the RegisterWindowMessage function when HELPMSGSTRING is passed as its argument.)
This member is filled on input.
hDevMode
Identifies a movable global memory object that contains a DEVMODE structure. Before the PrintDlg function is called, the members in this structure may contain data used to initialize the dialog box controls. When the PrintDlg function returns, the members in this structure specify the state of each of the dialog box controls.
If the application uses the structure to initialize the dialog box controls, it must allocate space for and create the DEVMODE structure. (The application should allocate a movable memory object.)
If the application does not use the structure to initialize the dialog box controls, the hDevMode member may be NULL. In this case, the PrintDlg function allocates memory for the structure, initializes its members, and returns a handle that identifies it.
If the device driver for the specified printer does not support extended device modes, the hDevMode member is NULL when PrintDlg returns.
If the device name (specified by the dmDeviceName member of the DEVMODE structure) does not appear in the [devices] section of WIN.INI, the PrintDlg function returns an error.
The value of hDevMode may change during the execution of the PrintDlg function. This member is filled on input and output.
hDevNames
Identifies a movable global memory object that contains a DEVNAMES structure. This structure contains three strings; these strings specify the driver name, the printer name, and the output-port name. Before the PrintDlg function is called, the members of this structure contain strings used to initialize the dialog box controls. When the PrintDlg function returns, the members of this structure contain the strings typed by the user. The calling application uses these strings to create a device context or an information context.
If the application uses the structure to initialize the dialog box controls, it must allocate space for and create the DEVMODE data structure. (The application should allocate a movable global memory object.)
If the application does not use the structure to initialize the dialog box controls, the hDevNames member can be NULL. In this case, the PrintDlg function allocates memory for the structure, initializes its members (using the printer name specified in the DEVMODE data structure), and returns a handle that identifies it. When the PrintDlg function initializes the members of the DEVNAMES structure, it uses the first port name that appears in the [devices] section of WIN.INI. For example, the function uses “LPT1” as the port name if the following string appears in the [devices] section:
PCL / HP LaserJet=HPPCL,LPT1:,LPT2:
If both the hDevMode and hDevNames members are NULL, PrintDlg specifies the current default printer for hDevNames.
The value of hDevNames may change during the execution of the PrintDlg function. This member is filled on input and output.
hDC
Identifies either a device context or an information context, depending on whether the Flags member specifies the PD_RETURNDC or the PD_RETURNIC flag. If neither flag is specified, the value of this member is undefined. If both flags are specified, hDC is PD_RETURNDC.
This member is filled on output.
Flags
Specifies the dialog box initialization flags. This member may be a combination of the following values:
Value | Meaning |
PD_ALLPAGES | Indicates that the All radio button was selected when the user closed the dialog box. (This value is used as a placeholder, to indicate that the PD_PAGENUMS and PD_SELECTION flags are not set. This value can be set on input and output.) | |
PD_COLLATE | Causes the Collate Copies check box to be checked when the dialog box is created. When the PrintDlg function returns, this flag indicates the state in which the user left the Collate Copies check box. This flag can be set on input and output. | |
PD_DISABLEPRINTTOFILE | Disables the Print to File check box. | |
PD_ENABLEPRINTHOOK | Enables the hook function specified in the lpfnPrintHook member of this structure. | |
PD_ENABLEPRINTTEMPLATE | ||
Causes the system to use the dialog box template identified by the hInstance and lpPrintTemplateName members to create the Print dialog box. | ||
PD_ENABLEPRINTTEMPLATEHANDLE | ||
Indicates that the hPrintTemplate member identifies a data block that contains a pre-loaded dialog box template. The system ignores the hInstance member if this flag is specified. | ||
PD_ENABLESETUPHOOK | Enables the hook function specified in the lpfnSetupHook member of this structure. | |
PD_ENABLESETUPTEMPLATE | ||
Causes the system to use the dialog box template identified by the hInstance and lpSetupTemplateName members to create the Print Setup dialog box. | ||
PD_ENABLESETUPTEMPLATEHANDLE | ||
Indicates that the hSetupTemplate member identifies a data block that contains a pre-loaded dialog box template. The system ignores the hInstance member if this flag is specified. | ||
PD_HIDEPRINTTOFILE | Hides and disables the Print to File check box. | |
PD_NOPAGENUMS | Disables the Pages radio button and the associated edit controls. | |
PD_NOSELECTION | Disables the Selection radio button. | |
PD_NOWARNING | Prevents the warning message from being displayed when there is no default printer. | |
PD_PAGENUMS | Causes the Pages radio button to be selected when the dialog box is created. When the PrintDlg function returns, this flag is set if the Pages button is in the selected state. If neither PD_PAGENUMS nor PD_SELECTION is specified, the All radio button is in the selected state. | |
This flag can be set on input and output. | ||
PD_PRINTSETUP | Causes the system to display the Print Setup dialog box rather than the Print dialog box. | |
PD_PRINTTOFILE | Causes the Print to File check box to be checked when the dialog box is created. | |
This flag can be set on input and output. | ||
PD_RETURNDC | Causes the PrintDlg function to return a device context matching the selections that the user made in the dialog box. The handle to the device context is returned in the hDC member. If neither PD_RETURNDC nor PD_RETURNIC is specified, the hDC parameter is undefined on output. | |
PD_RETURNDEFAULT | Causes the PrintDlg function to return DEVMODE and DEVNAMES structures that are initialized for the system default printer. PrintDlg does this without displaying a dialog box. Both the hDevNames and the hDevMode members should be NULL; otherwise, the function returns an error. If the system default printer is supported by an old printer driver (earlier than Windows version 3.0), only the hDevNames member is returned—the hDevMode member is NULL. | |
PD_RETURNIC | Causes the PrintDlg function to return an information context matching the selections that the user made in the dialog box. The information context is returned in the hDC member. If neither PD_RETURNDC nor PD_RETURNIC is specified, the hDC parameter is undefined on output. | |
PD_SELECTION | Causes the Selection radio button to be selected when the dialog box is created. When the PrintDlg function returns, this flag is set if the Selection button is in the selected state. If neither PD_PAGENUMS nor PD_SELECTION is specified, the All radio button is in the selected state. | |
This flag can be set on input and output. | ||
PD_SHOWHELP | Causes the dialog box to show the Help button. If this flag is specified, the hwndOwner must not be NULL. | |
PD_USEDEVMODECOPIES | Disables the Copies edit control if a printer driver does not support multiple copies. If a driver does support multiple copies, setting this flag indicates that the PrintDlg function should store the requested number of copies in the dmCopies member of the DEVMODE structure and store the value 1 in the nCopies member of the PRINTDLG structure. | |
If this flag is not set, the PRINTDLG structure stores the value 1 in the dmCopies member of the DEVMODE structure and stores the requested number of copies in the nCopies member of the PRINTDLG structure. |
These flags may be set when the structure is initialized, except where specified.
nFromPage
Specifies the initial value for the starting page in the From edit control. When the PrintDlg function returns, this member specifies the page at which to begin printing. This value is valid only if the PD_PAGENUMS flag is specified. The maximum value for this member is 0xFFFE; if 0xFFFF is specified, the From edit control is left blank.
This member is filled on input and output.
nToPage
Specifies the initial value for the ending page in the To edit control. When the PrintDlg function returns, this member specifies the last page to print. This value is valid only if the PD_PAGENUMS flag is specified. The maximum value for this member is 0xFFFE; if 0xFFFF is specified, the To edit control is left blank.
This member is filled on input and output.
nMinPage
Specifies the minimum number of pages that can be specified in the From and To edit controls. This member is filled on input.
nMaxPage
Specifies the maximum number of pages that can be specified in the From and To edit controls. This member is filled on input.
nCopies
Before the PrintDlg function is called, this member specifies the value to be used to initialize the Copies edit control if the hDevMode member is NULL; otherwise, the dmCopies member of the DEVMODE structure contains the value used to initialize the Copies edit control.
When PrintDlg returns, the value specified by this member depends on the version of Windows for which the printer driver was written. For printer drivers written for Windows versions earlier than 3.0, this member specifies the number of copies requested by the user in the Copies edit control. For printer drivers written for Windows versions 3.0 and later, this member specifies the number of copies requested by the user if the PD_USEDEVMODECOPIES flag was not set; otherwise, this member specifies the value 1 and the actual number of copies requested appears in the DEVMODE structure.
This member is filled on input and output.
hInstance
Identifies a data block that contains the pre-loaded dialog box template specified by the lpPrintTemplateName or the lpSetupTemplateName member. This member is used only if the Flags member specifies the PD_ENABLEPRINTTEMPLATE or PD_ENABLESETUPTEMPLATE flag; otherwise, this member is ignored.
This member is filled on input.
lCustData
Specifies application-defined data that the system passes to the hook function identified by the lpfnPrintHook or the lpfnSetupHook member. The system passes a pointer to the PRINTDLG structure in the lParam parameter of the WM_INITDIALOG message; this pointer can be used to retrieve the lCustData member.
lpfnPrintHook
Points to the exported hook function that processes dialog box messages if the application customizes the Print dialog box. This member is ignored unless the PD_ENABLEPRINTHOOK flag is specified in the Flags member.
This member is filled on input.
lpfnSetupHook
Points to the exported hook function that processes dialog box messages if the application customizes the Print Setup dialog box. This member is ignored unless the PD_ENABLESETUPHOOK flag is specified in the Flags member.
This member is filled on input.
lpPrintTemplateName
Points to a null-terminated string that specifies the dialog box template that is to be substituted for the standard dialog box template in COMMDLG. An application must specify the PD_ENABLEPRINTTEMPLATE constant in the Flags member to enable the hook function; otherwise, the system ignores this structure member.
This member is filled on input.
lpSetupTemplateName
Points to a null-terminated string that specifies the dialog box template that is to be substituted for the standard dialog box template in COMMDLG. An application must specify the PD_ENABLEPRINTTEMPLATE constant in the Flags member to enable the hook function; otherwise, the system ignores this structure member.
This member is filled on input.
hPrintTemplate
Identifies the handle of the global memory object that contains the pre-loaded dialog box template to be used instead of the default template in COMMDLG.DLL for the Print dialog box. To use the dialog box template, the PD_ENABLEPRINTTEMPLATEHANDLE flag must be set.
This member is filled on input.
hSetupTemplate
Identifies the handle of the global memory object that contains the pre-loaded dialog box template to be used instead of the default template in COMMDLG.DLL for the Print Setup dialog box. To use the dialog box template, the PD_ENABLEPRINTTEMPLATEHANDLE flag must be set.
This member is filled on input.