Lazarus

Programming => General => Topic started by: pcurtis on July 10, 2020, 06:09:04 pm

Title: Title bar thickness
Post by: pcurtis on July 10, 2020, 06:09:04 pm
Hi All,

How do I get the forms title bar thickness?

Thanks in advance.
Title: Re: Title bar thickness
Post by: RAW 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
Title: Re: Title bar thickness
Post by: pcurtis on July 10, 2020, 06:27:30 pm
W10
Title: Re: Title bar thickness
Post by: RAW 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
Title: Re: Title bar thickness
Post by: pcurtis 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  :(
Title: Re: Title bar thickness
Post by: winni 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
Title: Re: Title bar thickness
Post by: Warfley 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
Title: Re: Title bar thickness
Post by: winni 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
Title: Re: Title bar thickness
Post by: Warfley 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)
Title: Re: Title bar thickness
Post by: RAW on July 10, 2020, 09:47:43 pm
Result is 21 px .... exactly like the WINAPI ...  :)
Title: Re: Title bar thickness
Post by: winni 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