Enumerate and Change Display Modes
2013-10-18 16:38
288 查看
http://www.codeproject.com/Articles/2518/Enumerate-and-Change-Display-Modes
Introduction
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 theEnumDisplaySettingsAPI 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:
Collapse |
Copy Code
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
iModeNumparameter before each subsequent call to
EnumDisplaySettings. According to MSDN, graphics mode indexes start at zero and when you call
EnumDisplaySettingswith
iModeNumset to zero, the OS initializes and caches information about the display device. When you call the function with
iModeNumset to a non-zero value, the function returns the information that was cached the last time the function was called with
iModeNumset to zero.
The Current Display Mode
To find the display mode currently in use, set theiModeNumparameter of
EnumDisplaySettingsto
ENUM_CURRENT_SETTINGS.
Collapse |
Copy Code
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 theChangeDisplaySettingsAPI function.
Collapse |
Copy Code
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); }
Conclusion
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 RevisionLicense
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.相关文章推荐
- JSF Logic: Dymanically display images and change text style
- how to change the ruby and rails version
- gparted and how to change /home directory to a new partition
- Multiple VideoDisplay and playback controls for each using repeater
- [PowerShell Utils] Automatically Change DNS and then Join Domain
- Verification and Change-Impact Analysis of Access Control Policies
- Understanding ChangeSets and Merge with Team Foundation Server
- Rockie's Android Porting Guide(5)——Change your location and add the screenlock
- step by step change public-ip and vip
- ALV Tree Demo using RS_TREE_LIST_DISPLAY and RS_TREE_CONSTRUCT
- Search Bar and Search Display Controller在iOS8的兼容问题。
- Training - Problem and Change Management
- theano tutorial(九)Configuration Settings and Compiling Modes(译)
- How to Collect and Display System Statistics (CPU and IO) for CBO use
- Oracle 11g Data Guard: How to Change Data Guard Protection Modes
- Method and apparatus for loading a segment register in a microprocessor capable of operating in multiple modes
- Linux下安装oracle数据库提示DISPLAY not set. Please set the DISPLAY and try again。
- How to Change the DBID and the DBNAME by using NID [ID 224266.1]
- What will be the change in complexity if we will choose 2 and 3 pivots in the quicksort algorithm
- Get and display the size of file and directory in Linux system using du command 获取和现实linux文件大小(三)