Global Const $MONITOR_DEFAULTTONULL = 0x00000000
Global Const $MONITOR_DEFAULTTOPRIMARY = 0x00000001
Global Const $MONITOR_DEFAULTTONEAREST = 0x00000002
Global Const $CCHDEVICENAME = 32
Global Const $MONITORINFOF_PRIMARY = 0x00000001
$_GetMonitors = _EnumDisplayMonitors()
For $i = 1 to $_GetMonitors[0][0]
Dim $arMonitorInfos[4]
;MsgBox(64, "", "Monitor Handle: "& $_GetMonitors[$i][0] &@CRLF& "Left: "& $_GetMonitors[$i][1] &@CRLF& "Top: "& $_GetMonitors[$i][2] &@CRLF& "Right: "& $_GetMonitors[$i][3] &@CRLF& "Bottom: "& $_GetMonitors[$i][4])
If _GetMonitorInfo($_GetMonitors[$i][0], $arMonitorInfos) Then _
Msgbox(0, "Monitor-Infos", "Rect-Monitor" & @Tab & ": " & $arMonitorInfos[0] & @LF & _
"Rect-Workarea" & @Tab & ": " & $arMonitorInfos[1] & @LF & _
"PrimaryMonitor?" & @Tab & ": " & $arMonitorInfos[2] & @LF & _
"Devicename" & @Tab & ": " & $arMonitorInfos[3])
Next
;==================================================================================================
; Function Name: _EnumDisplayMonitors()
; Description:: Load monitor positions
; Parameter(s): n/a
; Return Value(s): 2D Array of Monitors
; [0][0] = Number of Monitors
; [i][0] = HMONITOR handle of this monitor.
; [i][1] = Left Position of Monitor
; [i][2] = Top Position of Monitor
; [i][3] = Right Position of Monitor
; [i][4] = Bottom Position of Monitor
; Note: [0][1..4] are set to Left,Top,Right,Bottom of entire screen
; hMonitor is returned in [i][0], but no longer used by these routines.
; Also sets $__MonitorList global variable (for other subs to use)
; Author(s): xrxca ([email protected])
;==================================================================================================
Func _EnumDisplayMonitors()
Global $__MonitorList[1][5]
$__MonitorList[0][0] = 0
Local $handle = DllCallbackRegister("_MonitorEnumProc", "int", "hwnd;hwnd;ptr;lparam")
DllCall("user32.dll", "int", "EnumDisplayMonitors", "hwnd", 0, "ptr", 0, "ptr", DllCallbackGetPtr($handle), "lparam", 0)
DllCallbackFree($handle)
Local $i = 0
For $i = 1 To $__MonitorList[0][0]
If $__MonitorList[$i][1] < $__MonitorList[0][1] Then $__MonitorList[0][1] = $__MonitorList[$i][1]
If $__MonitorList[$i][2] < $__MonitorList[0][2] Then $__MonitorList[0][2] = $__MonitorList[$i][2]
If $__MonitorList[$i][3] > $__MonitorList[0][3] Then $__MonitorList[0][3] = $__MonitorList[$i][3]
If $__MonitorList[$i][4] > $__MonitorList[0][4] Then $__MonitorList[0][4] = $__MonitorList[$i][4]
Next
Return $__MonitorList
EndFunc ;==>_EnumDisplayMonitors
Func _GetMonitorInfo($hMonitor, ByRef $arMonitorInfos)
Local $stMONITORINFOEX = DllStructCreate("dword;int[4];int[4];dword;char[" & $CCHDEVICENAME & "]")
DllStructSetData($stMONITORINFOEX, 1, DllStructGetSize($stMONITORINFOEX))
$nResult = DllCall("user32.dll", "int", "GetMonitorInfo", "hwnd", $hMonitor, "ptr", DllStructGetPtr($stMONITORINFOEX))
If $nResult[0] = 1 Then
$arMonitorInfos[0] = DllStructGetData($stMONITORINFOEX, 2, 1) & ";" & _
DllStructGetData($stMONITORINFOEX, 2, 2) & ";" & _
DllStructGetData($stMONITORINFOEX, 2, 3) & ";" & _
DllStructGetData($stMONITORINFOEX, 2, 4)
$arMonitorInfos[1] = DllStructGetData($stMONITORINFOEX, 3, 1) & ";" & _
DllStructGetData($stMONITORINFOEX, 3, 2) & ";" & _
DllStructGetData($stMONITORINFOEX, 3, 3) & ";" & _
DllStructGetData($stMONITORINFOEX, 3, 4)
$arMonitorInfos[2] = DllStructGetData($stMONITORINFOEX, 4)
$arMonitorInfos[3] = DllStructGetData($stMONITORINFOEX, 5)
EndIf
Return $nResult[0]
EndFunc ;==>_GetMonitorInfo
;==================================================================================================
; Function Name: _MonitorEnumProc($hMonitor, $hDC, $lRect, $lParam)
; Description:: Enum Callback Function for EnumDisplayMonitors in _GetMonitors
; Author(s): xrxca ([email protected])
;==================================================================================================
Func _MonitorEnumProc($hMonitor, $hDC, $lRect, $lParam)
Local $Rect = DllStructCreate("int left;int top;int right;int bottom", $lRect)
$__MonitorList[0][0] += 1
ReDim $__MonitorList[$__MonitorList[0][0] + 1][5]
$__MonitorList[$__MonitorList[0][0]][0] = $hMonitor
$__MonitorList[$__MonitorList[0][0]][1] = DllStructGetData($Rect, "left")
$__MonitorList[$__MonitorList[0][0]][2] = DllStructGetData($Rect, "top")
$__MonitorList[$__MonitorList[0][0]][3] = DllStructGetData($Rect, "right")
$__MonitorList[$__MonitorList[0][0]][4] = DllStructGetData($Rect, "bottom")
Return 1
EndFunc ;==>_MonitorEnumProc