Page 1 of 1

GetWindowTitleHeight()

Posted: Sun May 30, 2021 1:19 pm
by Olli
This returns the height (in pixels) of any window title bars.

Code: Select all

Procedure.I GetWindowTitleHeight()

  Define void.I = OpenWindow(#PB_Any, 0, 0, 1, 1, "", #PB_Window_Invisible | #PB_Window_Maximize)
  Define result.I = WindowY(void, #PB_Window_InnerCoordinate)
  CloseWindow(void)
  ProcedureReturn result
  
EndProcedure

Re: GetWindowTitleHeight()

Posted: Sun May 30, 2021 2:05 pm
by Mijikai
I think this also works:

Code: Select all

EnableExplicit

Macro WindowTitleHeight(_window_)
  (WindowY(_window_,#PB_Window_InnerCoordinate) - WindowY(_window_,#PB_Window_FrameCoordinate))
EndMacro

Procedure.i Main()
  If OpenWindow(0,0,0,320,200,#Null$,#PB_Window_SystemMenu|#PB_Window_ScreenCentered|#PB_Window_MinimizeGadget)
    Debug WindowTitleHeight(0)
    Repeat
      Select WaitWindowEvent()
        Case #PB_Event_CloseWindow
          Break
      EndSelect
    ForEver
    CloseWindow(0)  
  EndIf  
  ProcedureReturn #Null
EndProcedure

Main()

End

Re: GetWindowTitleHeight()

Posted: Sun May 30, 2021 6:25 pm
by Olli
I think too, this does it too !

Edit : no ! You have the top border which is included in your version. It's a problem !

Re: GetWindowTitleHeight()

Posted: Sun May 30, 2021 6:49 pm
by Mijikai
Olli wrote: Sun May 30, 2021 6:25 pm You have the top border which is included in your version. It's a problem !
Ah ok, without the top border it would look like this:

Code: Select all

Procedure.i WindowTitleHeight(Window.i)
  Protected top.i
  Protected border.i
  top = WindowHeight(Window,#PB_Window_FrameCoordinate) - WindowHeight(Window,#PB_Window_InnerCoordinate)
  border = top - (WindowY(Window,#PB_Window_InnerCoordinate) - WindowY(Window,#PB_Window_FrameCoordinate))
  ProcedureReturn top - (border * 2)
EndProcedure

Re: GetWindowTitleHeight()

Posted: Sun May 30, 2021 8:17 pm
by Olli
It's right ! But a few more complex than my algo : is there a reason not to use a widow window ? Performance ?

Re: GetWindowTitleHeight()

Posted: Sun May 30, 2021 8:44 pm
by Mijikai
It doesnt go through registering and setting up a window so i expect it to be a bit smaller under the hood.

Re: GetWindowTitleHeight()

Posted: Mon May 31, 2021 8:18 am
by BarryG
For Microsoft Windows, you can do it with one API command:

Code: Select all

Debug GetSystemMetrics_(#SM_CYCAPTION)