Jump to content

Detecting an LCDs native resolution


Recommended Posts

I've found a couple of WMI commands to detect the current monitor resolution but are there any ways to query the monitor to discover its native resolution?

Thanks

local $tDEVMODE = DllStructCreate('byte[32];dword[10];byte[32];dword[6]')
local $pDEVMODE = DllStructGetPtr($tDEVMODE)
local $i = 0, $Ret

while 1
    $Ret = DllCall('user32.dll', 'int', 'EnumDisplaySettings', 'ptr', 0, 'dword', $i, 'ptr', $pDEVMODE)
    if (@error) or ($Ret[0] = 0) then
        exitloop
    endif
    $Width = DllStructGetData($tDEVMODE, 4, 2)
    $Height = DllStructGetData($tDEVMODE, 4, 3)
    $Bits = DllStructGetData($tDEVMODE, 4, 1)
    ConsoleWrite($Width & ' x ' & $Height & ' x ' & $Bits & ' bit' & @CR)
    $i += 1
wend

Maximum resolution from this list is native resolution for LCD monitors.

^_^

Edited by Yashied
Link to comment
Share on other sites

  • 2 weeks later...

local $tDEVMODE = DllStructCreate('byte[32];dword[10];byte[32];dword[6]')
local $pDEVMODE = DllStructGetPtr($tDEVMODE)
local $i = 0, $Ret

while 1
    $Ret = DllCall('user32.dll', 'int', 'EnumDisplaySettings', 'ptr', 0, 'dword', $i, 'ptr', $pDEVMODE)
    if (@error) or ($Ret[0] = 0) then
        exitloop
    endif
    $Width = DllStructGetData($tDEVMODE, 4, 2)
    $Height = DllStructGetData($tDEVMODE, 4, 3)
    $Bits = DllStructGetData($tDEVMODE, 4, 1)
    ConsoleWrite($Width & ' x ' & $Height & ' x ' & $Bits & ' bit' & @CR)
    $i += 1
wend

Maximum resolution from this list is native resolution for LCD monitors.

:)

Thanks for that - it worked 100% - more questions after the code.

Here's some rough code that does the job

local $tDEVMODE = DllStructCreate('byte[32];dword[10];byte[32];dword[6]')
local $pDEVMODE = DllStructGetPtr($tDEVMODE)
local $i = 0, $Ret
$Res = ""


;-----------------------------------------------------
; populate all resolutions into a buffer
;-----------------------------------------------------
while 1
    $Ret = DllCall('user32.dll', 'int', 'EnumDisplaySettings', 'ptr', 0, 'dword', $i, 'ptr', $pDEVMODE)
    if (@error) or ($Ret[0] = 0) then
        exitloop
    endif
    $Width = DllStructGetData($tDEVMODE, 4, 2)
    $Height = DllStructGetData($tDEVMODE, 4, 3)
    $Bits = DllStructGetData($tDEVMODE, 4, 1)
    $Res = $Res & $Width & "," & $Height & "," & $Bits & ":"
    $i += 1
wend
;MsgBox(0, "", $Res)


;-----------------------------------------------------
; Find highest resolution
;-----------------------------------------------------

; lets split the string into an array using a colon (:) as a delimiter
$arrRes = StringSplit($Res, ":")


; Lets find the highest color depth
$ColorDepth = 0
for $i = 1 to 5000
    $tmp1 = StringSplit($arrRes[$i], ",")
    if @error then ExitLoop
    
    if UBound($tmp1) = 4 Then; check if array has 4 elements (640, 480, 8, null), if so, obtain the highest color depth from the array
        if Number($tmp1[3]) > $ColorDepth Then 
            $ColorDepth = Number($tmp1[3])
        EndIf
    EndIf
        
Next


; Lets find the highest X resolution eg 1024 x XXX x XX
$XRes = 0
for $i = 1 to 5000
    $tmp1 = StringSplit($arrRes[$i], ",")
    if @error then ExitLoop
    
    if UBound($tmp1) = 4 Then; check if array has 4 elements (640, 480, 8, null), if so, obtain the highest color depth from the array
        if Number($tmp1[1]) > $XRes Then 
            $XRes = Number($tmp1[1])
        EndIf
    EndIf
        
Next


; lets find the highest Y resolution only if the X resolution equals above
$YRes = 0
for $i = 1 to 5000
    $tmp1 = StringSplit($arrRes[$i], ",")
    if @error then ExitLoop
    
    if UBound($tmp1) = 4 Then; check if array has 4 elements (640, 480, 8, null), if so, obtain the highest color depth from the array
        if Number($tmp1[1]) = $XRes Then; only query array objects that match the X resolution
            if Number($tmp1[2]) > $YRes Then
                $YRes = Number($tmp1[2])
            EndIf
        EndIf
    EndIf
Next

            
msgbox(0, "", "Native resolution is " & $XRes & " x " & $YRes & " x " & $ColorDepth, 1)

