#NoTrayIcon
$sPrinter = _GetDefaultPrinter()
ConsoleWrite("Default printer: " & $sPrinter & @CRLF)
$hPrinter = _OpenPrinter($sPrinter)
ConsoleWrite("Printer handle: " & $hPrinter & @CRLF)
; GUI...
$hGui = GUICreate("winspool.drv", 400, 200)
$hButton = GUICtrlCreateButton("Printer Properties Window", 50, 50, 140, 30)
GUISetState(@SW_SHOW)
While 1
Switch GUIGetMsg()
Case - 3
ExitLoop
Case $hButton
_PrinterPropertiesWindow($hPrinter, $hGui)
EndSwitch
WEnd
ConsoleWrite("Close printer: " & _ClosePrinter($hPrinter) & @CRLF)
;Functions...
Func _PrinterPropertiesWindow($hPrinter, $hOwner = 0)
Local $a_iCall = DllCall("winspool.drv", "int", "PrinterProperties", "hwnd", $hOwner, "hwnd", $hPrinter)
If @error Or Not $a_iCall[0] Then
Return SetError(1, 0, "")
EndIf
Return SetError(0, 0, 1)
EndFunc ;==>_PrinterPropertiesWindow
Func _OpenPrinter($sPrinterName)
Local $a_iCall = DllCall("winspool.drv", "int", "OpenPrinterW", "wstr", $sPrinterName, "hwnd*", 0, "ptr", 0)
If @error Or Not $a_iCall[0] Then
Return SetError(1, 0, "")
EndIf
Return SetError(0, 0, $a_iCall[2])
EndFunc ;==>_OpenPrinter
Func _ClosePrinter($hPrinter)
Local $a_iCall = DllCall("winspool.drv", "int", "ClosePrinter", "hwnd", $hPrinter)
If @error Or Not $a_iCall[0] Then
Return SetError(1, 0, "")
EndIf
Return SetError(0, 0, 1)
EndFunc ;==>_ClosePrinter
Func _GetDefaultPrinter()
Local $a_iCall = DllCall("winspool.drv", "int", "GetDefaultPrinterW", "wstr", "", "dword*", 0)
If @error Or $a_iCall[0] Then
Return SetError(1, 0, "")
EndIf
Local $iBufferSize = $a_iCall[2]
$a_iCall = DllCall("winspool.drv", "int", "GetDefaultPrinterW", "wstr", "", "dword*", $iBufferSize)
If @error Or Not $a_iCall[0] Then
Return SetError(1, 0, "")
EndIf
Return SetError(0, 0, $a_iCall[1])
EndFunc ;==>_GetDefaultPrinter