Jump to content
Sign in to follow this  

Fetch the width and height of a specific monitor

Recommended Posts

I can't take any credit for this

#include <Array.au3>
Global $__MonitorList[1][5]
$__MonitorList[0][0] = 0
$res = _GetMonitors()
#Region thanks to xrxca for these functions
Func _GetMonitors()
 $__MonitorList[0][0] = 0 ;  Added so that the global array is reset if this is called multiple times
 Local $handle = DllCallbackRegister("_MonitorEnumProc", "int", "hwnd;hwnd;ptr;lparam")
 DllCall("user32.dll", "int", "EnumDisplayMonitors", "hwnd", 0, "ptr", 0, "ptr", DllCallbackGetPtr($handle), "lparam", 0)
 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]
 Return $__MonitorList
EndFunc   ;==>_GetMonitors
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]
 If $hDC = $hDC Then
 If $lParam = $lParam Then
 $__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 ; Return 1 to continue enumeration
EndFunc   ;==>_MonitorEnumProc
#EndRegion thanks to xrxca for these functions



My Android cat and mouse game

We're gonna need another Timmy!

Share this post

Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Create New...