March 9, 2021
Hot Topics:

Screen Resolutions

  • By Steve Anderson
  • Send Email »
  • More Articles »

Now that you can retrieve both the current screen resolutions and number of colours that are selected in Windows, you will want to know how you can enumerate the resolutions and colour modes that a machine supports. This can be very useful especially with changing the screen resolution programmatically, as you must know whether the computer supports it.


This API function retrieves information about the display driver’s graphics modes. There are three parameters:

LpszDeviceName – Leave this as null (0&)

IModeNum = This is the index of the display mode that you want to retrieve information about, starting with 0. You call this in a sequence, and it will continue returning modes until 0 is returned by the API function.

PDevMode – This parameter points to a DevMode type structure in which to retrieve information about the graphics modes that are available.

The following properties of the DevMode structure will be retrieved:

  • dmBitsPerPel – This is the bits per pixel or colour depth that is available in the selected graphics mode
  • dmPelsWidth – This is the width of the screen or the x axis.
  • dmPelsHeight – This is the height of the screen or the y axis.

Now to create a function to do this.

Private Declare Function EnumDisplaySettings Lib _
"user32" Alias "EnumDisplaySettingsA" _
(ByVal lpszDeviceName As Long, ByVal iModeNum As Long, _
lpDevMode As Any) As Boolean

'Screen Resolution
Private Const CCDEVICENAME = 32
Private Const CCFORMNAME = 32

Private Type DEVMODE
  dmDeviceName As String * CCDEVICENAME
  dmSpecVersion As Integer
  dmDriverVersion As Integer
  dmSize As Integer
  dmDriverExtra As Integer
  dmFields As Long
  dmOrientation As Integer
  dmPaperSize As Integer
  dmPaperLength As Integer
  dmPaperWidth As Integer
  dmScale As Integer
  dmCopies As Integer
  dmDefaultSource As Integer
  dmPrintQuality As Integer
  dmColor As Integer
  dmDuplex As Integer
  dmYResolution As Integer
  dmTTOption As Integer
  dmCollate As Integer
  dmFormName As String * CCFORMNAME
  dmUnusedPadding As Integer
  dmBitsPerPel As Integer
  dmPelsWidth As Long
  dmPelsHeight As Long
  dmDisplayFlags As Long
  dmDisplayFrequency As Long
End Type

Public Sub EnumDisplay()

Dim lTemp As Long, tDevMode As DEVMODE, lIndex As Long
' Declare variables
lIndex = 0
lTemp = EnumDisplaySettings(0&, lIndex, tDevMode)
' Call the API function with the current index
If lTemp = 0 Then Exit Do
' If the API function returns 0 then no more
' data is availible or an error has occurred.
' As you increase the index on each call
' when there is no more data to enumerate the
' function will return 0

With tDevMode
Debug.Print .dmPelsWidth & " pixels by " _
& .dmPelsHeight & " pixels, Color Mode " _
& .dmBitsPerPel & " bit"
' Print the mode information to the debug
End With

lIndex = lIndex + 1
End Sub

This function will enumerate all the display modes and display them in the debug window.

The functions here are demonstrated in the EnumDisplayModes demo project.

Page 4 of 6

This article was originally published on November 20, 2002

Enterprise Development Update

Don't miss an article. Subscribe to our newsletter below.

Thanks for your registration, follow us on our social networks to keep up-to-date