GetWindowTitleHeight()

Share your advanced PureBasic knowledge/code with the community.
Olli
Addict
Addict
Posts: 1071
Joined: Wed May 27, 2020 12:26 pm

GetWindowTitleHeight()

Post 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
User avatar
Mijikai
Addict
Addict
Posts: 1360
Joined: Sun Sep 11, 2016 2:17 pm

Re: GetWindowTitleHeight()

Post 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
Olli
Addict
Addict
Posts: 1071
Joined: Wed May 27, 2020 12:26 pm

Re: GetWindowTitleHeight()

Post 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 !
User avatar
Mijikai
Addict
Addict
Posts: 1360
Joined: Sun Sep 11, 2016 2:17 pm

Re: GetWindowTitleHeight()

Post 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
Olli
Addict
Addict
Posts: 1071
Joined: Wed May 27, 2020 12:26 pm

Re: GetWindowTitleHeight()

Post by Olli »

It's right ! But a few more complex than my algo : is there a reason not to use a widow window ? Performance ?
User avatar
Mijikai
Addict
Addict
Posts: 1360
Joined: Sun Sep 11, 2016 2:17 pm

Re: GetWindowTitleHeight()

Post by Mijikai »

It doesnt go through registering and setting up a window so i expect it to be a bit smaller under the hood.
BarryG
Addict
Addict
Posts: 3320
Joined: Thu Apr 18, 2019 8:17 am

Re: GetWindowTitleHeight()

Post by BarryG »

For Microsoft Windows, you can do it with one API command:

Code: Select all

Debug GetSystemMetrics_(#SM_CYCAPTION)
Post Reply