Change the display mode directly in the program

zhaozj2021-02-11  225

Change the display mode directly in the program

You can access the system registry hkey_current_config / display / setings to know the current display resolution and number of colors. However, the following methods are often used: The key API function is EnumdisPlaySettings and ChangeDisplaySettings. The former is used to get all the display modes supported by the currently display drive, while the latter is used to change the display mode. If some programs change the display mode, Windows sends a WM_DISPLAYCHANGE message to all the running programs. Getting the current display mode can use the following function, it is more reliable than accessing the registry. Bool CVideoModes :: GetCurrentVideoSettings (DEVMODE * devmode) {HWND hwndDesktop = GetDesktopWindow (); 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 all display modes how to use EnumDisplaySettings get the currently supported: int MODENUM, DONE; DEVMODE DEVMODE; DONE = 0; modenum = 0; do {done =! EnumdisplaySettings (null, modenum, & devmode); addtolist (& devmode); modenum ;} while (! done); setting display mode is as follows: RC = ChangeDisplaySettings (& devmodecds_fullscreen); The devmode here is obtained in front of EnumdisplaySettings. If you set it normally, return value DISP_CHANGE_SUCCESSFUL.

转载请注明原文地址:https://www.9cbs.com/read-4071.html

New Post(0)