Using VC to realize dynamic change of Windows display characteristics

Source: Internet
Author: User
Tags modify valid

For Windows platform, display resolution, color number, refresh rate and other characteristics are important, especially for multimedia applications and game software. In many cases, the user's current screen settings are not suitable for the software's running needs, the software is usually to prompt the user to set the screen to the software required resolution and color number, and then restart the software. This will undoubtedly increase the average user's operating burden and difficulty, reducing the software's friendliness and ease of use. The ideal approach is to change the screen settings dynamically at the beginning of the software to meet the requirements of software operation. After the software is run, the screen settings are automatically changed back to the original set values. All these processes are done unconsciously. This example shows the dynamic setting of the system display resolution, as long as the system's hardware support, you can set the resolutions to 1024*768 or 800*600; the color is set to 8 bits, 24 bits, 32 bits, etc. The interface effect after compiling the program is as shown in Figure one:

Figure I, set the system resolution of the Program Interface effect diagram

First, the programming method

We know that the display of the display corresponds to video memory, the smallest unit on the monitor is the pixel (Pixel, which considers only logical pixels), and the smallest unit of memory is bits (bits). The characteristics of display work are mainly reflected in color number and resolution. The number of colors displayed by the monitor depends on the number of bits (bits) of video memory used in the unit pixel. In the memory, if the 8-bit video memory (that is, a byte of memory used to pixels) corresponds to a pixel on the monitor, the number of colors displayed by the monitor is 28=256; Similarly, if the current color is 16 bits, the display displays a number of colors of 216 = 65536 colors. The resolution of the monitor refers to the horizontal resolution and the vertical resolution, often referred to 800x600, refers to the level of the pixel shown 800, in the vertical aspect of the pixel is 600.

In VC provides a modified display device (such as monitors, printers, etc., this article only on the display) properties of the function changedisplaysettings (), the function can according to your needs for the display device to make the appropriate changes. The prototype of the function is: LONG changedisplaysettings (Lpdevmode lpdevmode, DWORD dwflags), and its parameters have the following meanings:

Lpdevmode: A pointer to the DEVMODE data structure, the DEVMODE data structure describes the values of the various properties of the display. The member variables that are typically used are:

Dmsize: The size of the DEVMODE data structure used (in bytes);

Dmbitsperpel: The number of memory bits (bits) used per pixel;

Dmpelswidth: Horizontal resolution (dots);

Dmpelsheight Pixel Height: Vertical resolution (dots);

Dmdisplayfrequency: Display refresh rate, in Hertz;

Dmfields: In general, different display devices (such as printers) use the DEVMODE data structure of different content, such as setting a printer, you do not use the Dmdisplayfrequency attribute. Therefore, when you use the DEVMODE data structure, you should explain to the system you specifically use the effective data members, Dmfields is the use of this. If only dmpelswidth (horizontal resolution) and dmpelsheight (vertical resolution) are used in the program, the value should be dm_pelswidth| Dm_pelsheight.

dwflags: Indicates how the display device is modified. The specific values are as follows: 0: Dynamic change display device properties; Cds_updateregistry: Dynamically changing the display device properties and modifying registry settings, the next time you start your computer, the changes are still valid; Cds_test: Test whether the changes are valid.

The return value after the above function call is as follows: Disp_change_successful: Modified successfully; Disp_change_restart: Reboot after modification (select "Restart computer before applying new color" in monitor settings); Disp_change_ FAILED: Modify failed; Disp_change_badmode: Modify mode error (for example, your monitor is monochrome, but you modify it to 256 colors). If the parameter lpdevmode is null when the function is called and the dwflags is 0, the display device uses the registry current value to set the display attribute. These are the most common uses of the changedisplaysettings () function, which are described in more detail in MSDN.

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.