Recent

Author Topic: Screen size  (Read 3038 times)

Borneq

  • Full Member
  • ***
  • Posts: 248
Screen size
« on: January 21, 2020, 10:07:53 pm »
How to read screen resoution , for example 1920x1080?
How to detect second monitor?
Is possible detect physical monitor size? Probably it is possible, bacause ubuntu program Xreader (called fom textWorks) show me pdf at 100% exactly equal printed page.
« Last Edit: January 21, 2020, 10:10:41 pm by Borneq »

syntonica

  • Full Member
  • ***
  • Posts: 120
Re: Screen size
« Reply #1 on: January 21, 2020, 10:29:20 pm »
It's not pretty. You have to be able to query the monitor hardware since every monitor has a different physical DPI. Start here:

https://wiki.lazarus.freepascal.org/High_DPI

You should be able to use one of those hooks to get the ratios you need.

Ñuño_Martínez

  • Hero Member
  • *****
  • Posts: 1186
    • Burdjia
Re: Screen size
« Reply #2 on: January 21, 2020, 10:49:50 pm »
Use the Screen object.
Are you interested in game programming? Join the Pascal Game Development community!
Also visit the Game Development Portal

howardpc

  • Hero Member
  • *****
  • Posts: 4144
Re: Screen size
« Reply #3 on: January 21, 2020, 11:01:34 pm »
Every Lazarus form has a Monitor property which has Height, Width and PixelsPerInch properties.

Ñuño_Martínez

  • Hero Member
  • *****
  • Posts: 1186
    • Burdjia
Re: Screen size
« Reply #4 on: January 22, 2020, 11:49:29 am »
Every Lazarus form has a Monitor property which has Height, Width and PixelsPerInch properties.
Yes, TForm.Monitor references the monitor where the form is created (not sure if it changes if you drag the window to another monitor). The Screen object has a list with all available monitors.
Are you interested in game programming? Join the Pascal Game Development community!
Also visit the Game Development Portal

BeniBela

  • Hero Member
  • *****
  • Posts: 905
    • homepage
Re: Screen size
« Reply #5 on: January 22, 2020, 11:55:43 am »
I use this to get the usable screen size:

Code: Pascal  [Select][+][-]
  1. var workarea: TRect;
  2.   mon: TMonitor;
  3. begin
  4.   //see MoveToDefaultPosition
  5.   workarea := default(TRect);
  6.   if Application.MainForm <> nil then mon := Application.MainForm.Monitor
  7.   else mon := Monitor;
  8.   if mon <> nil then workarea := mon.WorkareaRect;
  9.   if (workarea.Width <= 0) or (workarea.Height <= 0) then workarea := screen.WorkAreaRect;
  10.   if (workarea.Width <= 0) or (workarea.Height <= 0) then workarea := screen.DesktopRect;
  11.   if ((workarea.Width <= 0) or (workarea.Height <= 0)) and (mon <> nil) then workarea := mon.BoundsRect;
  12.   if (workarea.Width <= 0) or (workarea.Height <= 0) then begin
  13.     workarea.Width := screen.Width;
  14.     workarea.Height := screen.Height;
  15.   end;

 

TinyPortal © 2005-2018