共用方式為


PrintDlg function

[PrintDlg is available for use in the operating systems specified in the Requirements section. It may be altered or unavailable in subsequent versions. Instead, use PrintDlgEx or PageSetupDlg.]

Displays a Print Dialog Box or a Print Setup dialog box. The Print dialog box enables the user to specify the properties of a particular print job.

Syntax

BOOL WINAPI PrintDlg(
  _Inout_ LPPRINTDLG lppd
);

Parameters

  • lppd [in, out]
    Type: LPPRINTDLG

    A pointer to a PRINTDLG structure that contains information used to initialize the dialog box. When PrintDlg returns, this structure contains information about the user's selections.

Return value

Type: BOOL

If the user clicks the OK button, the return value is nonzero. The members of the PRINTDLG structure pointed to by the lppd parameter indicate the user's selections.

If the user canceled or closed the Print or Printer Setup dialog box or an error occurred, the return value is zero. To get extended error information, use the CommDlgExtendedError function. If the user canceled or closed the dialog box, CommDlgExtendedError returns zero; otherwise, it returns one of the following values.

CDERR_FINDRESFAILURE

CDERR_INITIALIZATION

CDERR_LOADRESFAILURE

CDERR_LOADSTRFAILURE

CDERR_LOCKRESFAILURE

CDERR_MEMALLOCFAILURE

CDERR_MEMLOCKFAILURE

CDERR_NOHINSTANCE

CDERR_NOHOOK

CDERR_NOTEMPLATE

CDERR_STRUCTSIZE

PDERR_CREATEICFAILURE

PDERR_DEFAULTDIFFERENT

PDERR_DNDMMISMATCH

PDERR_GETDEVMODEFAIL

PDERR_INITFAILURE

PDERR_LOADDRVFAILURE

PDERR_NODEFAULTPRN

PDERR_NODEVICES

PDERR_PARSEFAILURE

PDERR_PRINTERNOTFOUND

PDERR_RETDEFFAILURE

Remarks

If the hook procedure (pointed to by the lpfnPrintHook or lpfnSetupHook member of the PRINTDLG structure) processes the WM_CTLCOLORDLG message, the hook procedure must return a handle to the brush that should be used to paint the control background.

Note that the values of hDevMode and hDevNames in PRINTDLG may change when they are passed into PrintDlg. This is because these members are filled on both input and output.

To switch printer selection, use PrintDlg or PrintDlgEx.

Windows Server 2003, Windows XP, and Windows 2000: To switch printer selection, use the Printer button

Known issue: If PD_RETURNDC is set but PD_USEDEVMODECOPIESANDCOLLATE flag is not set, the PrintDlgEx and PrintDlg functions return incorrect number of copies. To get the correct number of copies, ensure that the calling application always uses PD_USEDEVMODECOPIESANDCOLLATE with PD_RETURNDC.

Examples

For an example, see Displaying the Print Dialog Box.

Requirements

Minimum supported client

Windows 2000 Professional [desktop apps only]

Minimum supported server

Windows 2000 Server [desktop apps only]

Header

Commdlg.h (include Windows.h)

Library

Comdlg32.lib

DLL

Comdlg32.dll

Unicode and ANSI names

PrintDlgW (Unicode) and PrintDlgA (ANSI)

See also

Reference

CommDlgExtendedError

PRINTDLG

PrintHookProc

SetupHookProc

WM_CTLCOLORDLG

Conceptual

Common Dialog Box Library

Other Resources

CreateDC

DOCINFO

StartDoc