Change the display mode directly in the program

Source: Internet
Author: User

Change the display mode directly in the program

You can access the hkey_current_config/display/setings in the system registry to learn the current display resolution and number of colors.
However, the following methods are commonly used:
Key API functions are enumdisplaysettings and changedisplaysettings. The former 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 mode, Windows sends the wm_displaychange message to all running programs. To obtain the current display mode, you can use the following function, which is more reliable than accessing the registry.
Bool cvideomodes: getcurrentvideosettings (devmode * devmode)
{
Hwnd hwnddesktop = getdomaintopwindow ();
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;
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
Obtained by using enumdisplaysettings.
If the setting is normal, the returned value is disp_change_successful.

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.