How could I detect if the monitor is a CRT or an LCD? Again, I'm not certain of which WMI objects to query or any other methods of getting the data....

Thanks

Link to comment
Share on other sites

Thanks for that - it worked 100% - more questions after the code.

Here's some rough code that does the job

local $tDEVMODE = DllStructCreate('byte[32];dword[10];byte[32];dword[6]')
local $pDEVMODE = DllStructGetPtr($tDEVMODE)
local $i = 0, $Ret
$Res = ""


;-----------------------------------------------------
; populate all resolutions into a buffer
;-----------------------------------------------------
while 1
    $Ret = DllCall('user32.dll', 'int', 'EnumDisplaySettings', 'ptr', 0, 'dword', $i, 'ptr', $pDEVMODE)
    if (@error) or ($Ret[0] = 0) then
        exitloop
    endif
    $Width = DllStructGetData($tDEVMODE, 4, 2)
    $Height = DllStructGetData($tDEVMODE, 4, 3)
    $Bits = DllStructGetData($tDEVMODE, 4, 1)
    $Res = $Res & $Width & "," & $Height & "," & $Bits & ":"
    $i += 1
wend
;MsgBox(0, "", $Res)


;-----------------------------------------------------
; Find highest resolution
;-----------------------------------------------------

; lets split the string into an array using a colon (:) as a delimiter
$arrRes = StringSplit($Res, ":")


; Lets find the highest color depth
$ColorDepth = 0
for $i = 1 to 5000
    $tmp1 = StringSplit($arrRes[$i], ",")
    if @error then ExitLoop
    
    if UBound($tmp1) = 4 Then; check if array has 4 elements (640, 480, 8, null), if so, obtain the highest color depth from the array
        if Number($tmp1[3]) > $ColorDepth Then 
            $ColorDepth = Number($tmp1[3])
        EndIf
    EndIf
        
Next


; Lets find the highest X resolution eg 1024 x XXX x XX
$XRes = 0
for $i = 1 to 5000
    $tmp1 = StringSplit($arrRes[$i], ",")
    if @error then ExitLoop
    
    if UBound($tmp1) = 4 Then; check if array has 4 elements (640, 480, 8, null), if so, obtain the highest color depth from the array
        if Number($tmp1[1]) > $XRes Then 
            $XRes = Number($tmp1[1])
        EndIf
    EndIf
        
Next


; lets find the highest Y resolution only if the X resolution equals above
$YRes = 0
for $i = 1 to 5000
    $tmp1 = StringSplit($arrRes[$i], ",")
    if @error then ExitLoop
    
    if UBound($tmp1) = 4 Then; check if array has 4 elements (640, 480, 8, null), if so, obtain the highest color depth from the array
        if Number($tmp1[1]) = $XRes Then; only query array objects that match the X resolution
            if Number($tmp1[2]) > $YRes Then
                $YRes = Number($tmp1[2])
            EndIf
        EndIf
    EndIf
Next

            
msgbox(0, "", "Native resolution is " & $XRes & " x " & $YRes & " x " & $ColorDepth, 1)

How could I detect if the monitor is a CRT or an LCD? Again, I'm not certain of which WMI objects to query or any other methods of getting the data....

Thanks

1. Wow!!! Are you not able to think of an easier way to find the native resolution? Do you there are some associations with the following entries: Width x Height x Bits?

2. Most LCD monitors frequency is 60 Hz. You can use it to determine the type of monitor. Of course this is not 100% accurate method, but the other way, I do not see.

local $tDEVMODE = DllStructCreate('byte[32];dword[10];byte[32];dword[6]')
local $pDEVMODE = DllStructGetPtr($tDEVMODE)
local $i = 0, $m, $Ret, $Mult = 0, $Native[4]

while 1
    $Ret = DllCall('user32.dll', 'int', 'EnumDisplaySettings', 'ptr', 0, 'dword', $i, 'ptr', $pDEVMODE)
    if (@error) or ($Ret[0] = 0) then
        exitloop
    endif
    $Width = DllStructGetData($tDEVMODE, 4, 2)
    $Height = DllStructGetData($tDEVMODE, 4, 3)
    $Bits = DllStructGetData($tDEVMODE, 4, 1)
    $m = $Width * $Height * $Bits
    if $m > $Mult then
        $Native[0] = $Width
        $Native[1] = $Height
        $Native[2] = $Bits
        $Native[3] = DllStructGetData($tDEVMODE, 4, 5)
        $Mult = $m
    endif
    $i += 1
wend

if $Mult > 0 then
    if $Native[3] = 60 then
        $Native[3] = 'LCD'
    else
        $Native[3] = 'CRT'
    endif
    ConsoleWrite('Native resolution is ' & $Native[0] & 'x' & $Native[1] & 'x' & $Native[2] & ' (' & $Native[3] & ')' & @CR)
else
    ConsoleWrite('Error!' & @CR)
endif
Link to comment
Share on other sites

  • 2 years later...

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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...