Recent

Author Topic: Lazarus Detect DPI Scalling Level of Windows [SOLVED]  (Read 490 times)

AlphaInc.

  • Jr. Member
  • **
  • Posts: 93
Lazarus Detect DPI Scalling Level of Windows [SOLVED]
« on: April 15, 2021, 07:33:58 pm »
Hello everybody,

I recently opened a thread asking how you could scale the tool's window proportional to the resolution of the client (windows). I was pointed to an external component TFormResizer (EasySize) with which I could resize the image based on the resolution. All the components on my form (Buttons) did also resize.

Now I wanted to expand on that a little by also detecting the zoom (don't know if it's called DPI Scalling, in windows settings it's called "change the size of text apps and other items") and setting a secreen resolution based on that.

My code so far:

Code: Pascal  [Select][+][-]
  1. procedure TForm1.FormCreate(Sender: TObject);
  2. begin
  3.    Sizer := TFormResizer.Create(self);
  4.    Sizer.EnforceMinSize := false;
  5.    Sizer.ResizeFonts := true;
  6.    Sizer.MinFontSize := 6;
  7.    Sizer.MaxFontSize := 30;
  8.    Sizer.InitializeForm;
  9.  
  10.    Width := round(Screen.Width/2.4);
  11.    Height := round(Screen.Height/2.4);
  12.  
  13.    Position := poScreenCenter;
  14. end;

I want to change the code to something like this.

Code: Pascal  [Select][+][-]
  1.    if Zoom=100% then
  2.       begin
  3.          Width := round(Screen.Width/2.4);
  4.          Height := round(Screen.Height/2.4);
  5.       end;
  6.    else if Zoom=125% then
  7.       begin
  8.          Width := round(Screen.Width/2.8);
  9.          Height := round(Screen.Height/2.8);
  10.       end;
  11.    ...

The only problem I have is that I don't know how to detect the Zoom-factor.
« Last Edit: April 15, 2021, 09:57:13 pm by AlphaInc. »

sstvmaster

  • Full Member
  • ***
  • Posts: 246
Re: Lazarus Detect DPI Scalling Level of Windows
« Reply #1 on: April 15, 2021, 07:55:24 pm »
Maybe like so?
Code: Pascal  [Select][+][-]
  1. Screen.PixelsPerInch
Windows 10 (64 bit)
Lazarus: 2.0.12 / Trunk x32

wp

  • Hero Member
  • *****
  • Posts: 8347
Re: Lazarus Detect DPI Scalling Level of Windows
« Reply #2 on: April 15, 2021, 08:01:26 pm »
LCL does not support zooming. So your zoom factor is fully under your own control. I'd say that your design machine defines what is 100%.
Mainly Lazarus trunk / fpc 3.2.0 / all 32-bit on Win-10, but many more...

AlphaInc.

  • Jr. Member
  • **
  • Posts: 93
Re: Lazarus Detect DPI Scalling Level of Windows
« Reply #3 on: April 15, 2021, 08:32:29 pm »
Maybe like so?
Code: Pascal  [Select][+][-]
  1. Screen.PixelsPerInch

So how to check for DPI Scaling 100%?
Code: Pascal  [Select][+][-]
  1. If Screen.PixelsPerInch := 100
or
Code: Pascal  [Select][+][-]
  1. If Screen.PixelsPerInch := 1
or how do you set 100%

AlphaInc.

  • Jr. Member
  • **
  • Posts: 93
Re: Lazarus Detect DPI Scalling Level of Windows
« Reply #4 on: April 15, 2021, 08:35:04 pm »
LCL does not support zooming. So your zoom factor is fully under your own control. I'd say that your design machine defines what is 100%.

Not sure if we are talking about the same (if yes and I didn't understand you correctly, excuse me) but I don't want to zoom the software I just want to read (or better import the value as an integer) the defined zoom in windows settings to use it in my tool.

dseligo

  • Sr. Member
  • ****
  • Posts: 275
Re: Lazarus Detect DPI Scalling Level of Windows
« Reply #5 on: April 15, 2021, 09:10:00 pm »
Maybe like so?
Code: Pascal  [Select][+][-]
  1. Screen.PixelsPerInch

So how to check for DPI Scaling 100%?
Code: Pascal  [Select][+][-]
  1. If Screen.PixelsPerInch := 100
or
Code: Pascal  [Select][+][-]
  1. If Screen.PixelsPerInch := 1
or how do you set 100%

Put you Windows DPI to 100% and then check result:
Code: Pascal  [Select][+][-]
  1. ShowMessage(IntToStr(Screen.PixelsPerInch));

AlphaInc.

  • Jr. Member
  • **
  • Posts: 93
Re: Lazarus Detect DPI Scalling Level of Windows
« Reply #6 on: April 15, 2021, 09:56:48 pm »
Maybe like so?
Code: Pascal  [Select][+][-]
  1. Screen.PixelsPerInch

So how to check for DPI Scaling 100%?
Code: Pascal  [Select][+][-]
  1. If Screen.PixelsPerInch := 100
or
Code: Pascal  [Select][+][-]
  1. If Screen.PixelsPerInch := 1
or how do you set 100%

Put you Windows DPI to 100% and then check result:
Code: Pascal  [Select][+][-]
  1. ShowMessage(IntToStr(Screen.PixelsPerInch));

Ahh Thank you. It got it.  :)

sstvmaster

  • Full Member
  • ***
  • Posts: 246
Re: Lazarus Detect DPI Scalling Level of Windows [SOLVED]
« Reply #7 on: April 15, 2021, 11:13:43 pm »
You are welcome.  :)
Windows 10 (64 bit)
Lazarus: 2.0.12 / Trunk x32

 

TinyPortal © 2005-2018