Recent

Author Topic: ClientHeight and Height return same size  (Read 2623 times)

rpetges

  • Jr. Member
  • **
  • Posts: 57
    • Attribute Changer Website
ClientHeight and Height return same size
« 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.

   
« Last Edit: September 26, 2021, 04:30:38 pm by rpetges »

Bart

  • Hero Member
  • *****
  • Posts: 4477
    • Bart en Mariska's Webstek
Re: ClientHeight and Height return same size
« Reply #1 on: September 26, 2021, 09:21:26 pm »
Read the FAQ please.

Bart

rpetges

  • Jr. Member
  • **
  • Posts: 57
    • Attribute Changer Website
Re: ClientHeight and Height return same size
« Reply #2 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.
« Last Edit: September 27, 2021, 07:42:47 pm by rpetges »

jamie

  • Hero Member
  • *****
  • Posts: 4928
Re: ClientHeight and Height return same size
« Reply #3 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..
The only true wisdom is knowing you know nothing

rpetges

  • Jr. Member
  • **
  • Posts: 57
    • Attribute Changer Website
Re: ClientHeight and Height return same size
« Reply #4 on: September 27, 2021, 07:42:07 pm »
Thanks for the info, I'll have a look.

winni

  • Hero Member
  • *****
  • Posts: 2715
Re: ClientHeight and Height return same size
« Reply #5 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


Winni

dsiders

  • Hero Member
  • *****
  • Posts: 520
Re: ClientHeight and Height return same size
« Reply #6 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


Winni


Perhaps this routine could be added to the forms.pp (or appropriate) unit...
Lazarus 2.0.12, 2.2.0-RC1, 2.3.0 (Git) / FPC 3.2.0, 3.2.2 / x86-win64 / Windows 8.1

robert rozee

  • New Member
  • *
  • Posts: 35
Re: ClientHeight and Height return same size
« Reply #7 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.  
« Last Edit: September 29, 2021, 07:54:11 am by robert rozee »

 

TinyPortal © 2005-2018