Salut,
Je cherche un moyen d'ouvrir la boite des propriétés d'une imprimante sans passer par le composant PrintDialog.
J'utilise pour cela les API windows mais je plante sur la fonction PrinterProperties.
J'ai juste mis un bouton sur une fenêtre qui fait appel au code suivant :
<DllImport("winspool.drv", CharSet:=CharSet.Auto, _
SetLastError:=True)> _
Private Shared Function OpenPrinter( _
ByVal pPrinterName As String, ByRef hPrinter As IntPtr, _
ByVal pDefault As IntPtr) As Boolean
End Function
<DllImport("winspool.drv", CharSet:=CharSet.Auto, _
SetLastError:=True)> _
Private Shared Function ClosePrinter( _
ByVal hPrinter As IntPtr) As Boolean
End Function
<DllImport("winspool.drv", CharSet:=CharSet.Unicode, ExactSpelling:=False, CallingConvention:=CallingConvention.StdCall)> _
Private Function PrinterProperties( _
ByVal hwnd As IntPtr, _
ByVal hPrinter As IntPtr) As Long
End Function
'*******************************************************
Dim hPrinter As IntPtr
Dim lAns As Long
Try
OpenPrinter(printerName, hPrinter, IntPtr.Zero)
lAns = PrinterProperties(Me.Handle, hPrinter)
DisplayPrinterProperties = lAns <> 0
Catch
Throw New Win32Exception(Marshal.GetLastWin32Error())
Finally
ClosePrinter(hPrinter)
End Try
Quelqu'un aurait-il une idée ou déjà rencontrer ce problème ?
Merci
Partager