readmedottxt Posted April 26, 2009 Share Posted April 26, 2009 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 Link to comment Share on other sites More sharing options...
Valuater Posted April 27, 2009 Share Posted April 27, 2009 Maybe this can helphttp://www.autoitscript.com/forum/index.ph...st&p=2965238) Link to comment Share on other sites More sharing options...
Yashied Posted April 27, 2009 Share Posted April 27, 2009 (edited) 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? Thankslocal $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 April 27, 2009 by Yashied My UDFs: iKey | FTP Uploader | Battery Checker | Boot Manager | Font Viewer | UDF Keyword Manager | Run Dialog Replacement | USBProtect | 3D Axis | Calculator | Sleep | iSwitcher | TM | NetHelper | File Types Manager | Control Viewer | SynFolders | DLL Helper Animated Tray Icons UDF Library | Hotkeys UDF Library | Hotkeys Input Control UDF Library | Caret Shape UDF Library | Context Help UDF Library | Most Recently Used List UDF Library | Icons UDF Library | FTP UDF Library | Script Communications UDF Library | Color Chooser UDF Library | Color Picker Control UDF Library | IPHelper (Vista/7) UDF Library | WinAPI Extended UDF Library | WinAPIVhd UDF Library | Icon Chooser UDF Library | Copy UDF Library | Restart UDF Library | Event Log UDF Library | NotifyBox UDF Library | Pop-up Windows UDF Library | TVExplorer UDF Library | GuiHotKey UDF Library | GuiSysLink UDF Library | Package UDF Library | Skin UDF Library | AITray UDF Library | RDC UDF Library Appropriate path | Button text color | Gaussian random numbers | Header's styles (Vista/7) | ICON resource enumeration | Menu & INI | Tabbed string size | Tab's skin | Pop-up circular menu | Progress Bar without animation (Vista/7) | Registry export | Registry path jumping | Unique hardware ID | Windows alignment More... Link to comment Share on other sites More sharing options...
readmedottxt Posted May 11, 2009 Author Share Posted May 11, 2009 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 expandcollapse popuplocal $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 More sharing options...
Yashied Posted May 11, 2009 Share Posted May 11, 2009 Thanks for that - it worked 100% - more questions after the code. Here's some rough code that does the job expandcollapse popuplocal $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.... Thanks1. 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 My UDFs: iKey | FTP Uploader | Battery Checker | Boot Manager | Font Viewer | UDF Keyword Manager | Run Dialog Replacement | USBProtect | 3D Axis | Calculator | Sleep | iSwitcher | TM | NetHelper | File Types Manager | Control Viewer | SynFolders | DLL Helper Animated Tray Icons UDF Library | Hotkeys UDF Library | Hotkeys Input Control UDF Library | Caret Shape UDF Library | Context Help UDF Library | Most Recently Used List UDF Library | Icons UDF Library | FTP UDF Library | Script Communications UDF Library | Color Chooser UDF Library | Color Picker Control UDF Library | IPHelper (Vista/7) UDF Library | WinAPI Extended UDF Library | WinAPIVhd UDF Library | Icon Chooser UDF Library | Copy UDF Library | Restart UDF Library | Event Log UDF Library | NotifyBox UDF Library | Pop-up Windows UDF Library | TVExplorer UDF Library | GuiHotKey UDF Library | GuiSysLink UDF Library | Package UDF Library | Skin UDF Library | AITray UDF Library | RDC UDF Library Appropriate path | Button text color | Gaussian random numbers | Header's styles (Vista/7) | ICON resource enumeration | Menu & INI | Tabbed string size | Tab's skin | Pop-up circular menu | Progress Bar without animation (Vista/7) | Registry export | Registry path jumping | Unique hardware ID | Windows alignment More... Link to comment Share on other sites More sharing options...
Stilez Posted August 6, 2011 Share Posted August 6, 2011 I'm using and it seems to work well, including in a virtual machine. Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now