Recent

Author Topic: Wrong resolution of second screen  (Read 404 times)

Apiglio

  • Newbie
  • Posts: 2
Wrong resolution of second screen
« on: December 05, 2024, 01:20:35 pm »
I'm using TScreen.Monitors to get resolution information of Desktop and find the size of Primary Screen is correct but not of the second.

Here is my code:
Code: Pascal  [Select][+][-]
  1.   for idx:=0{edited} to Screen.MonitorCount-1 do
  2.   begin
  3.     writeln(Format('Monitor %d:',[idx]));
  4.     writeln(Format('  PPI = %d', [Screen.Monitors[idx].PixelsPerInch]));
  5.     with Screen.Monitors[idx].BoundsRect do
  6.       writeln(Format('  Boundary: left = %d, top = %d, width = %d, height = %d', [Left, Top, Width, Height]));
  7.   end;
  8.  
Here is my screen setting:
Code: Text  [Select][+][-]
  1. +---+-------+
  2. |   |       |
  3. | 1 |   0   |
  4. |   |       |
  5. +---+-------+
  6. monitor 0:
  7.   Resolution: 2560 x 1440
  8.   Scaling:   150%
  9.  
  10. monitor 1:
  11.   Resolution: 900 x 1440
  12.   Scaling:   100%
  13.  
run the code and I got this:
Code: Pascal  [Select][+][-]
  1. Monitor 0:
  2.   PPI = 144
  3.   Boundary: left = 0, top = 0, width = 2560, height = 1440
  4. Monitor 1:
  5.   PPI = 144
  6.   Boundary: left = -1350, top = 0, width = 1350, height = 2160
  7.  

If I set the scaling of second screen to 150% (same as Primary Screen), everything would be all right. What is going on? Can I only use LCL and Windows unit to solve this problem?
« Last Edit: December 05, 2024, 03:16:51 pm by Apiglio »

rvk

  • Hero Member
  • *****
  • Posts: 6640
Re: Wrong resolution of second screen
« Reply #1 on: December 05, 2024, 02:12:01 pm »
Normally, an application is only DPI aware (for one monitor).
So there is only one DPI known, not multiple per monitor.

If you go into your project options, you can set the DPI awareness to "Per monitor" (True/PM).
After that... the DPI settings are per monitor and you get the expected result.

(BTW. You need to count idx from 0 to MonitorCount - 1. You counted from 1, not 0.
But in your result it was correct monitor 0 so I guess that was a copy error.)

Quote
Monitor 0:
  PPI = 96
  Boundary: left = 1920, top = 126, width = 1920, height = 1080
Monitor 1:
  PPI = 144
  Boundary: left = -1920, top = 129, width = 1920, height = 1080
Monitor 2:
  PPI = 96
  Boundary: left = 0, top = 0, width = 1920, height = 1200
« Last Edit: December 05, 2024, 02:14:43 pm by rvk »

Apiglio

  • Newbie
  • Posts: 2
Re: Wrong resolution of second screen
« Reply #2 on: December 05, 2024, 03:13:47 pm »
Thank you, @rvk. It works.

(BTW. You need to count idx from 0 to MonitorCount - 1. You counted from 1, not 0.
But in your result it was correct monitor 0 so I guess that was a copy error.)
Yes, that's awkward. I changed some code to make it brief.  :-[

 

TinyPortal © 2005-2018