Type a page name and press Enter. You'll jump to the page if it exists, or you can create it if it doesn't.
To create a page in a module other than comdlg32, prefix the name with the module name and a period.
<DllImport("comdlg32.dll", CharSet:=CharSet.Auto)> _
Private Shared Function PrintDlg(<[In], Out> ByVal lppd As PRINTDLG) As Boolean
Private Shared Function PrintDlgEx(<[In](), Out()> ByVal lppd As PRINTDLGEX) As Boolean
End Function
// PRINTDLG that will be passed to PrintDlg API function.
PRINTDLG printdlg = new PRINTDLG();
printdlg.lStructSize = Marshal.SizeOf(printdlg);
printdlg.hwndOwner = hwndDialogOwner;
// Pass the handles to the DEVMODE and DEVNAMES structures from the
// printer settings object to the PRINTDLG so that the current
// printsettings are displayed in the print setup dialog.
printdlg.hDevMode = printerSettings.GetHdevmode();
printdlg.hDevNames = printerSettings.GetHdevnames();
// Uncomment the line below to indicate that only the print setup dialog should be shown.
//printdlg.Flags = PD_PRINTSETUP;
// Invoke the dialog.
bool l = PrintDlg(printdlg);
// Pass the resulting DEVMODE and DEVNAMES structs back to the
// caller via the PrinterSettings object that was passed in.
printerSettings.SetHdevmode(printdlg.hDevMode);
printerSettings.SetHdevnames(printdlg.hDevNames);
}
Tips & Tricks:
Please add some!
VB.NET Sample Code:
Imports System.Runtime.InteropServices
Public Class WWPrintDialog
Private Const START_PAGE_GENERAL = &HFFFFFFFF
Private m_bShowHelp As Boolean = False
Private m_bShowStatusDialog As Boolean = False
Private m_bShowNetwork As Boolean = False
Private m_bAllowSelection As Boolean = False
Private m_bAllowSomePages As Boolean = False
Private m_bShowCollate As Boolean = False
Private m_hParent As IntPtr
Private m_bAllowPrintToFile As Boolean = False
Private m_sPrinterName As String = String.Empty
Private m_Copies As Integer = 1
<DllImport("comdlg32.dll", CharSet:=CharSet.Auto)> _
Private Shared Function PrintDlgEx(<[In](), Out()> ByVal lppd As PRINTDLGEX) As Boolean
End Function
Public Property Parent() As IntPtr
Get
Return m_hParent
End Get
Set(ByVal value As IntPtr)
m_hParent = value
End Set
End Property
Public Function ShowDialog() As DialogResult
Return InvokePrintDlgEx()
End Function
Public Function InvokePrintDlgEx() As DialogResult
Dim ret As Object = Nothing
Dim _pdex As PRINTDLGEX = New PRINTDLGEX()
Dim _ppr As PRINTPAGERANGE = New PRINTPAGERANGE()
Dim prnsettings As Printing.PrinterSettings = New Printing.PrinterSettings()
Return IIf(PrintDlgEx(_pdex), DialogResult.OK, DialogResult.Cancel)
End Function
End Class
<StructLayout(LayoutKind.Sequential, CharSet:=CharSet.Auto, Pack:=1), System.Runtime.InteropServices.ComVisible(False)> _
Public Class PRINTDLGEX
Public lStructSize As Int32
Public hwndOwner As IntPtr
Public hDevMode As IntPtr
Public hDevNames As IntPtr
Public hDC As IntPtr = IntPtr.Zero
Public Flags As Int32
Public Flags2 As Int32
Public ExclusionFlags As Int32
Public nPageRanges As Int32
Public nMaxPageRanges As Int32
Public lpPageRanges As IntPtr
Public nMinPage As Int32
Public nMaxPage As Int32
Public nCopies As Int32
Public hInstance As IntPtr = IntPtr.Zero
<MarshalAs(UnmanagedType.LPStr, SizeConst:=&H20)> _
Public lpPrintTemplateName As String
Public lpCallback As IntPtr = IntPtr.Zero
Public nPropertyPages As Int32
Public lphPropertyPages As IntPtr = IntPtr.Zero
Public nStartPage As Int32
Public dwResultAction As Int32
End Class
<StructLayout(LayoutKind.Sequential, CharSet:=CharSet.Auto, Pack:=1), System.Runtime.InteropServices.ComVisible(False)> _
Public Class PRINTPAGERANGE
Public nFromPage As Int32
Public nToPage As Int32
End Class
<StructLayout(LayoutKind.Sequential, CharSet:=CharSet.Auto, Pack:=1), System.Runtime.InteropServices.ComVisible(False)> _
Public Class PRINTFLAG
Public Const PD_ALLPAGES As Int32 = 0
Public Const PD_SELECTION As Int32 = 1
Public Const PD_PAGENUMS As Int32 = 2
Public Const PD_NOSELECTION As Int32 = 4
Public Const PD_NOPAGENUMS As Int32 = 8
Public Const PD_COLLATE As Int32 = 16
Public Const PD_PRINTTOFILE As Int32 = 32
Public Const PD_PRINTSETUP As Int32 = 64
Public Const PD_NOWARNING As Int32 = 128
Public Const PD_RETURNDC As Int32 = 256
Public Const PD_RETURNIC As Int32 = 512
Public Const PD_RETURNDEFAULT As Int32 = 1024
Public Const PD_SHOWHELP As Int32 = 2048
Public Const PD_ENABLEPRINTHOOK As Int32 = 4096
Public Const PD_ENABLESETUPHOOK As Int32 = 8192
Public Const PD_ENABLEPRINTTEMPLATE As Int32 = 16384
Public Const PD_ENABLESETUPTEMPLATE As Int32 = 32768
Public Const PD_ENABLEPRINTTEMPLATEHANDLE As Int32 = 65536
Public Const PD_ENABLESETUPTEMPLATEHANDLE As Int32 = 131072
Public Const PD_USEDEVMODECOPIES As Int32 = 262144
Public Const PD_USEDEVMODECOPIESANDCOLLATE As Int32 = 262144
Public Const PD_DISABLEPRINTTOFILE As Int32 = 524288
Public Const PD_HIDEPRINTTOFILE As Int32 = 1048576
Public Const PD_NONETWORKBUTTON As Int32 = 2097152
Public Const PD_CURRENTPAGE As Int32 = 4194304
Public Const PD_NOCURRENTPAGE As Int32 = 8388608
Public Const PD_EXCLUSIONFLAGS As Int32 = 16777216
Public Const PD_USELARGETEMPLATE As Int32 = 268435456
Public Const PD_EXCL_COPIESANDCOLLATE As Int32 = (256 Or 32768)
End Class
Please edit this page!
Do you have...
helpful tips or sample code to share for using this API in managed code?
corrections to the existing content?
variations of the signature you want to share?
additional languages you want to include?
Select "Edit This Page" on the right hand toolbar and edit it! Or add new pages containing supporting types needed for this API (structures, delegates, and more).