Search code examples
winapifiremonkeydelphi-10.1-berlin

Is it possible to retrieve the font scaling in Windows?


Trying to change dimensions of my FMX form to emulate a 'FullScreen' mode, but using the Screen size backfires when a user has its settings with some bigger scaling, since the whole form becomes bigger than the screen.

How can I retrieve the scaling value so I can Size the form accordingly?

EDIT: That's a little snippet that shows what was my intention with the question and how it was solved. Thank you for you time and help.

 procedure TMyForm.ApplyFullScreen;
var
  tmpEscale: Extended;
begin
  BorderStyle := TFmxFormBorderStyle.None;
  Left := 0;
  Top := 0;

  tmpEscala := USER_DEFAULT_SCREEN_DPI / GetDeviceCaps(GetDC(0), LOGPIXELSX);

  Height := Round(Screen.Height * tmpEscala);
  Width := Round(Screen.Width * tmpEscala);
end;

Solution

  • When you call EnumDisplaySettings the resulting DEVMODE structure contains the DPI setting in the dmYResolution field. Beware that passing NULL as the device name to EnumDisplaySettings will get the information only for one screen, on a multimonitor system you should enumerate all the display devices.

    You can also call GetDeviceCaps on a device context, and query for LOGPIXELSX and LOGPIXELSY.

    The DPI corresponds to font scaling as follows:

    • 100% = 96 dpi
    • 125% = 120 dpi
    • 150% = 144 dpi
    • 200% = 192 dpi

    For more information, it would be good to refer to the MSDN article on DPI-related APIs