API llamada para abrir el cuadro de diálogo de propiedades de la impresora
Autor: vitoriatang
Desde: Internet
. NET Framework encapsula una gran cantidad de cuadros de diálogo sobre la impresión, como PrintDialog, PageSetupDialog
Pero a veces también hay que preocuparse por el cuadro de diálogo de propiedades de la impresora, entonces puede llamar a la API para resolver este problema. Hay varias funciones API relacionadas con
PrinterProperties
DocumentProperties
OpenPrinter
ClosePrinter
introducidas una por una
printerproperties
muestra el cuadro de diálogo de propiedades de la impresora.
documentproperties
muestra el cuadro de diálogo de configuración de la impresora.
openprinter
abre la impresora
closeprinter
cerrar la impresora
Al llamar a printerproperties o documentproperties, debe llamar a openprinter primero y llamar a closeprinter después del final.
En cuanto a la diferencia entre las propiedades de la impresora y la configuración de la impresora, lo entiendo por mí mismo. Puede encontrar información más detallada en msdn
códigos de muestra:
1. 声明 API 函数
[System.Runtime.InteropServices.DllImportAttribute ("winspool.drv", SetLastError = true)]
public extern static int DocumentProperties (
IntPtr hWnd, // maneja a la ventana principal
IntPtr hPrinter, // maneja a
cadena de objeto de impresora pDeviceName, // nombre de dispositivo
ref IntPtr pDevModeOutput, // modo de dispositivo modificado
ref IntPtr pDevModeInput, // modo de dispositivo original
int fMode); // opciones de modo
[System.Runtime.InteropServices.DllImportAttribute ("winspool.drv")]
public static extern int PrinterProperties (
IntPtr hwnd, // maneja la ventana principal
IntPtr hPrinter); // manejar al objeto de la impresora
[System.Runtime.InteropServices.DllImportAttribute ("winspool.drv", SetLastError = true)]
public extern static int OpenPrinter (
string pPrinterName, // nombre de impresora
ref IntPtr hPrinter, // maneja al objeto de impresora
ref IntPtr pDefault); // manejar el objeto de impresora predeterminado.
[System.Runtime.InteropServices.DllImportAttribute ("winspool.drv", SetLastError = true)]
public static extern int ClosePrinter (
IntPtr phPrinter); // manejar al objeto de la impresora
2. 调用 DocumentProperties
private void documentPropButton_Click (remitente del objeto, EventArgs e)
{ string printerName = _document.PrinterSettings.PrinterName;
if (printerName! = null && printerName.Length> 0)
{ IntPtr pPrinter = IntPtr.Zero; IntPtr pDevModeOutput = IntPtr.Zero; IntPtr pDevModeInput = IntPtr.Zero; IntPtr nullPointer = IntPtr.Zero;
OpenPrinter (nombreImpresora, ref pPrinter, ref nullPointer);
int iNeeded = DocumentProperties (this.Handle, pPrinter, printerName, ref pDevModeOutput, ref pDevModeInput, 0);
pDevModeOutput = System.Runtime.InteropServices.Marshal.AllocHGlobal (iNeeded);
DocumentProperties (this.Handle, pPrinter, printerName, ref pDevModeOutput, ref pDevModeInput, DM_PROMPT);
ClosePrinter (pPrinter);
}
}
3.调用 PrinterProperties
private void printPropButton_Click (remitente del objeto, EventArgs e)
{ string printerName = _document.PrinterSettings.PrinterName;
if (printerName! = null && printerName.Length> 0)
{ IntPtr pPrinter = IntPtr.Zero; IntPtr pDevModeOutput = IntPtr.Zero; IntPtr pDevModeInput = IntPtr.Zero; IntPtr nullPointer = IntPtr.Zero;
OpenPrinter (nombreImpresora, ref pPrinter, ref nullPointer);
int iNeeded = PrinterProperties (this.Handle, pPrinter);
ClosePrinter (pPrinter);
}