Change the display mode directly in the program

Source: Internet
Author: User

 

 

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.

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.