DLLs sind kompliziert...

  • dword ist kein String, du musst den Wert davon gucken und den stattdessen eingeben

    Ähhh, ok. Sorry. Das war noch falsch drinnen. Trotzdem liegt das Problem eine Zeile weiter unten.

    Spoiler anzeigen
    [autoit]

    Local $Struct, $StructData, $hScreen

    [/autoit] [autoit][/autoit] [autoit]

    HotKeySet("{ESC}","End")

    [/autoit] [autoit][/autoit] [autoit]

    While Sleep(100)
    $Struct = DllStructCreate("long;long")
    DllStructSetData($Struct, 1, MouseGetPos(0))
    DllStructSetData($Struct, 2, MouseGetPos(1))
    $StructData = DllStructGetData(DllStructCreate("uint64", DllStructGetPtr($Struct)), 1)

    [/autoit] [autoit][/autoit] [autoit]

    $hScreen = DllCall("User32.dll", "handle", "MonitorFromPoint", "uint64", $StructData, "dword", 0)
    $test = DllCall("User32.dll", "ptr", "GetMonitorInfo", "handle", $hScreen)

    [/autoit] [autoit][/autoit] [autoit]

    ToolTip($hScreen[0])
    WEnd

    [/autoit] [autoit][/autoit] [autoit]

    Func End()
    Exit
    EndFunc ;==>End

    [/autoit]

    Die Zeile 12 mit $test = DllCall..... funktioniert nicht, aber wie müsste der korrekt Aufruf lauten?

    Danke!

  • [autoit]

    #include <Array.au3>
    #include <Constants.au3>
    #include <GDIConstants.au3>

    [/autoit][autoit][/autoit][autoit]

    HotKeySet("{ESC}","End")

    [/autoit][autoit][/autoit][autoit]

    While Sleep(100)
    $Struct = DllStructCreate("long;long")
    DllStructSetData($Struct, 1, MouseGetPos(0))
    DllStructSetData($Struct, 2, MouseGetPos(1))
    $StructData = DllStructGetData(DllStructCreate("uint64", DllStructGetPtr($Struct)), 1)

    [/autoit][autoit][/autoit][autoit]

    $hScreen = DllCall("User32.dll", "handle", "MonitorFromPoint", "uint64", $StructData, "dword", 0)
    ; $hscreen = DllCall("User32.dll", "handle", "MonitorFromPoint", "long", MouseGetPos(0), "long", MouseGetPos(1), "dword", 0)
    ;_arraydisplay($hscreen)
    $tagmonitorinfo=dllstructcreate("dword cbSize;long[4];long[4];dword dwFlags")
    DllStructSetData($tagmonitorinfo,1,DllStructGetSize($tagMonitorinfo))
    $test = DllCall("User32.dll", "boolean", "GetMonitorInfo", "hwnd", $hScreen[0],"ptr",DllStructGetPtr($tagMonitorinfo))
    ;_arraydisplay($test)
    ;~ consolewrite(DllStructGetData($tagMonitorinfo,1,1)&@crlf) ;cbSitze
    ;~ for $i=1 to 4 ;rcMonitor
    ;~ consolewrite(DllStructGetData($tagMonitorinfo,2,$i)&@crlf)
    ;~ next
    ;~ for $i=1 to 4 ;rcWork
    ;~ consolewrite(DllStructGetData($tagMonitorinfo,3,$i)&@crlf)
    ;~ next
    ;~ consolewrite(DllStructGetData($tagMonitorinfo,4,1)&@crlf) ;dwFlags sollte die nummer des zzt aktiven monitors sein

    [/autoit][autoit][/autoit][autoit]

    ToolTip($hScreen[0]&" "&DllStructGetData($tagMonitorinfo,4,1))
    WEnd

    [/autoit][autoit][/autoit][autoit]

    Func End()
    Exit
    EndFunc ;==>End

    [/autoit]

    /edit/ dwflags sind die Attribute des zzt aktiven Monitors, s. meinen Link einen Post drüber

  • Vielen Dank!

    Ich habe das Skript mal etwas angepasst, damit ich das auch etwas besser verstehe!

    Spoiler anzeigen
    [autoit]

    Local $Struct, $StructData, $hScreen, $ptrInfo, $TagMonitorInfo

    [/autoit] [autoit][/autoit] [autoit]

    HotKeySet("{ESC}","End")

    [/autoit] [autoit][/autoit] [autoit]

    While Sleep(100)
    $Struct = DllStructCreate("long;long") ;Create struct
    DllStructSetData($Struct, 1, MouseGetPos(0)) ;Insert actual mouse pointer position
    DllStructSetData($Struct, 2, MouseGetPos(1))
    $StructData = DllStructGetData($Struct, 1) ;Get struct data
    $hScreen = DllCall("User32.dll", "handle", "MonitorFromPoint", "uint64", $StructData, "dword", 0) ;Get handle of screen on which the mouse cursor is

    [/autoit] [autoit][/autoit] [autoit]

    $TagMonitorInfo = DllStructCreate("dword cbSize;long[4];long[4];dword dwFlags")
    DllStructSetData($tagmonitorinfo, 1, DllStructGetSize($TagMonitorInfo))
    DllCall("User32.dll", "boolean", "GetMonitorInfo", "hwnd", $hScreen[0], "ptr", DllStructGetPtr($TagMonitorInfo))

    [/autoit] [autoit][/autoit] [autoit]

    ToolTip("rcMonitor: " & DllStructGetData($TagMonitorInfo,2,1))
    WEnd

    [/autoit] [autoit][/autoit] [autoit]

    Func End()
    Exit
    EndFunc ;==>End

    [/autoit]

    Bin ich mit der Maus auf dem Bildschirm 2, sehe ich im ToolTip die X-Auflösung des Monitor 1!
    Gehe ich mit der Maus auf Bildschirm 1, sehe ich als X-Auflösung 0!

    Wenn ich $TagMonitorInfo,4,1 verwende, dann lautet die Zahl auf Screen 2 = 0 und auf Screen 1 = 1.

    Aber eigentlich möchte ich ja auf Screen 2 = 2 und auf Screen 1 = 1!

    Oder noch besser: die Funktion, welche ich in einem Post am Anfang geschickt habe (_GetMonitorInfo()) sollte zu den zugehörigen Positionen und Koordinaten der Bildschirme auch die richtige Bildschirmnummer ausgeben!

    Spoiler anzeigen
    [autoit]

    #include-once

    [/autoit] [autoit][/autoit] [autoit]

    Func _GetMonitorInfo()
    ;Returns some informations about your screens
    ;Call: _GetMonitorInfo()
    ;Return: Array With
    ;[0][0] Nr of Monitors
    ;[1][0] X Resolution of Monitor x
    ;[1][1] Y Resolution of Monitor x
    ;[1][2] X Position of Monitor x
    ;[1][3] Y Position of Monitor x

    [/autoit] [autoit][/autoit] [autoit]

    ;[2][0] X Resolution of Monitor y
    ;[2][1] Y Resolution of Monitor y
    ;[2][2] X Position of Monitor y
    ;[2][3] Y Position of Monitor y
    ;......

    [/autoit] [autoit][/autoit] [autoit]

    Local $NrOfMonitors, $ResolutionX[32], $ResolutionY[32], $PositionX[32], $PositionY[32], $Ret
    Local $cbMonitorEnumProc = DllCallbackRegister("MonitorEnumProc", "ubyte", "ptr;ptr;ptr;int")

    [/autoit] [autoit][/autoit] [autoit]

    If @error Then Return SetError(1, 0, False)
    Local $strctCount = DllStructCreate("uint Count;uint Width[12];uint Height[12];int left[12];int top[12]")
    If @error Then Return SetError(2, @error, False)
    Local $iCount

    [/autoit] [autoit][/autoit] [autoit]

    DllStructSetData($strctCount, "Count", 0)

    [/autoit] [autoit][/autoit] [autoit]

    $Ret = DllCall("User32.dll", "ubyte","EnumDisplayMonitors","ptr", 0,"ptr", 0, "ptr", DllCallbackGetPtr($cbMonitorEnumProc), "ptr", DllStructGetPtr($strctCount))
    If @error Or $Ret[0] = 0 Then Return SetError(3, @error, False)

    [/autoit] [autoit][/autoit] [autoit]

    DllCallbackFree($cbMonitorEnumProc)

    [/autoit] [autoit][/autoit] [autoit]

    $iCount = Int(DllStructGetData($strctCount, "Count"))

    [/autoit] [autoit][/autoit] [autoit]

    Local $aMonitors[$iCount+1][4] = [[$iCount]]

    [/autoit] [autoit][/autoit] [autoit]

    For $i = 1 To $iCount
    $aMonitors[$i][0] = Int(DllStructGetData($strctCount, "Width",$i))
    $aMonitors[$i][1] = Int(DllStructGetData($strctCount, "Height",$i))
    $aMonitors[$i][2] = Int(DllStructGetData($strctCount, "left",$i))
    $aMonitors[$i][3] = Int(DllStructGetData($strctCount, "top",$i))
    Next

    [/autoit] [autoit][/autoit] [autoit]

    $strctCount = 0
    Return $aMonitors
    EndFunc

    [/autoit] [autoit][/autoit] [autoit]

    Func MonitorEnumProc($hMonitor, $hdcMonitor, $lprcMonitor, $dwData)
    Local $strctRECT = DllStructCreate("long left;long top;long right;long bottom", $lprcMonitor)
    Local $strctCount = DllStructCreate("uint Count;uint Width[12];uint Height[12];int left[12];int top[12]", $dwData)
    Local $iNumber = DllStructGetData($strctCount, "Count")
    Local $Height = Int(DllStructGetData($strctRECT, "bottom"))-Int(DllStructGetData($strctRECT, "top"))
    Local $Width = Int(DllStructGetData($strctRECT, "right"))-Int(DllStructGetData($strctRECT, "left"))

    [/autoit] [autoit][/autoit] [autoit]

    DllStructSetData($strctCount, "Width", $Width, $iNumber+1)
    DllStructSetData($strctCount, "Height", $Height, $iNumber+1)
    DllStructSetData($strctCount, "left", Int(DllStructGetData($strctRECT, "left")), $iNumber+1)
    DllStructSetData($strctCount, "top", Int(DllStructGetData($strctRECT, "top")), $iNumber+1)
    DllStructSetData($strctCount, "Count", $iNumber+1)
    Return True
    EndFunc

    [/autoit]

    Ist das möglich?

    2 Mal editiert, zuletzt von veronesi (27. Mai 2010 um 21:13)

  • So, ich habe natürlich beim übersetzen einen kleinen Fehler gemacht!

    Mit diesem Script kann ich erfolgreich die X und Y Position des Bildschirms bestimmen, auf welchem die Maus ist!
    Vielen Dank an Alle!

    Spoiler anzeigen
    [autoit]

    Local $Struct, $StructData, $hScreen, $ptrInfo, $TagMonitorInfo

    [/autoit] [autoit][/autoit] [autoit]

    HotKeySet("{ESC}","End")

    [/autoit] [autoit][/autoit] [autoit]

    While Sleep(100)
    $Struct = DllStructCreate("long;long") ;Create struct
    DllStructSetData($Struct, 1, MouseGetPos(0)) ;Insert actual mouse pointer position
    DllStructSetData($Struct, 2, MouseGetPos(1))
    $StructData = DllStructGetData(DllStructCreate("uint64", DllStructGetPtr($Struct)), 1) ;Get struct data
    $hScreen = DllCall("User32.dll", "handle", "MonitorFromPoint", "uint64", $StructData, "dword", 0) ;Get handle of screen on which the mouse cursor is

    [/autoit] [autoit][/autoit] [autoit]

    $TagMonitorInfo = DllStructCreate("dword cbSize;long[4];long[4];dword dwFlags")
    DllStructSetData($tagmonitorinfo, 1, DllStructGetSize($TagMonitorInfo))
    DllCall("User32.dll", "boolean", "GetMonitorInfo", "hwnd", $hScreen[0], "ptr", DllStructGetPtr($TagMonitorInfo))

    [/autoit] [autoit][/autoit] [autoit]

    ToolTip("X-Pos: " & DllStructGetData($TagMonitorInfo,2,1) & @LF & "Y-Pos: " & DllStructGetData($TagMonitorInfo,2,2))
    WEnd

    [/autoit] [autoit][/autoit] [autoit]

    Func End()
    Exit
    EndFunc ;==>End

    [/autoit]
  • Der Vollständigkeit halber hier noch ein korrigierter Fehler:

    Zeile 16 und 17 von meiner Funktion TileWindows() enthielten einen Fehler!
    Diese Funktion fragt den Bildschirm ab, auf welchem die Maus ist. Da ich aber immer einen falschen Bildschirm zurückbekam, dachte ich, dass deshalb die TileWindows() Funktion manchmal nicht funktioniere! Doch der Fehler lag an diesen beiden Zeilen!

    Somit ist alles in Ordnung!

    Vielen Dank!

    Korrigierte TileWindows()

    Spoiler anzeigen
    [autoit]

    #include-once
    #include "Func_GetMonitorInfo.au3"
    #include "Func_GetMouseInfo.au3"

    [/autoit] [autoit][/autoit] [autoit]

    Func _TileWindows()
    ;Tile Windows on that screen where the mouse is!
    ;Call: _TileWindows()

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

    Local $MonNr, $Left, $Top, $Right, $Bottom, $tStruct, $Rect, $aTmp[32][32]
    $MonNr = _GetMouseInfo()
    $aTmp = _GetMonitorInfo()

    [/autoit] [autoit][/autoit] [autoit]

    $Left = $aTmp[$MonNr][2]
    $Top = $aTmp[$MonNr][3]
    $Right = $aTmp[$MonNr][0] + $Left
    $Bottom = $aTmp[$MonNr][1] + $Top

    [/autoit] [autoit][/autoit] [autoit]

    $tStruct = DllStructCreate("int[4]") ;4 points of values that are integers
    DllStructSetData($tStruct, 1, $Left, 1)
    DllStructSetData($tStruct, 1, $Top, 2)
    DllStructSetData($tStruct, 1, $Right, 3)
    DllStructSetData($tStruct, 1, $Bottom, 4)
    $Rect = DllStructGetPtr($tStruct) ;Now $rect holds our left/top/right/bottom values in a type of array basically

    [/autoit] [autoit][/autoit] [autoit]

    DllCall("user32.dll", "int", "TileWindows", "int", 0, "int", 0, "Ptr", $Rect, "int", 0, "int", 0)
    EndFunc

    [/autoit]