How to set the screen resolution programmatically

Spread the love

// How to set the screen resolution.

procedure SetResolution(XRes, YRes: DWord);
var
   lpDevMode : TDeviceMode;
begin
     EnumDisplaySettings(nil, 0, lpDevMode);

     lpDevMode.dmFields := DM_PELSWIDTH or DM_PELSHEIGHT;
     lpDevMode.dmPelsWidth := XRes;
     lpDevMode.dmPelsHeight := YRes;

     ChangeDisplaySettings(lpDevMode, 0);
end;