WinBatch Tech Support Home

Database Search

If you can't find the information using the categories below, post a question over in our WinBatch Tech Support Forum.

TechHome

WMI
plus
plus

Can't find the information you are looking for here? Then leave a message over on our WinBatch Tech Support Forum.

List Available Screen Resolutions


Question:

Is there a way to retrieve ALL the possible resolutions for the current computer ?

I can get the current ones with the script below. Is there a way to query to get what other resolutions work with the current PC setup?

;Retrieve information
objWMIService = GetObject( "winmgmts://./root/cimv2" )
colItems = objWMIService.ExecQuery( "Select * from Win32_DisplayConfiguration", , 48 )
strMsg = ""
;Format output
ForEach objItem In colItems
   strMsg = StrCat(strMsg, "VideoCard   : " , objItem.DeviceName , @CRLF)
   strMsg = StrCat(strMsg, "XResolution : " , objItem.PelsWidth , @CRLF)
   strMsg = StrCat(strMsg, "YResolution : " , objItem.PelsHeight , @CRLF)
   strMsg = StrCat(strMsg, "BitsPerPel  : " , objItem.BitsPerPel , @CRLF)
   strMsg = StrCat(strMsg, "VRefresh    : " , objItem.DisplayFrequency , @CRLF)
Next
;Display the result
Message("Debug", strMsg)

Answer:

Here is some code that should be able to get all of those possible values.

UserDll=StrCat(DirWindows(1),"USER32.DLL")
TDEVICEMODEA=BinaryAlloc(156)                      ;DEVMODE structure
;Size of TDEVICEMODEA record: 156 Bytes
;Field offsets and sizes are:
offdmDeviceName       = 0   ;32
offdmSpecVersion      = 32  ;2
offdmDriverVersion    = 34  ;2
offdmSize             = 36  ;2
offdmDriverExtra      = 38  ;2
offdmFields           = 40  ;4
offdmOrientation      = 44  ;2
offdmPaperSize        = 46  ;2
offdmPaperLength      = 48  ;2
offdmPaperWidth       = 50  ;2
offdmScale            = 52  ;2
offdmCopies           = 54  ;2
offdmDefaultSource    = 56  ;2
offdmPrintQuality     = 58  ;2
offdmColor            = 60  ;2
offdmDuplex           = 62  ;2
offdmYResolution      = 64  ;2
offdmTTOption         = 66  ;2
offdmCollate          = 68  ;2
offdmFormName         = 70  ;32
offdmLogPixels        = 102 ;2
offdmBitsPerPel       = 104 ;4
offdmPelsWidth        = 108 ;4
offdmPelsHeight       = 112 ;4
offdmDisplayFlags     = 116 ;4
offdmDisplayFrequency = 120 ;4
offdmICMMethod        = 124 ;4
offdmICMIntent        = 128 ;4
offdmMediaType        = 132 ;4
offdmDitherType       = 136 ;4
offdmICCManufacturer  = 140 ;4
offdmICCModel         = 144 ;4
offdmPanningWidth     = 148 ;4
offdmPanningHeight    = 152 ;4
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
;Bool EnumDisplaySettingsA (String:lpszDeviceName,Integer:iModeNum,Pointer:lpDevMode)
;   lpszDeviceName is a pointer to the target display adapter.  Null specifies default adapter.
;   iModeNum specifies whether to query the display adapter or the registry settings for the adapter.
;   lpDevMode is a pointer to a DevMode structure to store info about the specified graphics mode.
ModeIndex=0
Selection=""
data = ''
While 1
   ReturnValue=DllCall(UserDll,long:"EnumDisplaySettingsA",lpnull,long:ModeIndex,lpbinary:TDEVICEMODEA )
   If ReturnValue==0 Then Break

;   Get info on relevant display settings
   dmPelsWidth        = BinaryPeek4(TDEVICEMODEA,offdmPelsWidth)        ;Horizontal resolution
   dmPelsHeight       = BinaryPeek4(TDEVICEMODEA,offdmPelsHeight)       ;Vertical resolution
   dmBitsPerPel       = BinaryPeek4(TDEVICEMODEA,offdmBitsPerPel)       ;Color depth
   dmDisplayFrequency = BinaryPeek4(TDEVICEMODEA,offdmDisplayFrequency) ;Refresh Rate
   dmDisplayFlags     = BinaryPeek4(TDEVICEMODEA,offdmDisplayFlags)

   data = StrCat(data,dmPelsWidth,',',dmPelsHeight,',',dmBitsPerPel,',',dmDisplayFrequency, @TAB)
   ModeIndex = ModeIndex+1
EndWhile
AskItemlist("Screen Resolutions (width,height,bitsperpixel,frequency)",data,@TAB,@UNSORTED,@SINGLE)
BinaryFree(TDEVICEMODEA)
Exit

Article ID:   W17320
File Created: 2007:07:03:14:29:28
Last Updated: 2007:07:03:14:29:28