Delphi implementation dynamically modifies display resolution

Source: Internet
Author: User

This example shows how to dynamically modify the resolution of the screen in a program, and it takes effect without restarting the computer.

Add two button controls to the form, and the finished main interface is shown in Figure 1.

Figure 1 Main interface

Add a custom function dynamicresolution to the program, which has two parameters, corresponding to the horizontal and vertical resolution, and the function has a bool-type return value that can be judged by the return value to determine whether the Dynamicresolution function is properly executed. The Dynamicresolution function code is as follows:

function TfrmMain.DynamicResolution(X, Y: word): BOOL;
 var
  lpDevMode: TDeviceMode;
 begin
  Result := EnumDisplaySettings(nil, 0, lpDevMode);
  if Result then
  begin
   lpDevMode.dmFields := DM_PELSWIDTH Or DM_PELSHEIGHT;
   lpDevMode.dmPelsWidth := X;
   lpDevMode.dmPelsHeight := Y;
   Result:=ChangeDisplaySettings(lpDevMode,0)= DISP_CHANGE_SUCCESSFUL;
  end;
 end;

While the program is running, call Dynamicresolution (640,480) or dynamicresolution (800,600) to modify the resolution by clicking the two buttons "640*480" and "800*600" on the form.

The program first obtains the current screen resolution by enumdisplaysettings, stores it in the variable lpdevmode, and then sets the Lpdevmode to the new resolution. Finally, through the ChangeDisplaySettings function to complete the dynamic modification of the display resolution of the specific operation.

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.