Page 1 of 1
Forum

Welcome to the Tweaking4All community forums!
When participating, please keep the Forum Rules in mind!

Topics for particular software or systems: Start your topic link with the name of the application or system.
For example “MacOS X – Your question“, or “MS Word – Your Tip or Trick“.

Please note that switching to another language when reading a post will not bring you to the same post, in Dutch, as there is no translation for that post!




Share:
Notifications
Clear all

Lazarus Pascal - Determine titlebar height crossplatform quick and easy

1 Posts
1 Users
0 Likes
154 Views
 Hans
(@hans)
Famed Member Admin
Joined: 10 years ago
Posts: 2547
Topic starter  

Seems hard to determine the height of the titlebar/caption of a form.
I've seen some calls that are Windows specific only, and some tricks that maximize the form to determine the size (flicker), or system calls that simply do not work on all platforms.

So after tinkering with that issue for a bit, I figured; why not use the "translation" of a pixel on a form to its location on the screen and determine how much it's off? (a.k.a. the titlebar height)

Tested this under Windows (11), macOS (Monterey and Sonoma), GTK2 and QT5 ... and it just works ...

function DetermineTitlebarHeight(aForm:Tform):integer;
var
  global_pos : TPoint;
begin
  global_pos := aForm.ClientToScreen(Point (1,1));
  Result     := global_pos.Y - aForm.Top;
end;

I've tested this at onFormPaint and onFormChangeBounds, and even when changing themes (Linux) it adapts.

For testing I've added a little project that has 2 units, where the 2nd unit stays aligned to the bottom of the first unit.


   
ReplyQuote

Like what you see and you'd like to help out? 

The best way to help is of course by assisting others with their questions here in the forum, but you can also help us out in other ways:

- Do your shopping at Amazon, it will not cost you anything extra but may generate a small commission for us,
- send a cup of coffee through PayPal ($5, $10, $20, or custom amount),
- become a Patreon,
- donate BitCoin (BTC), or BitCoinCash (BCH).

Share: