Jump to content
Sign in to follow this  

Function: monitor_resolutions

Recommended Posts


I also attached it (see below the code) so that you can download it.


PS: Made a small update to fix a problems with laptops.

; function monitor_resolutions()
; -John Taylor
; Sept-9-2006
; returns an array of monitors with their corresponding resolutions
; array[0][0] contains the number of monitors
; array[1][0] is the width of the 1st monitor
; array[1][1] is the height of the 1st monitor

Opt("MustDeclareVars", 1)

Func monitor_resolutions()
    local $wmi_svc, $slots, $monitor
    local $h, $v
    local $i
    local $results[16][2]

    local $debug = 0

    $wmi_svc = ObjGet("winmgmts:\\.\root\CIMV2")
    if "" == $wmi_svc then
        if 1 == $debug then MsgBox(0,"WMI Error", "Can connect to WMI service")
        return -1

    $slots = $wmi_svc.ExecQuery("SELECT CurrentHorizontalResolution,CurrentVerticalResolution FROM Win32_VideoController", "WQL", (0x10 + 0x20) )

    if Not IsObj( $slots ) then 
        if 1 == $debug then MsgBox(0, "WMI Error", "No WMI objects found")
        return -2

    ; count the number of monitors and
    ; iterate through each monitor and populate the $results array
    $i = 0
    for $monitor in $slots
        $h = int($monitor.CurrentHorizontalResolution)
        $v = int($monitor.CurrentVerticalResolution)
        if $h <= 1 or $v <= 1 then ContinueLoop

        $i += 1
        if 1 = $debug then MsgBox(0, "Monitor " & $i, "Resolution : " & $h & "x" & $v)

        $results[$i][0] = $h
        $results[$i][1] = $v
    $results[0][0] = $i

    return $results

; testing
Dim $mon = monitor_resolutions()
Dim $j

for $j = 1 to $mon[0][0]
    MsgBox(0, "Monitor " & $j, $mon[$j][0] & "x" & $mon[$j][1])


Edited by jftuga

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  


Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.