166 lines
5.8 KiB
AutoIt
166 lines
5.8 KiB
AutoIt
#cs ----------------------------------------------------------------------------
|
|
|
|
AutoIt Version: 3.3.12.0
|
|
Author: Sqozz
|
|
|
|
Script Function:
|
|
Template AutoIt script.
|
|
|
|
#ce ----------------------------------------------------------------------------
|
|
|
|
Func _getPrimaryMonDimensions()
|
|
$allMonitors = _WinAPI_EnumDisplayMonitors()
|
|
; [0] ==> X-Pos
|
|
; [1] ==> Y-Pos
|
|
; [2] ==> Width
|
|
; [3] ==> Height
|
|
Dim $primaryMonitor[4]
|
|
|
|
For $i = 1 To $allMonitors[0][0]
|
|
$aData = _WinAPI_GetMonitorInfo ( $allMonitors[$i][0] )
|
|
If $aData[2] == 1 Then
|
|
$primaryMonitor[0] = DllStructGetData($aData[0], 1)
|
|
$primaryMonitor[1] = DllStructGetData($aData[0], 2)
|
|
$primaryMonitor[2] = DllStructGetData($aData[0], 3)
|
|
$primaryMonitor[3] = DllStructGetData($aData[0], 4)
|
|
EndIf
|
|
Next
|
|
|
|
Return $primaryMonitor
|
|
EndFunc
|
|
|
|
Func _calcDimensions($secondaryMonitor)
|
|
; [0] ==> X-Pos
|
|
; [1] ==> Y-Pos
|
|
; [2] ==> Width
|
|
; [3] ==> Height
|
|
Dim $secondaryMonitorRealDim[4]
|
|
$primaryMonitor = _getPrimaryMonDimensions()
|
|
$secondaryMonitorRealDim[0] = $secondaryMonitor[0]
|
|
$secondaryMonitorRealDim[1] = $secondaryMonitor[1]
|
|
$secondaryMonitorRealDim[2] = $secondaryMonitor[2] - $secondaryMonitor[0]
|
|
$secondaryMonitorRealDim[3] = $secondaryMonitor[3] - $secondaryMonitor[1]
|
|
|
|
Return $secondaryMonitorRealDim
|
|
EndFunc
|
|
|
|
Func _genMonitorList()
|
|
$physicalMonitors = _WinAPI_EnumDisplayMonitors()
|
|
Dim $monitors[$physicalMonitors[0][0]][5]
|
|
|
|
For $i = 1 To $physicalMonitors[0][0]
|
|
; [0] ==> X-Pos
|
|
; [1] ==> Y-Pos
|
|
; [2] ==> Width
|
|
; [3] ==> Height
|
|
; [4] ==> Handle
|
|
Dim $monitor[4]
|
|
|
|
$aData = _WinAPI_GetMonitorInfo ( $physicalMonitors[$i][0] )
|
|
$monitor[0] = DllStructGetData($aData[0], 1)
|
|
$monitor[1] = DllStructGetData($aData[0], 2)
|
|
$monitor[2] = DllStructGetData($aData[0], 3)
|
|
$monitor[3] = DllStructGetData($aData[0], 4)
|
|
|
|
If $aData[2] <> 1 Then
|
|
$monitor[0] = DllStructGetData($aData[0], 1)
|
|
$monitor[1] = DllStructGetData($aData[0], 2)
|
|
$monitor[2] = DllStructGetData($aData[0], 3)
|
|
$monitor[3] = DllStructGetData($aData[0], 4)
|
|
$monitor = _calcDimensions($monitor)
|
|
EndIf
|
|
|
|
$monitors[$i - 1][0] = $monitor[0]
|
|
$monitors[$i - 1][1] = $monitor[1]
|
|
$monitors[$i - 1][2] = $monitor[2]
|
|
$monitors[$i - 1][3] = $monitor[3]
|
|
$monitors[$i - 1][4] = $physicalMonitors[$i][0]
|
|
Next
|
|
|
|
Return $monitors
|
|
EndFunc
|
|
|
|
|
|
Func _getContainingMonitor($hwnd)
|
|
$monitors = _genMonitorList()
|
|
$desiredWinPos = _WinGetClientPos($hwnd)
|
|
$containingMonitor = Null
|
|
|
|
If _WinAPI_IsIconic($hwnd) Then
|
|
Return "Iconic"
|
|
Else
|
|
Return _WinAPI_MonitorFromWindow($hwnd)
|
|
EndIf
|
|
#cs === THIS IS OLD CODE ===
|
|
; Find containing monitor by the upper left corner of the application
|
|
$OldDeltaX = 99999999999
|
|
$OldDeltaY = 99999999999
|
|
$deltaX = 0
|
|
$deltaY = 0
|
|
For $i = 0 To UBound($monitors) - 1
|
|
If $desiredWinPos[0] >= $monitors[$i][0] And $desiredWinPos[1] >= $monitors[$i][1] And $desiredWinPos[0] <= $monitors[$i][0] + $monitors[$i][2] And $desiredWinPos[1] <= $monitors[$i][1] + $monitors[$i][3] Then
|
|
$deltaX = $desiredWinPos[0] - $monitors[$i][0]
|
|
$deltaY = $desiredWinPos[1] - $monitors[$i][1]
|
|
If $deltaX < $OldDeltaX And $deltaY < $OldDeltaY Then
|
|
$OldDeltaX = $deltaX
|
|
$OldDeltaY = $deltaY
|
|
$containingMonitor = $monitors[$i][4]
|
|
Else
|
|
ConsoleWrite("Second monitor found but delta is to high" & @CRLF)
|
|
EndIf
|
|
|
|
;ConsoleWrite("=== " & WinGetTitle($hwnd) & " ===" & @CRLF)
|
|
;ConsoleWrite("$desiredWinPos[0] ("&$desiredWinPos[0]&") >= (" & $monitors[$i][0] & ") $monitors[$i][0]" & @CRLF)
|
|
;ConsoleWrite("$desiredWinPos[1] ("&$desiredWinPos[1]&") >= (" & $monitors[$i][1] & ") $monitors[$i][1]" & @CRLF)
|
|
;ConsoleWrite("$desiredWinPos[0] ("&$desiredWinPos[0]&") <= (" & $monitors[$i][0] + $monitors[$i][2] & ") $monitors[$i][0] + $monitors[$i][2]" & @CRLF)
|
|
;ConsoleWrite("$desiredWinPos[1] ("&$desiredWinPos[1]&") <= (" & $monitors[$i][1] + $monitors[$i][3] & ") $monitors[$i][1] + $monitors[$i][3]" & @CRLF)
|
|
EndIf
|
|
Next
|
|
|
|
; If no monitor was found, check if maybe the end of the application is visible
|
|
If $containingMonitor == Null Then
|
|
$step = 100
|
|
; Try to find containing monitor by checking each pixel of the window
|
|
; This needs much computing power, so we first check in steps of 100 and go down to 1 until we found it
|
|
While $step > 0
|
|
For $i = 0 To UBound($monitors) - 1
|
|
For $width = 1 To $desiredWinPos[2] Step $step
|
|
For $height = 1 To $desiredWinPos[2] Step $step
|
|
If $desiredWinPos[0] + $width >= $monitors[$i][0] And $desiredWinPos[1] + $height >= $monitors[$i][1] And $desiredWinPos[0] + $width <= $monitors[$i][0] + $monitors[$i][2] And $desiredWinPos[1] + $height <= $monitors[$i][1] + $monitors[$i][3] Then
|
|
$containingMonitor = $monitors[$i][4]
|
|
ExitLoop
|
|
EndIf
|
|
Next
|
|
If $containingMonitor <> Null Then ExitLoop
|
|
Next
|
|
If $containingMonitor <> Null Then ExitLoop
|
|
Next
|
|
If $containingMonitor <> Null Then ExitLoop
|
|
$step -= 1
|
|
WEnd
|
|
EndIf
|
|
|
|
Return $containingMonitor
|
|
#ce
|
|
EndFunc
|
|
|
|
|
|
Func _WinGetClientPos($hwnd)
|
|
Local $client = _WinAPI_GetClientRect($hwnd)
|
|
Local $window = _WinAPI_GetWindowRect($hwnd)
|
|
Local $cRight = DllStructGetData($client, "Right")
|
|
Local $cBottom = DllStructGetData($client, "Bottom")
|
|
Local $wTop = DllStructGetData($window, "Top")
|
|
Local $wLeft = DllStructGetData($window, "Left")
|
|
Local $wRight = DllStructGetData($window, "Right")
|
|
Local $wBottom = DllStructGetData($window, "Bottom")
|
|
Local $borderLTR = (DllStructGetData($window, "Right") - DllStructGetData($window, "Left")) - DllStructGetData($client, "Right")
|
|
Local $borderTop = (DllStructGetData($window, "Bottom") - DllStructGetData($window, "Top")) - DllStructGetData($client, "Bottom")
|
|
Local $realPos[4]
|
|
$realPos[0] = $wLeft + ($borderLTR/2)
|
|
$realPos[1] = $wTop + ($borderTop/2)
|
|
$realPos[2] = ($wRight - $wLeft) - $borderLTR
|
|
$realPos[3] = ($wBottom - $wTop) - ($borderTop/2) - ($borderLTR/2)
|
|
|
|
Return $realPos
|
|
EndFunc |