You can access the system registry HKEY_CURRENT_CONFIGDISPLAYSETINGS to learn when
The front display resolution and the number of colors.
However, the following methods are commonly used:
Key API functions are EnumDisplaySettings and ChangeDisplaySettings. Before
Is used to obtain all the display modes supported by the current display driver, while the latter is used to change the display mode.
If a program changes the display modeWindows sends
WM_DISPLAYCHANGE message. You can use the following function to obtain the current display mode.
The Registry is reliable.
Bool CVideoModes: GetCurrentVideoSettings (DEVMODE * devmode)
{
HWND hwndDesktop = getdomaintopwindow ();
HDC hdc = GetDC (hwndDesktop );
Devmode-> dmSize = sizeof (DEVMODE );
Devmode-> dmBitsPerPel = GetDeviceCaps (hdc, BITSPIXEL );
Devmode-> dmPelsWidth = GetSystemMetrics (SM_CXSCREEN );
Devmode-> dmPelsHeight = GetSystemMetrics (SM_CYSCREEN );
Devmode-> dmFields = DM_BITSPERPEL | DM_PELSWIDTH | DM_PELSHEIGHT;
Return TRUE;
}
The following code shows how to use EnumDisplaySettings to obtain all currently supported display modes:
Int modenum, done;
DEVMODE devmode;
Done = 0;
Modenum = 0;
Do
{
Done =! EnumDisplaySettings (NULL, modenum, & devmode );
AddToList (& devmode );
Modenum ++;
} While (! Done );
You can set the display mode as follows:
Rc = ChangeDisplaySettings (& devmodeCDS_FULLSCREEN); The devmode here is
YesObtained by EnumDisplaySettings.
If the setting is normal, the returned value is DISP_CHANGE_SUCCESSFUL.