Watch, Follow, &
Connect with Us

For forums, blogs and more please visit our
Developer Tools Community.


Welcome, Guest
Guest Settings
Help

Thread: Read Windows scaling


This question is answered. Helpful answers available: 0. Correct answers available: 1.


Permlink Replies: 6 - Last Post: Mar 19, 2017 1:13 AM Last Post By: Andrea Kaiser
Andrea Kaiser

Posts: 63
Registered: 11/17/15
Read Windows scaling  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Mar 16, 2017 1:17 AM
How can I read the value of the windows scaling in my Delphi application?

- Display properties
- Size of text...

Usual values are 100%, 125%, 150%.
Douglas Rudd

Posts: 314
Registered: 5/16/97
Re: Read Windows scaling
Helpful
Click to report abuse...   Click to reply to this thread Reply
  Posted: Mar 16, 2017 9:01 AM   in response to: Andrea Kaiser in response to: Andrea Kaiser
You can get the screen scaling like this:
screen_scaling:= Screen.PixelsPerInch / 96;


But this will only give the right answer if you have "Enable High-DPI" checked in your project options.
Otherwise, PixelsPerInch always returns 96.
Andrea Kaiser

Posts: 63
Registered: 11/17/15
Re: Read Windows scaling  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Mar 16, 2017 9:29 AM   in response to: Douglas Rudd in response to: Douglas Rudd
Douglas Rudd wrote:
You can get the screen scaling like this:
screen_scaling:= Screen.PixelsPerInch / 96;


But this will only give the right answer if you have "Enable High-DPI" checked in your project options.
Otherwise, PixelsPerInch always returns 96.

That's what I tried:
- Project options
- Application
- [x] Enable High-DPI

I set my screen to 100%:
- Display settings
- Move scroller to 100%
Result: Screen.PixelsPerInch = 96

Then I set my screen to 150%:
- Display settings
- Move scroller to 150%
Result: Screen.PixelsPerInch = still 96

What am I doing wrong?

Douglas Rudd

Posts: 314
Registered: 5/16/97
Re: Read Windows scaling  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Mar 16, 2017 9:09 PM   in response to: Andrea Kaiser in response to: Andrea Kaiser
- Move scroller to 150%
Result: Screen.PixelsPerInch = still 96

Hmm. What version of Delphi are you using? I tried it on Seattle and Berlin and it worked. I changed the slider to different sizes and it changed PixelsPerInch.

Is this on a new minimal app?
Andrea Kaiser

Posts: 63
Registered: 11/17/15
Re: Read Windows scaling  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Mar 17, 2017 1:16 AM   in response to: Douglas Rudd in response to: Douglas Rudd
Douglas Rudd wrote:
- Move scroller to 150%
Result: Screen.PixelsPerInch = still 96

Hmm. What version of Delphi are you using? I tried it on Seattle and Berlin and it worked. I changed the slider to different sizes and it changed PixelsPerInch.

Is this on a new minimal app?

Delphi Berlin, standard VCL application.

But I noticed something. When I just close the app, change the Windows scaling and start the app again, Screen.PixelsPerInch remains the same. However, when I reboot the computer, the value changes (to 144 at 150%).

Do you have to reboot or log off, as well?
Douglas Rudd

Posts: 314
Registered: 5/16/97
Re: Read Windows scaling
Helpful
Click to report abuse...   Click to reply to this thread Reply
  Posted: Mar 17, 2017 11:29 AM   in response to: Andrea Kaiser in response to: Andrea Kaiser
Yes,I did.

But there is a form event, that gives the new dpi when the setting changes without loging out. (at least in Windows 10)
The OnAfterMonitorDPIChanged, OnBeforeMonitorDPIChanged events
procedure TForm49.FormAfterMonitorDpiChanged(Sender: TObject; OldDPI,NewDPI: Integer);
begin
   showmessage(inttostr(NewDPI));
end;
Andrea Kaiser

Posts: 63
Registered: 11/17/15
Re: Read Windows scaling  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Mar 19, 2017 1:13 AM   in response to: Douglas Rudd in response to: Douglas Rudd
Douglas Rudd wrote:
Yes,I did.

But there is a form event, that gives the new dpi when the setting changes without loging out. (at least in Windows 10)
The OnAfterMonitorDPIChanged, OnBeforeMonitorDPIChanged events
procedure TForm49.FormAfterMonitorDpiChanged(Sender: TObject; OldDPI,NewDPI: Integer);
begin
   showmessage(inttostr(NewDPI));
end;

Thank you very much, Douglas!
Legend
Helpful Answer (5 pts)
Correct Answer (10 pts)

Server Response from: ETNAJIVE02