ioa747 Posted September 14, 2023 Share Posted September 14, 2023 (edited) after some time of use, I added some more functions, and converted it to udf, for simpler use e.g.: _MM_WinMoveOn($hWin, 10, 10, 600, 300, -1, "\\.\DISPLAY2", False) moves the specify win to position 10, 10, 600, 300 on monitor2 MultiMonitors.au3 Moves and arranges with relative coords to the active monitor ; #FUNCTION# ========================================================================================================= Spoiler _MM_WinBySide Moves and/or resizes and arrange windows between multi monitors. _MM_WinBySide( $hWin1 [, $hWin2 = 0 [, $iView1 = 65 [, $sDevice = "Primary"]]]) Parameters $hWin1 The title/hWnd/class of the window1. $hWin2 [optional] The title/hWnd/class of the window2. $iView1 [optional] Percentage of the current @DesktopWidth, for window1. Negative value start from the right side $sDevice [optional] The name of the device to move to, e.g. "\\.\DISPLAY1" , "\\.\DISPLAY2" , "Primary" is the primary monitor Return Value None Remarks If $hWin2 = 0 then will be ignored, and act only to window1 ; ==================================================================================================================== _MM_WinMoveOn Moves and/or resizes a window between multi monitors. _MM_WinMoveOn( $hWin, $iX, $iY, [$iWidth = Default [, $iHeigh = Default [, $iSpeed = -1 [, $sDevice = "Primary" [, $Scale = False]]]]] ) Parameters $hWin The title/hWnd/class of the window to move/resize. $iX X coordinate to move to. $iY Y coordinate to move to. $iWidth [optional] New width of the window. $iHeigh [optional] New height of the window. $iSpeed [optional] The speed to move the windows in the range 1 (fastest) to 100 (slowest). If not defined the move is instantaneous. $sDevice [optional] The name of the device to move to, e.g. \\.\DISPLAY1 , \\.\DISPLAY2 , "Primary" is the primary monitor $Scale [optional] True/False. If True the dimensions will be multiplied with the scale factor Return Value Success: a handle to the window. Failure: 0 if the window is not found. Remarks In $iX, $iY, $iWidth, $iHeigh parameters can use string expression with the variable $DtW = current @DesktopWidth , $DtH = current @DesktopHeight Example: _MM_WinMoveOn( $hWin_1, "$DtW / 3", "$DtH / 5", "$DtW / 2", "$DtH / 2" , -1, "\\.\DISPLAY2") ; ==================================================================================================================== _MM_MouseMoveOn Moves the mouse pointer between multi monitors. _MM_MouseMoveOn( $iX, $iY [, $iSpeed = 10 [, $sDevice = "Primary" [, $Scale = False]]] ) Parameters $iX - X coordinate to move to. $iY - Y coordinate to move to. $iSpeed - [optional] The speed to move the windows in the range 0 (fastest) to 100 (slowest). $sDevice - [optional] The name of the device to move to, e.g. \\.\DISPLAY1 , \\.\DISPLAY2 , "Primary" is the primary monitor $Scale - [optional] True/False. If True the dimensions will be multiplied with the scale factor Return Value None Remarks In $iX, $iY parameters can use string expression with the variable $DtW = current @DesktopWidth , $DtH = current @DesktopHeight ; ==================================================================================================================== _MM_ToolTipOn Creates a tooltip anywhere on multi monitors _MM_ToolTipOn($sText [, $iX = Default [, $iY = Default [, $sTitle = Default [, $iIcon = Default [, $iOptions = Default [, $sDevice = "Primary" [, $Scale = False]]]]]]]) Parameters $sText The text of the tooltip. (An empty string clears a displaying tooltip) $iX - [optional] The x position of the tooltip. $iY - [optional] The y position of the tooltip. $sTitle - [optional] The title for the tooltip. $iIcon - [optional] Pre-defined icon to show next to the title: Requires a title. 0=NoIcon, 1=InfoIcon, 2=WarningIcon, 3=ErrorIcon $iOptions - [optional] Sets different options for how the tooltip will be displayed (Can be added together): 1=Display As BalloonTip 2= Center The Tip At The X,Y Coord 4=Force the tooltip to always be visible confining it to monitor borders if necessary. If multiple monitors are used, then the tooltip will "snap-to" the nearest monitor. $sDevice - [optional] The name of the device to move to, e.g. \\.\DISPLAY1 , \\.\DISPLAY2 , "Primary" is the primary monitor $Scale - [optional] True/False. If True the dimensions will be multiplied with the scale factor Return Value None Remarks In $iX, $iY parameters can use string expression with the variable $DtW = current @DesktopWidth , $DtH = current @DesktopHeight ; ==================================================================================================================== _MM_GetPointPos Translate the X, Y point, to given monitor X, Y. _MM_GetPointPos( $iX, $iY [, $sDevice = "Primary" [, $Scale = False]] ) Parameters $iX - X coordinate to Translate. $iY - Y coordinate to Translate. $sDevice - [optional] The name of the device to move to, e.g. \\.\DISPLAY1 , \\.\DISPLAY2 , "Primary" is the primary monitor $Scale - [optional] True/False. If True the dimensions will be multiplied with the scale factor Return a two-element array containing the X, Y coordinates: $aArray[0] = X coord (horizontal), $aArray[1] = Y coord (vertical) Remarks $iX, $iY parameters can use string expression with the variable $DtW = current @DesktopWidth , $DtH = current @DesktopHeight ; ==================================================================================================================== _MM_GetMonitorsArray Return a 2D array containing the monitors informations _MM_GetMonitorsArray() Parameters None Return Return a 2D array containing the monitors informations Remarks It helps if used with Local Enum $hM, $RX, $RY, $RW, $RH, $Dv, $Pr, $WX, $WY, $WW, $WH, $Sc where 0=hM, 1=RX, 2=RY, 3=RW, 4=RH, 5=Dv, 6=Pr, 7=WX, 8=WY, 9=WW, 10=WH, 11=Sc ; ==================================================================================================================== MultiMonitors.au3 expandcollapse popup#AutoIt3Wrapper_Run_AU3Check=Y #AutoIt3Wrapper_Au3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 6 -w 7 #AutoIt3Wrapper_AU3Check_Stop_OnWarning=Y #AutoIt3Wrapper_UseX64=n ; *<- DllCall("user32.dll", "bool", "SetProcessDpiAwarenessContext", "int", -4) ; -4=PerMonitorAwareV2 #include-once ; #INDEX# ============================================================================================================ ; Title .........: MultiMonitors.au3 ; AutoIt Version : v3.3.16.1 or higher ; Language ......: English ; Description ...: Moves and arranges with relative coords to the active monitor ; Remarks .......: ; Note ..........: My first UDF :) Tested on Windows 10 Version 22H2 ; Author(s) .....: ioa747 ; Link...........: https://www.autoitscript.com/forum/topic/210826-moves-andor-resizes-and-arrange-windows-between-multi-monitors/ ; ==================================================================================================================== ; #INCLUDES# ========================================================================================================= #include <Array.au3> #include <WinAPIGdi.au3> #include <WindowsConstants.au3> ; #GLOBAL VARIABLES# ================================================================================================= ; ==================================================================================================================== ; Initialization DllCall("user32.dll", "bool", "SetProcessDpiAwarenessContext", "int", -4) ; -4=PerMonitorAwareV2 ; #CURRENT# ========================================================================================================== ; _MM_WinBySide: Moves and/or resizes and arrange windows between multi monitors. ; _MM_WinMoveOn: Moves and/or resizes a window between multi monitors. ; _MM_MouseMoveOn: Moves the mouse pointer between multi monitors. ; _MM_ToolTipOn : Creates a tooltip anywhere on multi monitors ; _MM_GetPointPos: Translate the X, Y point, to given monitor X, Y. ; _MM_GetMonitorsArray: Return a 2D array containing the monitors informations ; ==================================================================================================================== ; #FUNCTION# ========================================================================================================= ; Name...........: _MM_WinBySide ; Description ...: Moves and/or resizes and arrange windows between multi monitors. ; Syntax.........: _MM_WinBySide ( $hWin1 [, $hWin2 = 0 [, $iView1 = 65 [, $sDevice = "Primary"]]]) ; Parameters ....: $hWin1 - The title/hWnd/class of the window1, ; $hWin2 - [optional] The title/hWnd/class of the window2. ; $iView1 - [optional] Percentage of the current @DesktopWidth, for window1. Negative value start from the right side ; $sDevice - [optional] The name of the device to move to, e.g. \\.\DISPLAY1 , \\.\DISPLAY2 , "Primary" is the primary monitor ; Return value...: None ; Author ........: ioa747 ; Notes .........: If $hWin2 = 0 then will be ignored, and act only to window1 ; ==================================================================================================================== Func _MM_WinBySide($hWin1, $hWin2 = 0, $iView1 = 65, $sDevice = "Primary") Local Enum $hM, $RX, $RY, $RW, $RH, $Dv, $Pr, $WX, $WY, $WW, $WH, $Sc Local $Cur Local $aMon = _MM_GetMonitorsArray() If IsArray($aMon) Then For $i = 1 To $aMon[0][0] If $sDevice = "Primary" Then If $aMon[$i][$Pr] = 1 Then $Cur = $i Else If $aMon[$i][$Dv] = $sDevice Then $Cur = $i EndIf Next Else Return SetError(1, @extended, 0) EndIf If Not $Cur Then Return SetError(2, @extended, 0) EndIf Local $iScale, $iwX, $iwY, $iwW, $iwH, $awPos $iScale = ($aMon[$Cur][$RW] / 100) ; = 1% ; Win1 :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: If $iView1 > 0 Then $iwX = $aMon[$Cur][$WX] - (7 * $aMon[$Cur][$Sc]) $iwY = $aMon[$Cur][$WY] $iwW = ($iScale * $iView1) + (14 * $aMon[$Cur][$Sc]) $iwH = $aMon[$Cur][$WH] + (7 * $aMon[$Cur][$Sc]) Else $iwX = ($aMon[$Cur][$WW] - ($iScale * Abs($iView1))) - (7 * $aMon[$Cur][$Sc]) $iwY = $aMon[$Cur][$WY] $iwW = ($iScale * Abs($iView1)) + (14 * $aMon[$Cur][$Sc]) $iwH = $aMon[$Cur][$WH] + (7 * $aMon[$Cur][$Sc]) EndIf WinMove($hWin1, "", $iwX, $iwY, $iwW, $iwH) Sleep(200) $awPos = WinGetPos($hWin1) If $iwW <> $awPos[2] Then WinMove($hWin1, "", $iwX, $iwY, $iwW, $iwH) Sleep(200) $awPos = WinGetPos($hWin1) EndIf ; Win2 :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: If $hWin2 Then If $iView1 > 0 Then $iwX = $aMon[$Cur][$WX] + ($iScale * $iView1) - (7 * $aMon[$Cur][$Sc]) $iwY = $aMon[$Cur][$WY] $iwW = $aMon[$Cur][$RW] + (14 * $aMon[$Cur][$Sc]) - ($iScale * $iView1) $iwH = $aMon[$Cur][$WH] + (7 * $aMon[$Cur][$Sc]) Else $iwX = $aMon[$Cur][$WX] - (7 * $aMon[$Cur][$Sc]) $iwY = $aMon[$Cur][$WY] $iwW = $aMon[$Cur][$RW] + (14 * $aMon[$Cur][$Sc]) - ($iScale * Abs($iView1)) $iwH = $aMon[$Cur][$WH] + (7 * $aMon[$Cur][$Sc]) EndIf WinMove($hWin2, "", $iwX, $iwY, $iwW, $iwH) Sleep(200) $awPos = WinGetPos($hWin2) If $iwW <> $awPos[2] Then WinMove($hWin2, "", $iwX, $iwY, $iwW, $iwH) Sleep(200) $awPos = WinGetPos($hWin2) EndIf EndIf ;give focus to $hWin2 WinActivate($hWin2) ;give focus to $hWin1 WinActivate($hWin1) EndFunc ;==>_MM_WinBySide ; #FUNCTION# ========================================================================================================= ; Name...........: _MM_WinMoveOn ; Description ...: Moves and/or resizes a window between multi monitors. ; Syntax.........: _MM_WinMoveOn ( $hWin, $iX, $iY, [$iWidth = Default [, $iHeigh = Default [, $iSpeed = -1 [, $sDevice = "Primary" [, $Scale = False]]]]] ) ; Parameters ....: $hWin - The title/hWnd/class of the window to move/resize. ; $iX - X coordinate to move to. ; $iY - Y coordinate to move to. ; $iWidth - [optional] New width of the window ; $iHeigh - [optional] New height of the window. ; $iSpeed - [optional] The speed to move the windows in the range 1 (fastest) to 100 (slowest). If not defined the move is instantaneous ; $sDevice - [optional] The name of the device to move to, e.g. \\.\DISPLAY1 , \\.\DISPLAY2 , "Primary" is the primary monitor ; $Scale - [optional] True/False. If True the dimensions will be multiplied with the scale factor ; Return value...: Success: a handle to the window. Failure: 0 if the window is not found. ; Author ........: ioa747 ; Notes .........: In $iX, $iY, $iWidth, $iHeigh parameters can use string expression with the variable $DtW = current @DesktopWidth , $DtH = current @DesktopHeight ; ==================================================================================================================== Func _MM_WinMoveOn($hWin, $iX, $iY, $iWidth = Default, $iHeigh = Default, $iSpeed = -1, $sDevice = "Primary", $Scale = False) Local Enum $hM, $RX, $RY, $RW, $RH, $Dv, $Pr, $WX, $WY, $WW, $WH, $Sc Local $Cur, $iScale, $iwX, $iwY, $iwW, $iwH, $awPos, $DtW, $DtH Local $aMon = _MM_GetMonitorsArray() If IsArray($aMon) Then For $i = 1 To $aMon[0][0] If $sDevice = "Primary" Then If $aMon[$i][$Pr] = 1 Then $Cur = $i Else If $aMon[$i][$Dv] = $sDevice Then $Cur = $i EndIf Next Else Return SetError(1, @extended, 0) EndIf If Not $Cur Then Return SetError(2, @extended, 0) EndIf $DtW = $aMon[$Cur][$RW] $DtH = $aMon[$Cur][$RH] If $Scale = False Then $iScale = 1 Else $iScale = $aMon[$Cur][$Sc] EndIf ; Win1 :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: If WinExists($hWin) Then $awPos = WinGetPos($hWin) If VarGetType($iX) = "String" Then $iwX = $aMon[$Cur][$WX] + (Execute($iX) * $iScale) - (7 * $aMon[$Cur][$Sc]) Else $iwX = $aMon[$Cur][$WX] + ($iX * $iScale) - (7 * $aMon[$Cur][$Sc]) EndIf If VarGetType($iY) = "String" Then $iwY = $aMon[$Cur][$WY] + (Execute($iY) * $iScale) Else $iwY = $aMon[$Cur][$WY] + ($iY * $iScale) EndIf If $iWidth = Default Then $iwW = $awPos[2] * $iScale Else If VarGetType($iWidth) = "String" Then $iwW = (Execute($iWidth) * $iScale) + (14 * $aMon[$Cur][$Sc]) Else $iwW = ($iWidth * $iScale) + (14 * $aMon[$Cur][$Sc]) EndIf EndIf If $iHeigh = Default Then $iwH = $awPos[3] * $iScale Else If VarGetType($iHeigh) = "String" Then $iwH = (Execute($iHeigh) * $iScale) + (7 * $aMon[$Cur][$Sc]) Else $iwH = ($iHeigh * $iScale) + (7 * $aMon[$Cur][$Sc]) EndIf EndIf WinMove($hWin, "", $iwX, $iwY, $iwW, $iwH, $iSpeed) Sleep(200) $awPos = WinGetPos($hWin) If $iwW <> $awPos[2] Then WinMove($hWin, "", $iwX, $iwY, $iwW, $iwH) Sleep(200) $awPos = WinGetPos($hWin) EndIf ;give focus to $hWin WinActivate($hWin) Return $hWin Else Return SetError(3, @extended, 0) EndIf EndFunc ;==>_MM_WinMoveOn ; #FUNCTION# ========================================================================================================= ; Name...........: _MM_MouseMoveOn ; Description ...: Moves the mouse pointer between multi monitors. ; Syntax.........: _MM_MouseMoveOn ( $iX, $iY [, $iSpeed = 10 [, $sDevice = "Primary" [, $Scale = False]]] ) ; Parameters ....: $iX - X coordinate to move to. ; $iY - Y coordinate to move to. ; $iSpeed - [optional] The speed to move the windows in the range 0 (fastest) to 100 (slowest). ; $sDevice - [optional] The name of the device to move to, e.g. \\.\DISPLAY1 , \\.\DISPLAY2 , "Primary" is the primary monitor ; $Scale - [optional] True/False. If True the dimensions will be multiplied with the scale factor ; Return value...: None ; Author ........: ioa747 ; Notes .........: In $iX, $iY parameters can use string expression with the variable $DtW = current @DesktopWidth , $DtH = current @DesktopHeight ; ==================================================================================================================== Func _MM_MouseMoveOn($iX, $iY, $iSpeed = 10, $sDevice = "Primary", $Scale = False) Local Enum $hM, $RX, $RY, $RW, $RH, $Dv, $Pr, $WX, $WY, $WW, $WH, $Sc Local $Cur Local $aMon = _MM_GetMonitorsArray() If IsArray($aMon) Then For $i = 1 To $aMon[0][0] If $sDevice = "Primary" Then If $aMon[$i][$Pr] = 1 Then $Cur = $i Else If $aMon[$i][$Dv] = $sDevice Then $Cur = $i EndIf Next Else Return SetError(1, @extended, 0) EndIf If Not $Cur Then Return SetError(2, @extended, 0) EndIf Local $iScale, $iwX, $iwY, $amPos, $DtW, $DtH $DtW = $aMon[$Cur][$RW] $DtH = $aMon[$Cur][$RH] If $Scale = False Then $iScale = 1 Else $iScale = $aMon[$Cur][$Sc] EndIf $amPos = MouseGetPos() If VarGetType($iX) = "String" Then $iwX = $aMon[$Cur][$WX] + (Execute($iX) * $iScale) Else $iwX = $aMon[$Cur][$WX] + ($iX * $iScale) EndIf If VarGetType($iY) = "String" Then $iwY = $aMon[$Cur][$WY] + (Execute($iY) * $iScale) Else $iwY = $aMon[$Cur][$WY] + ($iY * $iScale) EndIf MouseMove($iwX, $iwY, $iSpeed) Sleep(200) $amPos = MouseGetPos() If $iwX <> $amPos[0] Then MouseMove($iwX, $iwY, $iSpeed) Sleep(200) $amPos = MouseGetPos() EndIf EndFunc ;==>_MM_MouseMoveOn ; #FUNCTION# ========================================================================================================= ; Name...........: _MM_ToolTipOn ; Description ...: Creates a tooltip anywhere on multi monitors ; Syntax.........: _MM_ToolTipOn($sText [, $iX = Default [, $iY = Default [, $sTitle = Default [, $iIcon = Default [, $iOptions = Default [, $sDevice = "Primary" [, $Scale = False]]]]]]]) ; Parameters ....: $sText The text of the tooltip. (An empty string clears a displaying tooltip) ; $iX - [optional] The x position of the tooltip. ; $iY - [optional] The y position of the tooltip. ; $sTitle - [optional] The title for the tooltip. ; $iIcon - [optional] Pre-defined icon to show next to the title: Requires a title. 0=NoIcon, 1=InfoIcon, 2=WarningIcon, 3=ErrorIcon ; $iOptions - [optional] Sets different options for how the tooltip will be displayed (Can be added together): ; 1=Display As BalloonTip 2= Center The Tip At The X,Y Coord 4=Force the tooltip to always be visible confining it to monitor borders if necessary. ; If multiple monitors are used, then the tooltip will "snap-to" the nearest monitor. ; $sDevice - [optional] The name of the device to move to, e.g. \\.\DISPLAY1 , \\.\DISPLAY2 , "Primary" is the primary monitor ; $Scale - [optional] True/False. If True the dimensions will be multiplied with the scale factor ; Return value...: None ; Author ........: ioa747 ; Notes .........: In $iX, $iY parameters can use string expression with the variable $DtW = current @DesktopWidth , $DtH = current @DesktopHeight ; ==================================================================================================================== Func _MM_ToolTipOn($sText, $iX = Default, $iY = Default, $sTitle = Default, $iIcon = Default, $iOptions = Default, $sDevice = "Primary", $Scale = False) ;~ ToolTip ( "text" [, x [, y [, "title" [, icon = 0 [, options]]]]] ) Local Enum $hM, $RX, $RY, $RW, $RH, $Dv, $Pr, $WX, $WY, $WW, $WH, $Sc Local $Cur Local $aMon = _MM_GetMonitorsArray() If IsArray($aMon) Then For $i = 1 To $aMon[0][0] If $sDevice = "Primary" Then If $aMon[$i][$Pr] = 1 Then $Cur = $i Else If $aMon[$i][$Dv] = $sDevice Then $Cur = $i EndIf Next Else Return SetError(1, @extended, 0) EndIf If Not $Cur Then Return SetError(2, @extended, 0) EndIf Local $iScale, $iwX, $iwY, $DtW, $DtH $DtW = $aMon[$Cur][$RW] $DtH = $aMon[$Cur][$RH] If $Scale = False Then $iScale = 1 Else $iScale = $aMon[$Cur][$Sc] EndIf If VarGetType($iX) = "String" Then $iwX = $aMon[$Cur][$WX] + (Execute($iX) * $iScale) Else $iwX = $aMon[$Cur][$WX] + ($iX * $iScale) EndIf If VarGetType($iY) = "String" Then $iwY = $aMon[$Cur][$WY] + (Execute($iY) * $iScale) Else $iwY = $aMon[$Cur][$WY] + ($iY * $iScale) EndIf ToolTip($sText, $iwX, $iwY, $sTitle, $iIcon, $iOptions) EndFunc ;==>_MM_ToolTipOn ; #FUNCTION# ========================================================================================================= ; Name...........: _MM_GetPointPos ; Description ...: Translate the X, Y point, to given monitor X, Y. ; Syntax.........: _MM_GetPointPos ( $iX, $iY [, $sDevice = "Primary" [, $Scale = False]] ) ; Parameters ....: $iX - X coordinate to Translate. ; $iY - Y coordinate to Translate. ; $sDevice - [optional] The name of the device to move to, e.g. \\.\DISPLAY1 , \\.\DISPLAY2 , "Primary" is the primary monitor ; $Scale - [optional] True/False. If True the dimensions will be multiplied with the scale factor ; Return value...: a two-element array containing the X, Y coordinates: $aArray[0] = X coord (horizontal), $aArray[1] = Y coord (vertical) ; Author ........: ioa747 ; Notes .........: In $iX, $iY parameters can use string expression with the variable $DtW = current @DesktopWidth , $DtH = current @DesktopHeight ; ==================================================================================================================== Func _MM_GetPointPos($iX, $iY, $sDevice = "Primary", $Scale = False) Local Enum $hM, $RX, $RY, $RW, $RH, $Dv, $Pr, $WX, $WY, $WW, $WH, $Sc Local $Cur Local $aMon = _MM_GetMonitorsArray() If IsArray($aMon) Then For $i = 1 To $aMon[0][0] If $sDevice = "Primary" Then If $aMon[$i][$Pr] = 1 Then $Cur = $i Else If $aMon[$i][$Dv] = $sDevice Then $Cur = $i EndIf Next Else Return SetError(1, @extended, 0) EndIf If Not $Cur Then Return SetError(2, @extended, 0) EndIf Local $iScale, $iwX, $iwY, $apPos[2], $DtW, $DtH $DtW = $aMon[$Cur][$RW] $DtH = $aMon[$Cur][$RH] If $Scale = False Then $iScale = 1 Else $iScale = $aMon[$Cur][$Sc] EndIf If VarGetType($iX) = "String" Then $iwX = $aMon[$Cur][$WX] + (Execute($iX) * $iScale) Else $iwX = $aMon[$Cur][$WX] + ($iX * $iScale) EndIf If VarGetType($iY) = "String" Then $iwY = $aMon[$Cur][$WY] + (Execute($iY) * $iScale) Else $iwY = $aMon[$Cur][$WY] + ($iY * $iScale) EndIf $apPos[0] = $iwX $apPos[1] = $iwY Return $apPos EndFunc ;==>_MM_GetPointPos ; #FUNCTION# ========================================================================================================= ; Name...........: _MM_GetMonitorsArray ; Description ...: Return a 2D array containing the monitors informations ; Syntax ........: _MM_GetMonitorsArray() ; Parameters ....: None ; Return values .: Return a 2D array containing the monitors informations ; Author ........: ioa747 ; Modified.......: ; Remarks .......: Help if use Local Enum $hM, $RX, $RY, $RW, $RH, $Dv, $Pr, $WX, $WY, $WW, $WH, $Sc ; 0=hM, 1=RX, 2=RY, 3=RW, 4=RH, 5=Dv, 6=Pr, 7=WX, 8=WY, 9=WW, 10=WH, 11=Sc ; ==================================================================================================================== Func _MM_GetMonitorsArray() ;0=hM, 1=RX, 2=RY, 3=RW, 4=RH, 5=Dv, 6=Pr, 7=WX, 8=WY, 9=WW, 10=WH, 11=Sc ;Local Enum $hM, $RX, $RY, $RW, $RH, $Dv, $Pr, $WX, $WY, $WW, $WH, $Sc Local $aPos, $aMonitorInfo, $aData = _WinAPI_EnumDisplayMonitors() If IsArray($aData) Then ReDim $aData[$aData[0][0] + 1][12] For $i = 1 To $aData[0][0] $aPos = _WinAPI_GetPosFromRect($aData[$i][1]) For $j = 0 To 3 $aData[$i][$j + 1] = $aPos[$j] Next $aMonitorInfo = _WinAPI_GetMonitorInfo($aData[$i][0]) $aData[$i][5] = $aMonitorInfo[3] ;Device name $aData[$i][6] = $aMonitorInfo[2] ;Primary $aData[$i][7] = DllStructGetData($aMonitorInfo[1], 1) ;wx $aData[$i][8] = DllStructGetData($aMonitorInfo[1], 2) ;wy $aData[$i][9] = DllStructGetData($aMonitorInfo[1], 3) ;ww $aData[$i][10] = DllStructGetData($aMonitorInfo[1], 4) ;wh $aData[$i][11] = _WinAPI_EnumDisplaySettings($aMonitorInfo[3], $ENUM_CURRENT_SETTINGS)[0] / @DesktopWidth Next EndIf ;_ArrayDisplay($aData, "", "", 0, Default, "0=hM|1=RX|2=RY|3=RW|4=RH|5=Dv|6=Pr|7=WX|8=WY|9=WW|10=WH|11=Sc") Return $aData EndFunc ;==>_MM_GetMonitorsArray Tested on Windows 10 Version 22H2 main setting Here I should emphasize, in my example I use \\.\DISPLAY1 as primary and \\.\DISPLAY2 as extended monitor on your system this may not work and need to be adjusted Example.au3 expandcollapse popup; https://www.autoitscript.com/forum/topic/210826-moves-andor-resizes-and-arrange-windows-between-multi-monitors ;---------------------------------------------------------------------------------------- ; Title...........: Example.au3 ; Description.....: Example for UDF "MultiMonitors.au3" ; AutoIt Version..: 3.3.16.1 Author: ioa747 ;---------------------------------------------------------------------------------------- #AutoIt3Wrapper_Au3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 6 -w 7 #include "MultiMonitors.au3" #include <Misc.au3> Global $hDLL = DllOpen("user32.dll") ; for the _IsPressed ; first make 2 Test File ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Global $sFile_1 = @ScriptDir & '\MoveOnMultiMonitors_Test_1.txt' Global $sFile_2 = @ScriptDir & '\MoveOnMultiMonitors_Test_2.txt' If Not FileExists($sFile_1) Then FileWriteLine($sFile_1, "Win_1") If Not FileExists($sFile_2) Then FileWriteLine($sFile_2, "Win_2") ; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ _Example_WinBySide() ; _MM_WinBySide: Moves and/or resizes and arrange windows between multi monitors. _Example_WinMoveOn() ; _MM_WinMoveOn: Moves and/or resizes a window between multi monitors. _Example() ; _MM_GetPointPos & _MM_GetPointPos ; Delete the 2 Test File ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ If FileExists($sFile_1) Then FileDelete($sFile_1) If FileExists($sFile_2) Then FileDelete($sFile_2) DllClose($hDLL) Exit ;---------------------------------------------------------------------------------------- Func _Example_WinBySide() ; _MM_WinBySide: Moves and/or resizes and arrange windows between multi monitors. Local $Tip, $Title Local $Sign = @CRLF & @CRLF & "press {CTRL} to continue to the next - press {ESC} to Exit" $Tip = "Start " $Title = "Moves and/or resizes and arrange windows between multi monitors" & $Sign ToolTip($Title, @DesktopWidth / 2, @DesktopHeight / 2, $Tip, 1) _Wait(2) Local $hWin_1 = WinWait("MoveOnMultiMonitors_Test_1.txt - Notepad", "", 1) If Not WinExists($hWin_1) Then ShellExecute("notepad.exe", $sFile_1) $hWin_1 = WinWait("MoveOnMultiMonitors_Test_1.txt - Notepad") ConsoleWrite("- $hWin_1=" & $hWin_1 & @CRLF) Local $hWin_2 = WinWait("MoveOnMultiMonitors_Test_2.txt - Notepad", "", 1) If Not WinExists($hWin_2) Then ShellExecute("notepad.exe", $sFile_2) $hWin_2 = WinWait("MoveOnMultiMonitors_Test_2.txt - Notepad") ConsoleWrite("- $hWin_2=" & $hWin_2 & @CRLF) ; 1) ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ $Tip = " Win_1 30% on the left side on Primary monitor" $Title = "1) _MM_WinBySide()" & $Sign ToolTip($Title, @DesktopWidth / 2, @DesktopHeight / 2, $Tip, 1) _MM_WinBySide($hWin_1, $hWin_2, 30) _Wait() ; 2) ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ $Tip = " Win_1 70% on the left side on DISPLAY2" $Title = "2) _MM_WinBySide()" & $Sign _MM_ToolTipOn($Title, "($DtW / 2)", "($DtH / 2)", $Tip, 1, Default, "\\.\DISPLAY2") _MM_WinBySide($hWin_1, $hWin_2, 70, "\\.\DISPLAY2") _Wait() ; 3) ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ $Tip = " Win_1 70% on the right side on Primary monitor" $Title = "3) _MM_WinBySide()" & $Sign ToolTip($Title, @DesktopWidth / 2, @DesktopHeight / 2, $Tip, 1) _MM_WinBySide($hWin_1, $hWin_2, -70) _Wait() WinClose($hWin_2) ; now we have 1 windows to handle $hWin_1 ~~~~~~~~~~ ; 4) ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ $Tip = " Win_1 alone 70% on the left side on Primary monitor" $Title = "4) _MM_WinBySide() - Win_1 alone" & $Sign ToolTip($Title, @DesktopWidth / 2, @DesktopHeight / 2, $Tip, 1) _MM_WinBySide($hWin_1, 0, 70) _Wait() ; 5) ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ $Tip = " Win_1 alone 70% on the right side on Primary monitor" $Title = "5) _MM_WinBySide() - Win_1 alone" & $Sign ToolTip($Title, @DesktopWidth / 2, @DesktopHeight / 2, $Tip, 1) _MM_WinBySide($hWin_1, 0, -70) _Wait() WinClose($hWin_1) EndFunc ;==>_Example_WinBySide ;---------------------------------------------------------------------------------------- Func _Example_WinMoveOn() ; _MM_WinMoveOn: Moves and/or resizes a window between multi monitors. Local $Tip, $Title Local $Sign = @CRLF & @CRLF & "press {CTRL} to continue to the next - press {ESC} to Exit" $Tip = "Start " $Title = "Moves and/or resizes a window between multi monitors." & $Sign ToolTip($Title, @DesktopWidth / 2, @DesktopHeight / 2, $Tip, 1) _Wait(2) Local $hWin_1 = WinWait("MoveOnMultiMonitors_Test_1.txt - Notepad", "", 1) If Not WinExists($hWin_1) Then ShellExecute("notepad.exe", $sFile_1) $hWin_1 = WinWait("MoveOnMultiMonitors_Test_1.txt - Notepad") ConsoleWrite("- $hWin_1=" & $hWin_1 & @CRLF) ; 1) ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ $Tip = " ($hWin_1, 0, 0, 600, 300, -1, '\\.\DISPLAY1')" $Title = "1) _MM_WinMoveOn" & $Sign ToolTip($Title, @DesktopWidth / 2, @DesktopHeight / 2, $Tip, 1) _MM_WinMoveOn($hWin_1, 0, 0, 600, 300, -1, "\\.\DISPLAY1") _Wait() ; 2) ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ $Tip = " ($hWin_1, 0, 300, Default, Default, -1, '\\.\DISPLAY1')" $Title = "2) _MM_WinMoveOn" & $Sign ToolTip($Title, @DesktopWidth / 2, @DesktopHeight / 2, $Tip, 1) _MM_WinMoveOn($hWin_1, 0, 300, Default, Default, -1, "\\.\DISPLAY1") _Wait() ; 3) ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ $Tip = " ($hWin_1, 0, 0, 600, 300, -1, '\\.\DISPLAY2', False)" $Title = "3) _MM_WinMoveOn" & $Sign _MM_ToolTipOn($Title, "($DtW / 2)", "($DtH / 2)", $Tip, 1, Default, "\\.\DISPLAY2") _MM_WinMoveOn($hWin_1, 0, 0, 600, 300, -1, "\\.\DISPLAY2", False) _Wait() ; 4) ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ $Tip = " ($hWin_1, 0, 0, 600, 300, -1, '\\.\DISPLAY2', True)" $Title = "4) _MM_WinMoveOn" & $Sign _MM_ToolTipOn($Title, "($DtW / 2)", "($DtH / 2)", $Tip, 1, Default, "\\.\DISPLAY2") _MM_WinMoveOn($hWin_1, 0, 0, 600, 300, -1, "\\.\DISPLAY2", True) _Wait() ; now we have 1 windows to handle with Special parameters ~~~~~~~~~~~ ; In $iX, $iY, $iWidth, $iHeigh parameters can use string expression with the variable $DtW = current @DesktopWidth , $DtH = current @DesktopHeight ; 5) ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ $Tip = '($hWin_1, "($DtW / 2) - 300", "($DtH / 2) - 150", 600, 300)' $Title = "5) _MM_WinMoveOn() - Special parameters" & $Sign ToolTip($Title, @DesktopWidth / 2, @DesktopHeight / 2, $Tip, 1) _MM_WinMoveOn($hWin_1, "($DtW / 2) - 300", "($DtH / 2) - 150", 600, 300) _Wait() ; 6) ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ $Tip = '($hWin_1, "($DtW/2) - ($DtW/4)", "($DtH/2) - ($DtH/4)", "($DtW/2)", "($DtH/2)", -1, "\\.\DISPLAY2")' $Title = "6) _MM_WinMoveOn() - Special parameters" & $Sign _MM_ToolTipOn($Title, "($DtW / 2)", "($DtH / 2)", $Tip, 1, Default, "\\.\DISPLAY2") _MM_WinMoveOn($hWin_1, "($DtW / 2) - ($DtW / 4)", "($DtH / 2) - ($DtH / 4)", "($DtW / 2)", "($DtH / 2)", -1, "\\.\DISPLAY2") _Wait() ; 7) ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ $Tip = '($hWin_1, "$DtW / 3", "$DtH / 5", "$DtW / 2", "$DtH / 2")' $Title = "7) _MM_WinMoveOn() - Special parameters" & $Sign ToolTip($Title, @DesktopWidth / 2, @DesktopHeight / 2, $Tip, 1) _MM_WinMoveOn($hWin_1, "$DtW / 3", "$DtH / 5", "$DtW / 2", "$DtH / 2") _Wait() ToolTip("") WinClose($hWin_1) EndFunc ;==>_Example_WinMoveOn ;---------------------------------------------------------------------------------------- Func _Example() ; _MM_GetPointPos & _MM_GetPointPos ; _MM_MouseMoveOn: Moves the mouse pointer between multi monitors. ; _MM_GetPointPos: Translate the X, Y point, to given monitor X, Y. Local $Tip, $Title Local $Sign = @CRLF & @CRLF & "press {CTRL} to continue to the next - press {ESC} to Exit" Local $iMidW = @DesktopWidth / 2, $iMidH = @DesktopHeight / 2 ; 1) ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ; move the mouse ponter to Desktop center $Tip = "Mouse x, y:" & @CRLF & $iMidW & ", " & $iMidH $Title = "1) midle point:" & $Sign ToolTip($Title, $iMidW, $iMidH, $Tip, 1, 3) MouseMove($iMidW, $iMidH) _Wait(2) ; 2) ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ; move the mouse ponter to center of DISPLAY2 with _MM_GetPointPos ; _MM_GetPointPos ( $iX, $iY [, $sDevice = "Primary" [, $Scale = False]] ) Local $aPos = _MM_GetPointPos("($DtW / 2)", "($DtH / 2)", "\\.\DISPLAY2") $Tip = "Mouse x, y:" & @CRLF & $aPos[0] & ", " & $aPos[1] $Title = "2) midle point:" & $Sign ToolTip($Title, $aPos[0], $aPos[1], $Tip, 1, 3) MouseMove($aPos[0], $aPos[1], 30) ; move the mouse ponter to 100, @DesktopHeight / 2 of DISPLAY2 with _MM_MouseMoveOn ; _MM_MouseMoveOn ( $iX, $iY [, $iSpeed = 10 [, $sDevice = "Primary" [, $Scale = False]]] ) _MM_MouseMoveOn(100, "($DtH / 2)", 30, "\\.\DISPLAY2") ; move the mouse ponter to center of DISPLAY2 with _MM_MouseMoveOn _MM_MouseMoveOn("($DtW / 2)", "($DtH / 2)", 30, "\\.\DISPLAY2") _Wait(2) ; 3) ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ; now let's see the $Scale parameter ; $Scale - [optional] True/False. Default = False ; If True the dimensions will be multiplied with the scale factor of curent monitor $Tip = " move mouse point back" $Title = "3) now let's see the $Scale parameter" & $Sign ToolTip($Title, @DesktopWidth / 2, @DesktopHeight / 2, $Tip, 1, 3) MouseMove($iMidW, $iMidH) _Wait() ; 4) ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ; $Scale = False $Tip = ' (1000, 1000, Default, "\\.\DISPLAY2", False )' $Title = "4) _MM_MouseMoveOn() - $Scale = False" & $Sign ; ToolTip($Tip, 1000, 1000, "_MM_MouseMoveOn() - $Scale = False", 1, 3) ; ordinary ToolTip _MM_ToolTipOn($Title, 1000, 1000, $Tip, 1, 3, "\\.\DISPLAY2", False) _MM_MouseMoveOn(1000, 1000, 10, "\\.\DISPLAY2", False) _Wait() ; 5) ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ; $Scale = True $Tip = ' (1000, 1000, Default, "\\.\DISPLAY2", True)' $Title = "5) _MM_MouseMoveOn() - $Scale = True" & $Sign ; ToolTip($Tip, 1000, 1000, "_MM_MouseMoveOn() - $Scale = False", 1, 3) ; ordinary ToolTip _MM_ToolTipOn($Title, 1000, 1000, $Tip, 1, 3, "\\.\DISPLAY2", True) _MM_MouseMoveOn(1000, 1000, 10, "\\.\DISPLAY2", True) _Wait() ; 6) ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ; which means that with the scale factor, we can use proportional dimensions with respect to the primary display $Tip = ' _MM_MouseMoveOn() - $Scale = True' $Title = "6) which means that with the scale factor," & @CRLF $Title &= "we can use proportional dimensions with respect to the primary display" & $Sign _MM_ToolTipOn($Title, @DesktopWidth / 2, @DesktopHeight / 2, $Tip, 1, -1, "\\.\DISPLAY2", True) _MM_MouseMoveOn(10, 10, 10, "\\.\DISPLAY2", True) _MM_MouseMoveOn(@DesktopWidth - 10, 10, 10, "\\.\DISPLAY2", True) _MM_MouseMoveOn(@DesktopWidth - 10, 10, 10, "\\.\DISPLAY2", True) _MM_MouseMoveOn(@DesktopWidth - 10, @DesktopHeight - 10, 10, "\\.\DISPLAY2", True) _MM_MouseMoveOn(10, @DesktopHeight - 10, 10, "\\.\DISPLAY2", True) _MM_MouseMoveOn(10, 10, 30, "\\.\DISPLAY2", True) ; 7) ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ $Tip = '=== _MM_ToolTipOn with $Scale False ===' $Title = "5) ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" & $Sign _MM_ToolTipOn($Tip, "$DtW/2", "$DtH/2", "$Scale = False", 1, 3, "\\.\DISPLAY2", False) _Wait() $Tip = '=== _MM_ToolTipOn with $Scale True ===' $Title = "5) ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" & $Sign _MM_ToolTipOn($Tip, @DesktopWidth / 2, @DesktopHeight / 2, "$Scale = True", 1, 3, "\\.\DISPLAY2", True) _Wait() ; 8) ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ConsoleWrite(@CRLF & "8) ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" & @CRLF) ; _MM_GetPointPos ( $iX, $iY [, $sDevice = "Primary" [, $Scale = False]] ) $aPos = _MM_GetPointPos(@DesktopWidth, @DesktopHeight, "\\.\DISPLAY2", False) ConsoleWrite("DISPLAY2 with false:" & $aPos[0] & "," & $aPos[1] & @CRLF) $aPos = _MM_GetPointPos(@DesktopWidth, @DesktopHeight, "\\.\DISPLAY2", True) ConsoleWrite(" DISPLAY2 with True:" & $aPos[0] & "," & $aPos[1] & @CRLF) EndFunc ;==>_Example ;---------------------------------------------------------------------------------------- Func _Wait($iSec = 5) ; 5*1000 = 5000 Local $iTmp, $Max = ($iSec * 1000) / 50 While Sleep(50) Select Case _IsPressed("11", $hDLL) ;11 CTRL key Sleep(50) Return Case _IsPressed("1B", $hDLL) ;1B = ESC key Exit EndSelect $iTmp += 1 If $iTmp = $Max Then Return WEnd EndFunc ;==>_Wait ;---------------------------------------------------------------------------------------- Please, every comment is appreciated! leave your comments and experiences here! Thank you very much Edited September 20, 2023 by ioa747 UpDate etidd and Danyfirex 1 1 I know that I know nothing Link to comment Share on other sites More sharing options...
ioa747 Posted September 20, 2023 Author Share Posted September 20, 2023 On 9/14/2023 at 9:53 PM, ioa747 said: converted it to udf I know that I know nothing Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now