Lazarus

Programming => General => Topic started by: AlphaInc. on April 15, 2021, 07:33:58 pm

Title: Lazarus Detect DPI Scalling Level of Windows [SOLVED]
Post by: AlphaInc. 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.
Title: Re: Lazarus Detect DPI Scalling Level of Windows
Post by: sstvmaster on April 15, 2021, 07:55:24 pm
Maybe like so?
Code: Pascal  [Select][+][-]
  1. Screen.PixelsPerInch
Title: Re: Lazarus Detect DPI Scalling Level of Windows
Post by: wp 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%.
Title: Re: Lazarus Detect DPI Scalling Level of Windows
Post by: AlphaInc. 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%
Title: Re: Lazarus Detect DPI Scalling Level of Windows
Post by: AlphaInc. 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.
Title: Re: Lazarus Detect DPI Scalling Level of Windows
Post by: dseligo 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));
Title: Re: Lazarus Detect DPI Scalling Level of Windows
Post by: AlphaInc. 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.  :)
Title: Re: Lazarus Detect DPI Scalling Level of Windows [SOLVED]
Post by: sstvmaster on April 15, 2021, 11:13:43 pm
You are welcome.  :)
TinyPortal © 2005-2018