Author: Ernesto De Spirito
How can I change the screen resolution?
Answer:
To change the screen resolution you can use the following function which is a
wrapper for the Windows API ChangeDisplaySettings. The function takes the desired
width and height as parameters and returns
the return value of ChangeDisplaySettings (see the documentation for more datails).
1 2 function SetScreenResolution(Width, Height: integer): Longint;
3 var4 DeviceMode: TDeviceMode;
5 begin6 with DeviceMode do7 begin8 dmSize := SizeOf(TDeviceMode);
9 dmPelsWidth := Width;
10 dmPelsHeight := Height;
11 dmFields := DM_PELSWIDTH or DM_PELSHEIGHT;
12 end;
13 Result := ChangeDisplaySettings(DeviceMode, CDS_UPDATEREGISTRY);
14 end;
You can use ChangeDisplaySettings to change other properties of the display like
the color depth and the display frequency.
Sample call
In the following example first we get the current screen resolution before setting
it to 800x600, and then we restore it calling SetScreenResolution again.
15 var16 OldWidth, OldHeight: integer;
17 18 procedure TForm1.Button1Click(Sender: TObject);
19 begin20 OldWidth := GetSystemMetrics(SM_CXSCREEN);
21 OldHeight := GetSystemMetrics(SM_CYSCREEN);
22 SetScreenResolution(800, 600);
23 end;
24 25 procedure TForm1.Button2Click(Sender: TObject);
26 begin27 SetScreenResolution(OldWidth, OldHeight);
28 end;
Copyright (c) 2001 Ernesto De Spiritomailto:edspirito@latiumsoftware.com
Visit: http://www.latiumsoftware.com/delphi-newsletter.php