Click here to Skip to main content
13,596,556 members
Click here to Skip to main content
Add your own
alternative version


25 bookmarked
Posted 29 Jun 2002

Enumerate and Change Display Modes

, 29 Jun 2002
Rate this:
Please Sign up or sign in to vote.
Get all possible display modes and change them using EnumDisplaySettings and ChangeDisplaySettings functions.
<!-- Download Links --> <!-- Article image -->

Sample Image - enum_display_modes.jpg

<!-- Add the rest of your HTML here -->


This article will briefly describe how to get all possible display modes for a system, including the current mode and also how to change the display mode dynamically.

Enumerating All Modes

To get all display modes available on the system, we use the EnumDisplaySettings API function.

From MSDN:
The EnumDisplaySettings function retrieves information about one of the graphics modes for a display device. To retrieve information for all the graphics modes of a display device, make a series of calls to this function.

So, to get all modes, we need to call this function until it returns FALSE. Here's the code:

<pre lang=c++> BOOL bRetVal; CString sDevMode; iMode = 0; do { bRetVal = ::EnumDisplaySettings(NULL, iMode, &devmode); iMode++; if (bRetVal) { sDevMode.Format("%d x %d, %d bits %dhtz", devmode.dmPelsWidth, devmode.dmPelsHeight, devmode.dmBitsPerPel, devmode.dmDisplayFrequency); // list box for all modes (see demo) if (m_lb1.AddString(sDevMode)==LB_ERR) AfxMessageBox("An error occurred!!!"); } } while (bRetVal);

In the above code segment, we increment the iModeNum parameter before each subsequent call to EnumDisplaySettings. According to MSDN, graphics mode indexes start at zero and when you call EnumDisplaySettings with iModeNum set to zero, the OS initializes and caches information about the display device. When you call the function with iModeNum set to a non-zero value, the function returns the information that was cached the last time the function was called with iModeNum set to zero.

The Current Display Mode

To find the display mode currently in use, set the iModeNum parameter of EnumDisplaySettings to ENUM_CURRENT_SETTINGS.

<pre lang=c++> if (::EnumDisplaySettings(NULL, ENUM_CURRENT_SETTINGS, &devmode)) { sDevMode.Format("%i x %i, %i bits %dhtz", devmode.dmPelsWidth, devmode.dmPelsHeight, devmode.dmBitsPerPel, devmode.dmDisplayFrequency); m_lb1.SelectString(0, sDevMode); }

Changing Modes

If you want to change the current display mode, use the ChangeDisplaySettings API function.

<pre lang=c++> BOOL bRetVal; iMode = m_lb1.GetCurSel(); bRetVal = ::EnumDisplaySettings(NULL, iMode, &devmode); if (bRetVal) { devmode.dmFields = DM_PELSWIDTH | DM_PELSHEIGHT | DM_BITSPERPEL | DM_DISPLAYFREQUENCY; ::ChangeDisplaySettings(&devmode, 0); }


This code can be used for DirectX programming to make sure the display adapter supports the correct modes. Other than that, its probably not a good idea to change the user's display mode in your app. But hey, that's up to you. (It is fun to play with however :) ).

Revision History

30 Jun 2002 - Initial Revision


This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


About the Author

Jason Henderson
United States United States
I have been a professional developer since 1996. I live in the middle of no where in Illinois, USA. I am married and have four children.

You may also be interested in...


Comments and Discussions

Questionthank you so much jason. Pin
Member 94277515-Mar-15 8:05
memberMember 94277515-Mar-15 8:05 
QuestionHow to remove a black background ? Pin
FebruaryGuy263-Dec-13 21:27
memberFebruaryGuy263-Dec-13 21:27 
QuestionHow to get list of modes that monitor cannot display? Pin
voltar2311-Oct-07 10:36
membervoltar2311-Oct-07 10:36 
GeneralMulti-Devices Pin
Ted Lin6-Feb-07 21:50
memberTed Lin6-Feb-07 21:50 
GeneralRe: Multi-Devices Pin
Jason Henderson7-Feb-07 2:42
memberJason Henderson7-Feb-07 2:42 
GeneralRe: Multi-Devices Pin
Ted Lin7-Feb-07 16:06
memberTed Lin7-Feb-07 16:06 
QuestionEnumerate and Change to hidden modes Pin
Robert Lin30-Mar-06 0:22
memberRobert Lin30-Mar-06 0:22 
AnswerRe: Enumerate and Change to hidden modes Pin
Member 12688199-Apr-09 22:36
memberMember 12688199-Apr-09 22:36 
GeneralPersistant Settings Pin
Steve Hart1-Feb-04 12:35
sussSteve Hart1-Feb-04 12:35 
GeneralRe: Persistant Settings Pin
Jason Henderson2-Feb-04 4:27
memberJason Henderson2-Feb-04 4:27 
GeneralRe: Persistant Settings Pin
Steve Hart3-Feb-04 8:22
memberSteve Hart3-Feb-04 8:22 
Generalconvexing affect Pin
wizavi23-Mar-03 17:25
memberwizavi23-Mar-03 17:25 
GeneralRe: convexing affect Pin
Jason Henderson24-Mar-03 2:28
memberJason Henderson24-Mar-03 2:28 
GeneralMulti Monitor Pin
Anonymous13-Dec-02 6:37
sussAnonymous13-Dec-02 6:37 
GeneralRe: Multi Monitor Pin
Jason Henderson13-Dec-02 10:04
memberJason Henderson13-Dec-02 10:04 
GeneralHandy bit of Code... Pin
Joel Holdsworth30-Jun-02 4:34
memberJoel Holdsworth30-Jun-02 4:34 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Cookies | Terms of Use | Mobile
Web02-2016 | 2.8.180621.3 | Last Updated 30 Jun 2002
Article Copyright 2002 by Jason Henderson
Everything else Copyright © CodeProject, 1999-2018
Layout: fixed | fluid