Ich weiß nicht, wo ich falsch lag, aber es ändert nichts an der die Landschaft.
Wo habe ich falsch gemacht?
Spoiler anzeigen
#include<WinPrint.au3>
#Include <WinAPI.au3>
#Include <String.au3>
Global Const $DC_DRIVER = 11
Global Const $DM_IN_PROMPT=4
Global Const $OFFS_ORIENT_FLAG=41 ; offset to Orientation flag
Global Const $OFFS_ORIENT_VALUE=45 ; offset to Orientation value
Global $hWindow, $cPrinter, $cDriver, $cPort, $hPrinter, $nBufsize, $cDevmode
[/autoit] [autoit][/autoit] [autoit]$res =_Identify_Printers()
$res = StringSplit(StringReplace ( StringReplace ( StringReplace ( $res, "*", ":"), ">", ""), "<", ""), ":")
$res_=DllCall("winspool.drv", "long", "DeviceCapabilitiesA", "str", $cPrinter, "str", $cPort, "int", $DC_DRIVER, "str", Chr(0), "long", 0)
$cPrinter = $res[1]
$cDriver = $res_[0]
$cPort = $res[2]
$hWindow = WinGetHandle ('AutoIt3.exe')
$hPrinter = 0
[/autoit] [autoit][/autoit] [autoit]$hPrinter = _OpenPrinter($cPrinter, $hPrinter, 0)
IF $hPrinter = 0 Then
MsgBox(0, "Error", "Could not open default printer. ")
ENDIF
;being called this way the function returns DEVMODE buffer required size
$nBufsize = _DocumentProperties($hWindow, $hPrinter, $cPrinter, 0, 0, 0)
$cDevmode = _StringRepeat(Chr(0), $nBufsize) ;
_SetOrient($DMORIENT_LANDSCAPE)
_DocumentProperties($hWindow, $hPrinter, $cPrinter, $cDevmode, $cDevmode, $DM_IN_PROMPT+$DM_IN_BUFFER+$DM_OUT_BUFFER)
_ClosePrinter($hPrinter)
[/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]Func _SetOrient($nOrient)
; DEVMODE is adjusted programmatically
; DM_IN_PROMPT not used -- the dialog window is not shown
LOCAL $dmFlags
;reading printer configuration
_DocumentProperties($hWindow, $hPrinter, $cPrinter, $cDevmode, 0, $DM_OUT_BUFFER)
$dmFlags = _buf2word(StringMid($cDevmode, $OFFS_ORIENT_FLAG, 4))
$dmFlags = BitOR($dmFlags, $DM_ORIENTATION)
$cDevmode = StringReplace($cDevmode, $OFFS_ORIENT_FLAG, 4, _num2dword($dmFlags))
$cDevmode = StringReplace($cDevmode, $OFFS_ORIENT_VALUE, 2, _num2word($nOrient))
; using modified DEVMODE structure in the next call
_DocumentProperties($hWindow, $hPrinter, $cPrinter,$cDevmode, $cDevmode, $DM_IN_BUFFER+$DM_OUT_BUFFER)
EndFunc
Func _buf2word($lcBuffer)
$return = Asc(StringMid($lcBuffer, 1, 1))+Asc(StringMid($lcBuffer, 2, 1))*256
EndFunc
Func _num2word($lnValue)
[/autoit] [autoit][/autoit] [autoit]RETURN Chr(MOD($lnValue,256)) + CHR(INT($lnValue/256))
[/autoit] [autoit][/autoit] [autoit]EndFunc
[/autoit] [autoit][/autoit] [autoit]Func _num2dword($lnValue)
[/autoit] [autoit][/autoit] [autoit]Global Const $m0=256
Global Const $m1=65536
Global Const $m2=16777216
Local $b0, $b1, $b2, $b3
[/autoit] [autoit][/autoit] [autoit]$b3 = Int($lnValue/$m2)
$b2 = Int(($lnValue - ($b3*$m2))/$m1)
$b1 = Int(($lnValue - ($b3*$m2) - ($b2*$m1))/$m0)
$b0 = Mod($lnValue, $m0)
RETURN Chr($b0)+Chr($b1)+Chr($b2)+Chr($b3)
[/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]EndFunc
[/autoit] [autoit][/autoit] [autoit];:::::::::::::::::::::::::::::::::::::::::::::::::::::::: Functions
[/autoit] [autoit][/autoit] [autoit]Func _GetProfileStringA($cApp, $cKeyName, $cDefault, $cReturn, $nSize)
$result = DllCall("kernel32.dll","dword","GetProfileStringA", "str", $cApp, "str", $cKeyName, "str", $cDefault, "str", $cReturn, "dword", $nSize)
Return $result
EndFunc
Func _DocumentProperties($hParent,$hPrinter,$szPrinter, $pDevModeOut ,$pDevModeIn=0,$fMode=0)
Local $err,$hwnd
;get a handle for property page parent
If $hParent = 0 Then
$hwnd = _WinAPI_GetDesktopWindow()
Else
$hwnd = $hParent
EndIf
Local $result = DllCall("winspool.drv","int","DocumentPropertiesW","hwnd",$hwnd,"handle",$hPrinter,"wstr",$szPrinter,"ptr",DllStructGetPtr($pDevModeOut),"ptr",$pDevModeIn,"dword",$fMode)
$err = @error
If $err Then Return SetError($err,0,0)
Return $result[0]
EndFunc
Func _DeviceCapabilities($objPrinterName, $objPrinterPortName, $fwCapability, $pOutput, $pDevMode)
[/autoit] [autoit][/autoit] [autoit]If $pOutput = "" Then $pOutput = Chr(0)
If $pDevMode = 0 Then $pDevMode = 0
$result = DllCall("winspool.drv", "long", "DeviceCapabilitiesA", _
"str", $objPrinterName, "str", $objPrinterPortName, _
"int", $fwCapability, "str", $pOutput, "long", $pDevMode)
Return $result[0]
[/autoit] [autoit][/autoit] [autoit]EndFunc
[/autoit] [autoit][/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]Func _OpenPrinter($pPrinter,ByRef $phPrinter,$pDefaults=-1)
Local $err,$tPDF
If $pDefaults = -1 Then
$tPDF = DllStructCreate("ptr;ptr;ptr")
DllStructSetData($tPDF,3,8)
$pDefaults = DllStructGetPtr($tPDF)
EndIf
Local $t_pPrinter = DllStructCreate("ptr")
$phPrinter = DllStructGetPtr($t_pPrinter)
Local $result = DllCall("winspool.drv","int","OpenPrinterW","wstr",$pPrinter,"ptr",$phPrinter,"ptr",$pDefaults)
$err = @error
$tPDF = 0
If $err Then Return SetError($err,0,0)
Return $result[0]
EndFunc
Func _ClosePrinter($pPrinter)
Local $err
Local $result = DllCall("winspool.drv","int","ClosePrinter","handle",$pPrinter)
$err = @error
If $err Then Return SetError($err,0,0)
Return $result[0]
EndFunc
;::::::::::::::::::::::::::::::::::::::::::::::::::::::::
Func _Identify_Printers()
Local $key, $default, $i = 1, $list, $name
If @OSType = "WIN32_WINDOWS" Then
$key = "HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\Print\Printers"
$default = RegRead("HKEY_CURRENT_CONFIG\System\CurrentControlSet\Control\Print\Printers","Default")
Else;WIN_NT type
$key = "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Print\Printers"
$default = RegRead("HKEY_CURRENT_USER\Software\Microsoft\Windows NT\CurrentVersion\Windows","Device")
$default = StringLeft($default, StringInStr($default,",")-1);remove info after comma...
EndIf
;;;$list = StringReplace($list, $default, '** ' & $default)
[/autoit] [autoit][/autoit] [autoit]; ENUMERATE LOCAL PRINTERS (AND ALSO 9x PRINTERS SHARED ON OTHER COMPUTERS)
While 1
;#cs - enum bug workaround
RegRead($key, "")
If @error = 1 Then ExitLoop
;#ce
Local $name = RegEnumKey($key, $i)
If @error Then ExitLoop
Local $port = "<" & RegRead($key & "\" & $name, "Port") & ">"
;************************************************************************modified
If $name = $default Then
$port = '* ' & $port
$res = $name &$port
[/autoit] [autoit][/autoit] [autoit]EndIf
;***********************************************************************
Local $driver = RegRead($key & "\" & $name, "Printer Driver")
Local $shared = RegRead($key & "\" & $name, "Share Name")
If $shared <> "" Then $shared = "$ " & $shared
$list = $list & $port & " " & $name & " [" & $driver & "] " & $shared & @CRLF
$i = $i + 1
WEnd
[/autoit] [autoit][/autoit] [autoit]; ENUMERATE 2000/XP PRINTERS SHARED ON OTHER COMPUTERS
If @OSType = "WIN_NT" Then
Local $i = 1, $j = 1
While 1
;#cs - enum bug workaround
RegRead($key, "")
If @error = 1 Then ExitLoop
;#ce
Local $serverAddress = RegEnumKey($key, $i)
If @error Then ExitLoop
$j = 1
While 1
;#cs - enum bug workaround
RegRead($key & "\" & $serverAddress & "\Printers", "")
If @error = 1 Then ExitLoop(2)
;#ce
Local $networkedPrinter = RegEnumKey($key & "\" & $serverAddress & "\Printers", $j)
If @error Then ExitLoop(2)
$name = RegRead($key & "\" & $serverAddress & "\Printers\" & $networkedPrinter, "Name")
Local $share = "<\\" & $serverAddress & "\" & RegRead($key & "\" & $serverAddress & "\Printers\" & $networkedPrinter, "Share Name") & ">"
If $name = $default Then $share = '* ' & $share
$list = $list & $share & " " & $name & " [" & $driver & "]" & @CRLF
$j = $j + 1
WEnd
$i = $i + 1
WEnd
EndIf
If $list = "" Then $list = "No printers detected" & @CRLF
;Return $list ; default value
Return $res
EndFunc