Automatisch Fenster auf dem Bildschirm anordnen, auf welchem der Mauscursor ist

  • Mit diesem Skript kann man automatisch alle offenen Fenster auf dem Bildschirm anordnen, auf welchem der Mauscursor ist:

    Spoiler anzeigen
    [autoit]

    Func _TileWindows()
    ;Tile Windows on that screen where the mouse is!
    ;Call: _TileWindows()
    ;Don't miss to include the Func_GetMonitorInfo.au3 (#include "Func_GetMonitorInfo.au3")
    ;Don't miss to include the Func_GetMouseInfo.au3 (#include "Func_GetMouseInfo.au3")

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

    Local $MonNr, $Left, $Top, $Right, $Bottom, $tStruct, $Rect
    $MonNr = _GetMouseInfo()
    $Left = _GetMonitorInfo("PosX",$MonNr)
    $Top = _GetMonitorInfo("PosY",$MonNr)
    $Right = $Left + _GetMonitorInfo("ResX",$MonNr)
    $Bottom = $Top + _GetMonitorInfo("ResY",$MonNr)

    [/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

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

    [/autoit]

    Dazu werden noch zwei Funktionen gebraucht, welche ich bereits hier veröffentlicht habe.

    Viel Spass!
    Veronesi

  • Tut mir leid, daß ich es dir so präsentieren muss, aber diese doofe Forensoftware löscht einfach

    ungefragt die Zeilenumbrüche aus meinem kopierten Code raus.

    Also füge ich es einfach als normalen Text ein, ich hoffe es ist das was du gesucht hast.


    Func _GetMouseInfo()
    ;Returns the screen number on which the actual mouse cursor is
    ;Call: _GetMouseInfo()
    ;Don't miss to include the Func_GetMonitorInfo.au3 (#include "Func_GetMonitorInfo.au3")

    $MousePos = MouseGetPos()
    $NrOfScreens = _GetMonitorInfo("Nr","")
    For $i = 1 To $NrOfScreens
    If $MousePos[0] >= _GetMonitorInfo("PosX",$i) AND ($MousePos[0] <= _GetMonitorInfo("PosX",$i) + _GetMonitorInfo("ResX",$i)) AND $MousePos[1] >= _GetMonitorInfo("PosY",$i) AND ($MousePos[1] <= _GetMonitorInfo("PosY",$i) + _GetMonitorInfo("ResY",$i)) Then Return $i
    ;Checks on which Screen the Mousecursor is
    Next
    EndFunc


    Func _GetMonitorInfo($Typ, $Nr)
    ;Returns some informations about your screens
    ;Call: _GetMonitorInfo("Typ", "Nr")
    ;Possible Values for "Typ": "Nr" / "ResX" / "ResY" / "PosX" / "PosY"
    ;If "Typ" = "Nr", then the Number of asked Screen will be ignored!
    ;Nr = Number of asked Screen

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

    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

    DllStructSetData($strctCount, "Count", 0)

    $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)

    DllCallbackFree($cbMonitorEnumProc)

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

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

    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

    If Not @error Then
    $NrOfMonitors = $aMonitors[0][0]
    For $i = 1 To $NrOfMonitors
    $ResolutionX[$i] = $aMonitors[$i][0]
    $ResolutionY[$i] = $aMonitors[$i][1]
    $PositionX[$i] = $aMonitors[$i][2]
    $PositionY[$i] = $aMonitors[$i][3]
    Next
    EndIf
    Select
    Case $Typ="Nr"
    Return $NrOfMonitors
    Case $Typ="ResX"
    Return $ResolutionX[$Nr]
    Case $Typ="ResY"
    Return $ResolutionY[$Nr]
    Case $Typ="PosX"
    Return $PositionX[$Nr]
    Case $Typ="PosY"
    Return $PositionY[$Nr]
    EndSelect
    EndFunc

    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"))

    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

  • Je älter die Leiche, desto... :D

    Der Beitrag von veronesi ist vom 2. April 2010!

    Wie komme ich von:


    http://www.autoit.de/index.php…Thread&threadID=19072

    auf den Beitrag, in dem ich die Funktionen finden?

    Indem du den Link...

    http://www.autoit.de/index.php?page=Thread&amp;threadID=19072

    so änderst...

    https://autoit.de/index.php?thread/19072

    Das Script funktioniert

    Das Script läuft... aber funktioniert sicher nicht so, wie gewünscht... denn zumindest bei mir werden auch die Fenster von Monitor 2 auf Monitor 1 verschoben, wenn sich die Maus auf Monitor 1 befindet.

    Das liegt daran, dass beim Aufruf von TileWindows kein Window-Handle für $hParent angegeben wird, weshalb dann das Desktop-Window als Parent-Window genommen wird.

    Zudem wird es evtl. schwierig, ein Window-Handle für $hParent anzugeben, dass für alle zu arrangierenden Windows das Parent-Window sein muss, wenn diese von verschiedenen Anwendungen und/oder keine Child-Windows sind.

    _WinAPI_TileWindows : Tiles the specified child windows of the specified parent window

    AutoIt: _WinAPI_TileWindows
    #include <WinAPISysWin.au3>
    
    _WinAPI_TileWindows ( $aWnds [, $tRECT = 0 [, $hParent = 0 [, $iFlags = 0 [, $iStart = 0 [, $iEnd = -1]]]]] )

    Und...

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

    Code
    ; https://msdn.microsoft.com/de-de/library/windows/desktop/ms633554(v=vs.85).aspx
    
    ;      Tiles the specified child windows of the specified parent window
    ;        WORD WINAPI TileWindows(
    ;          _In_opt_       HWND hwndParent,
    ;          _In_           UINT wHow,
    ;          _In_opt_ const RECT *lpRect,
    ;          _In_           UINT cKids,
    ;          _In_opt_ const HWND *lpKids
    ;        );

    wäre wohl so korrekt...

    DllCall("user32.dll", "WORD", "TileWindows", "HWND", 0, "UINT", 0, "PTR", $Rect, "UINT", 0, "HWND", 0)


    Doch mit diesem DllCall (wenn nur lpRect angegeben wird) kann man das Script genauso gut auch so schreiben...

    AutoIt
    #include <WinAPIGdi.au3>
    
    Local $aRes, $tPoint = _WinAPI_GetMousePos(), $aData = _WinAPI_GetMonitorInfo(_WinAPI_MonitorFromPoint($tPoint, 0))
    If Not @error Then $aRes = DllCall("user32.dll", "WORD", "TileWindows", "HWND", 0, "UINT", 0, "PTR", $aData[0], "UINT", 0, "HWND", 0)
    If Not @error Then MsgBox(64, @ScriptName, 'Number of windows arranged: ' & $aRes[0], 3)

    oder so...

    2 Mal editiert, zuletzt von Bitnugger (14. Februar 2018 um 12:17)

    • Offizieller Beitrag

    Genug mit der Leichenfledderei.