Lazarus

Programming => LCL => Topic started by: rpetges on September 26, 2021, 04:21:36 pm

Title: ClientHeight and Height return same size
Post by: rpetges on September 26, 2021, 04:21:36 pm
Hi,

I'm running Lazarus 2.0.12 on Windows 10 ( 100% DPI scaling ).

The Height property of a window should return the number of pixels, including title bar. However, during my tests, Height and ClientHeight return the same values. In fact, the titlebar height ( around 30 pixels ) is missing when using the Height property.

Any idea how to get the full height of a window ?

Many thanks.

   
Title: Re: ClientHeight and Height return same size
Post by: Bart on September 26, 2021, 09:21:26 pm
Read the FAQ (https://wiki.lazarus.freepascal.org/Lazarus_Faq#Why_are_TForm.ClientWidth.2FClientHeight_the_same_as_TForm.Width.2FHeight) please.

Bart
Title: Re: ClientHeight and Height return same size
Post by: rpetges on September 26, 2021, 09:26:15 pm
Aaaah, that explains. Thanks for the link.

While my application is only running on Windows, I will use ClientHeight and get the frame width and title bar height with the GetSystemMetrics function.
Title: Re: ClientHeight and Height return same size
Post by: jamie on September 27, 2021, 01:03:43 am
Please read this link
https://docs.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-getwindowrect

 Starting with vista the drop shadow is part of the window frame and the GetWindowRect will report that as part of the window size.

 Reading the link you can find out how to obtain the actual frame size you are seeing.

 Beware that if you expect your code to work in earlier OS versions Like i do, it's wise to dynamically link the procedure address in for this call at runtime and if it fails then you can use what ever the GetWindowRect returns..
Title: Re: ClientHeight and Height return same size
Post by: rpetges on September 27, 2021, 07:42:07 pm
Thanks for the info, I'll have a look.
Title: Re: ClientHeight and Height return same size
Post by: winni on September 27, 2021, 08:58:01 pm
Hi!

A plattform independent hack to get the height of the title bar is here:

https://forum.lazarus.freepascal.org/index.php/topic,54745.msg406887.html#msg406887 (https://forum.lazarus.freepascal.org/index.php/topic,54745.msg406887.html#msg406887)

Winni
Title: Re: ClientHeight and Height return same size
Post by: dsiders on September 27, 2021, 09:28:43 pm
Hi!

A plattform independent hack to get the height of the title bar is here:

https://forum.lazarus.freepascal.org/index.php/topic,54745.msg406887.html#msg406887 (https://forum.lazarus.freepascal.org/index.php/topic,54745.msg406887.html#msg406887)

Winni


Perhaps this routine could be added to the forms.pp (or appropriate) unit...
Title: Re: ClientHeight and Height return same size
Post by: robert rozee on September 29, 2021, 01:42:17 am
hi,
    the below is how i do it under linux mint 20.2. of interest in this case is that LBW gives you the width of the window's border, while TBH gives you the height of the window's top bar.

the width and height properties of Form1.Monitor.WorkAreaRect returns the usable screen area, ie, excluding the taskbar. in my case, i'm interested in the maximum window size that will still fit entirely on the monitor.


cheers,
rob   :-)


Code: Pascal  [Select][+][-]
  1. var maxW, maxH,                                                        // width and height when maximized
  2.        LBW,TBH:integer;                                                // left border width, top bar height
  3.          point:TPoint;                                                                                          
  4.  
  5.  
  6. begin
  7.   point.X:=Form1.Left;                                                 // left edge of Form1's left border, this is OUTSIDE of Form1's working area
  8.   point.Y:=Form1.Top;                                                  // top edge of Form1's title bar. again, this is OUTSIDE of Form1's working area
  9.  
  10.   LBW:=-Form1.ScreenToClient(point).X;                                 // ScreenToClient converts to (negative) left border width, sign changed so LBW is positive
  11.   TBH:=-Form1.ScreenToClient(point).Y;                                 // ScreenToClient converts to (negative) title bar height, sign changed so TBH is positive
  12.  
  13.   maxW:=Form1.Monitor.WorkAreaRect.Width-(LBW*2);                      // decrease width. ASSUMES Form1's right border is the same width as left border
  14.   maxH:=Form1.Monitor.WorkAreaRect.Height-(TBH+LBW);                   // decrease height. ASSUMES Form1's bottom border is the same width as left border
  15.                                                                        // note: WorkAreaRect ***excludes*** the taskbar    
  16.  
  17. end;
  18.  
TinyPortal © 2005-2018