Vb, Delphi, .net, framework, C++, Java, Pascal,Visual Studio, Asm, Ruby, C#, j#, Cs, Html, Php, Perl, Asp, xHtml Get Free Souce Code Here...

Changing the screen resolution - Delphi

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).

  function SetScreenResolution(Width, Height: integer): Longint;
    DeviceMode: TDeviceMode;
    with DeviceMode do begin
      dmSize := SizeOf(TDeviceMode);
      dmPelsWidth := Width;
      dmPelsHeight := Height;
      dmFields := DM_PELSWIDTH or DM_PELSHEIGHT;
    Result := ChangeDisplaySettings(DeviceMode, CDS_UPDATEREGISTRY);

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.

    OldWidth, OldHeight: integer;

  procedure TForm1.Button1Click(Sender: TObject);
    OldWidth := GetSystemMetrics(SM_CXSCREEN);
    OldHeight := GetSystemMetrics(SM_CYSCREEN);
    SetScreenResolution(800, 600);

  procedure TForm1.Button2Click(Sender: TObject);
    SetScreenResolution(OldWidth, OldHeight);


Post a Comment