` Printed Icetips Article

Icetips Article



Windows API: Change or detect screen resolution (1)
2003-01-26 -- Arnor Baldvinsson
 
Newsgroups: comp.lang.clarion

Hi Chris,

On Sat, 25 Jan 2003 17:47:32 -0600, "Chris Bordeman"
 wrote:

>My app requires 1024x768, how can I change the screen resolution at app
>startup?  Or at least detect it so I can tell the user to fix it, maybe even
>pop up the appropriate dialog?

You can use the GetSystemMetrics api to get the current resolution:

W = GetSystemMetrics(SM_CXSCREEN)
H = GetSystemMetrics(SM_CYSCREEN)

To change it, look at the ChangeDisplaySettings api.  You can download
some Delphi code from:

http://www.planet-source-code.com/vb/scripts/ShowCode.asp?txtCodeId=478&lngWId=7

The main function that does the resizing looks like this:

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

Looks fairly simple to me if you have the structures and equates.  Let
me know if you need any more help with this (haven't used it myself,
but it looks fairly simple)

Best regards,

ArnĂ³r Baldvinsson



Printed May 4, 2024, 7:02 pm
This article has been viewed/printed 35117 times.
Google search has resulted in 239 hits on this article since January 25, 2004.