Recent

Author Topic: Title bar thickness  (Read 1404 times)

pcurtis

  • Hero Member
  • *****
  • Posts: 951
Title bar thickness
« on: July 10, 2020, 06:09:04 pm »
Hi All,

How do I get the forms title bar thickness?

Thanks in advance.
Windows 10 20H2
Laz 2.2.0
FPC 3.2.2

RAW

  • Hero Member
  • *****
  • Posts: 868
Re: Title bar thickness
« Reply #1 on: July 10, 2020, 06:23:36 pm »
That depends on the OS or widgetset I guess ...
For Windows I have seen an example from GETMEM ... anywhere ...  :)

Maybe this is a starting point ...

https://wiki.lazarus.freepascal.org/GetSystemMetrics/de
https://docs.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-getsystemmetrics
« Last Edit: July 10, 2020, 06:29:38 pm by RAW »
Windows 7 Pro (x64 Sp1) & Windows XP Pro (x86 Sp3).

pcurtis

  • Hero Member
  • *****
  • Posts: 951
Re: Title bar thickness
« Reply #2 on: July 10, 2020, 06:27:30 pm »
W10
Windows 10 20H2
Laz 2.2.0
FPC 3.2.2

RAW

  • Hero Member
  • *****
  • Posts: 868
Re: Title bar thickness
« Reply #3 on: July 10, 2020, 06:48:11 pm »
How about this ??

Code: Pascal  [Select][+][-]
  1. procedure TForm1.Button1Click(Sender: TObject);
  2. begin
  3.   ShowMessage(IntToStr(GetSystemMetrics(SM_CYMENU)));
  4. end;

On my system this seems to be correct ... 21 px .. never used it ... seems to be the same as SM_CYCAPTION ... also 21 px
« Last Edit: July 10, 2020, 06:53:40 pm by RAW »
Windows 7 Pro (x64 Sp1) & Windows XP Pro (x86 Sp3).

pcurtis

  • Hero Member
  • *****
  • Posts: 951
Re: Title bar thickness
« Reply #4 on: July 10, 2020, 08:09:34 pm »
I found this on the net

Quote
In unthemed Windows, GetSystemMetrics(SM_CYCAPTION) is the height of the text in the title bar; you need to add in the size of the frame and border padding (GetSystemMetrics(SM_CYSIZEFRAME) + GetSystemMetrics(SM_CYEDGE) * 2).

For themed Windows (which is the default these days), GetThemeSysSize is most likely the function you're looking for; in particular, GetThemeSysSize(SM_CXBORDER) for the border width, and GetThemeSysSize(SM_CYSIZE) + GetThemeSysSize(SM_CXPADDEDBORDER) * 2 for the title bar.

But it's still not quite right  :(
Windows 10 20H2
Laz 2.2.0
FPC 3.2.2

winni

  • Hero Member
  • *****
  • Posts: 3197
Re: Title bar thickness
« Reply #5 on: July 10, 2020, 08:35:49 pm »
Hi!

As everybody told me, there is no way to get the titlebarheight in Linux, I found out how to do.

Perhaps that works also with Windows which can save a lot of Windows Messages and Metrics.

Code: Pascal  [Select][+][-]
  1.  function TitleBarHeight (Form: TForm) : Integer;
  2. var ws : TWindowState;
  3.     oldheight : integer;
  4.     count : integer = 0;
  5. begin
  6. ws := Form.WindowState;
  7. if ws <> wsMaximized then
  8.   begin
  9.    oldHeight := Form.Height;
  10.    Form.WindowState := wsMaximized;
  11.    repeat
  12.    Application.ProcessMessages; // let Form expand
  13.    inc (Count);
  14.    until (Form.Height<>oldHeight) or (count >= 3);//but one ProcessMessages may be not eough!
  15.    end;
  16. result := Form.Monitor.WorkAreaRect.Height -Form.Height;
  17. if ws <> wsMaximized then
  18.   begin
  19.   Form.WindowState := ws; // and back again
  20.   Application.ProcessMessages;
  21.   end;
  22. end;                  

Give some flicker - but you got the titlebarheight.

Winni

Warfley

  • Hero Member
  • *****
  • Posts: 1499
Re: Title bar thickness
« Reply #6 on: July 10, 2020, 08:42:06 pm »
Give some flicker - but you got the titlebarheight.

Winni

Couldn't this then be simply done by using a new form, give it an alpha value of 0 and doing all the stuff with it? this would at least not be visible.


Also, while not being a big problem, you should also consider than in linux one can change the style easily during runtime, meaning the size during one moment might not be the same size at another time

winni

  • Hero Member
  • *****
  • Posts: 3197
Re: Title bar thickness
« Reply #7 on: July 10, 2020, 09:25:36 pm »

Also, while not being a big problem, you should also consider than in linux one can change the style easily during runtime, meaning the size during one moment might not be the same size at another time

Allready done. Look into the code.

Winni

Warfley

  • Hero Member
  • *****
  • Posts: 1499
Re: Title bar thickness
« Reply #8 on: July 10, 2020, 09:45:04 pm »
Allready done. Look into the code.

Winni
Sure, I meant that in general, that you can't just call this function once on startup and expect the value to be constant. You need to call that function every time this is needed (probably can be cashed and only recalculated if WorkAreaRect.Height changed)

RAW

  • Hero Member
  • *****
  • Posts: 868
Re: Title bar thickness
« Reply #9 on: July 10, 2020, 09:47:43 pm »
Result is 21 px .... exactly like the WINAPI ...  :)
Windows 7 Pro (x64 Sp1) & Windows XP Pro (x86 Sp3).

winni

  • Hero Member
  • *****
  • Posts: 3197
Re: Title bar thickness
« Reply #10 on: July 10, 2020, 09:53:02 pm »
Result is 21 px .... exactly like the WINAPI ...  :)

Thanks!

Nice. Don'tneed to start old rusty Windows.

Winni

 

TinyPortal © 2005-2018