Page 1 of 1

Has a Window got a Titlebar or Menu?

Posted: Fri Jun 14, 2013 10:05 am
by RichardL
Hi,
I'm writing some utility code that needs to take account of the presence or otherwise of (a) the titlebar and (b) a menu.
GetSystemMetrics_() returns the heights of these items but the values are SYSTEM values. :) and do not appear to relate to the running program.
Can anyone tell me how to determine if a Windows program has a TitleBar and / or a Menu?
Thank you,
RichardL

Re: Has a Window got a Titlebar or Menu?

Posted: Fri Jun 14, 2013 11:09 am
by Bisonte
To Check Menu

Code: Select all

EnableExplicit
Define EventID, hMenu
If OpenWindow(0,0,0,500,250,"Window",#PB_Window_SystemMenu|#PB_Window_ScreenCentered)
  If CreateMenu(1,WindowID(0))
    MenuTitle("project")
      MenuItem(1,"Item",0)
  EndIf
  ButtonGadget(1,10,10,100,20,"test",0)
  Repeat
    EventID=WaitWindowEvent()
    If EventID=#PB_Event_Gadget
      Select EventGadget()
        Case 1
          hMenu = GetMenu_(WindowID(0))
          Debug hMenu
          SetMenu_(WindowID(0),0)
      EndSelect
    EndIf
  Until EventID = #PB_Event_CloseWindow
EndIf
And a WindowTitlebarCheck

Code: Select all

#CCHILDREN_TITLEBAR = 5

Structure TITLEBARINFO
  cbSize.l
  rcTitleBar.RECT
  rgstate.l[#CCHILDREN_TITLEBAR+1]
EndStructure

Procedure WindowTitleBar(Window)
  
  Protected hWnd = #False, Height
  Protected pti.TITLEBARINFO
  
  If IsWindow(Window)
    hWnd = WindowID(Window)
  Else
    If IsWindow_(hWnd)
      hWnd = hWnd
    EndIf
  EndIf
  
  If hWnd
    pti.TITLEBARINFO\cbSize = SizeOf(TITLEBARINFO)
    GetTitleBarInfo_(hWnd, pti)
    Height = pti\rcTitleBar\bottom-pti\rcTitleBar\top
    If Height > 0
      ProcedureReturn #True
    EndIf
  EndIf
  ProcedureReturn #False
    
EndProcedure

If OpenWindow(0,0,0,500,250,"Window",#PB_Window_SystemMenu|#PB_Window_ScreenCentered)
  
  If WindowTitleBar(0)
    Debug "Window has a Titlebar"
  Else
    Debug "Window has no Titlebar"
  EndIf
  
Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow
EndIf 
With help from RSBasic's WinAPI Library ;)

Re: Has a Window got a Titlebar or Menu?

Posted: Fri Jun 14, 2013 11:32 am
by RASHAD

Code: Select all

OpenWindow(0,0,0,400,300,"Test",#PB_Window_SystemMenu|#PB_Window_ScreenCentered)
SetWindowColor(0,#Gray)
Result = GetMenu_(WindowID(0))
If Result > 0
   Debug "There is a Menu"
Else
   Debug "No Menu"
EndIf
wi.WINDOWINFO\cbSize = SizeOf(wi)
GetWindowInfo_(WindowID(0),wi)
Caption = wi\rcClient\top - wi\rcWindow\top
If Caption > 10
   Debug "There is a TitltBar"
Else
   Debug "No Caption"
EndIf
Repeat
  Select WaitWindowEvent()
      
      Case #PB_Event_CloseWindow
            Quit = 1
      
      Case #PB_Event_Gadget
          Select EventGadget()
           Case 1            
          EndSelect
          
  EndSelect 

Until Quit = 1
End


Re: Has a Window got a Titlebar or Menu?

Posted: Fri Jun 14, 2013 1:03 pm
by RichardL
Gentlemen,
Thank you for your assistance with solving my problem. I am now a wiser man. :D

Based in RASHAD's solution I wrote the following test bed to find what I really wanted
which was "What is the aggregate width of the frame, title and menubar (when prersent)?

I should have asked the right question in the first place!

Code: Select all

; Find Y poition of client area in window with
; border / title / menu

OpenWindow(1,0,0,200,60,"",#PB_Window_BorderLess)
SetWindowColor(1,#Red)
wi.WINDOWINFO\cbSize = SizeOf(wi)
GetWindowInfo_(WindowID(1),wi)
Debug "RED"
Debug wi\cyWindowBorders
Debug wi\rcClient\top - wi\rcWindow\top 

OpenWindow(2,0,100,200,60,"",0)
SetWindowColor(2,#Green)
wi.WINDOWINFO\cbSize = SizeOf(wi)
GetWindowInfo_(WindowID(2),wi)
Debug "GREEN"
Debug wi\cyWindowBorders
Debug wi\rcClient\top - wi\rcWindow\top

OpenWindow(3,0,200,200,60,"",#PB_Window_SystemMenu)
SetWindowColor(3,#Blue)
CreateMenu(1,WindowID(3)) : MenuTitle("Fred")
wi.WINDOWINFO\cbSize = SizeOf(wi)
GetWindowInfo_(WindowID(3),wi)
Debug "BLUE"
Debug wi\cyWindowBorders
Debug wi\rcClient\top - wi\rcWindow\top

While WaitWindowEvent() <> #PB_Event_CloseWindow
Wend
Thanks again...
RichardL

Re: Has a Window got a Titlebar or Menu?

Posted: Sat Jun 15, 2013 12:07 pm
by infratec
Hi Richard,

same results without API stuff:

Code: Select all

; Find Y poition of client area in window with
; border / title / menu

Define WinFrameWidth.i, WinMenuHeight.i

OpenWindow(1,0,0,200,60,"",#PB_Window_BorderLess)
SetWindowColor(1,#Red)
Debug "RED"
WinFrameWidth = (WindowWidth(1, #PB_Window_FrameCoordinate) - WindowWidth(1, #PB_Window_InnerCoordinate)) / 2
If IsMenu(1)
  WinMenuHeight = MenuHeight()
Else
  WinMenuHeight = 0
EndIf
Debug WinFrameWidth 
Debug (WindowHeight(1, #PB_Window_FrameCoordinate) - WindowHeight(1, #PB_Window_InnerCoordinate)) - WinFrameWidth + WinMenuHeight


OpenWindow(2,0,100,200,60,"",0)
SetWindowColor(2,#Green)
Debug "GREEN"
WinFrameWidth = (WindowWidth(2, #PB_Window_FrameCoordinate) - WindowWidth(2, #PB_Window_InnerCoordinate)) / 2
If IsMenu(1)
  WinMenuHeight = MenuHeight()
Else
  WinMenuHeight = 0
EndIf
Debug WinFrameWidth
Debug (WindowHeight(2, #PB_Window_FrameCoordinate) - WindowHeight(2, #PB_Window_InnerCoordinate)) - WinFrameWidth + WinMenuHeight


OpenWindow(3,0,200,200,60,"",#PB_Window_SystemMenu)
SetWindowColor(3,#Blue)
CreateMenu(1,WindowID(3)) : MenuTitle("Fred")
Debug "BLUE"
WinFrameWidth = (WindowWidth(3, #PB_Window_FrameCoordinate) - WindowWidth(3, #PB_Window_InnerCoordinate)) / 2
If IsMenu(1)
  WinMenuHeight = MenuHeight()
Else
  WinMenuHeight = 0
EndIf
Debug WinFrameWidth
Debug (WindowHeight(3, #PB_Window_FrameCoordinate) - WindowHeight(3, #PB_Window_InnerCoordinate)) - WinFrameWidth + WinMenuHeight

While WaitWindowEvent() <> #PB_Event_CloseWindow
Wend
Bernd

Re: Has a Window got a Titlebar or Menu?

Posted: Wed Jul 24, 2013 10:32 pm
by blueznl

Code: Select all

Procedure x_window_exteriorsize(window_nr.i)                                                 ; returns exterior size for specifed window
  Protected rect.RECT
  ; Global x_retval_x.i, x_retval_y.i, x_retval_width.i, x_retval_height.i
  ;
  ; *** returns coordinates and size of window exterior
  ;
  ; in:    window_nr            - pb window number
  ; out:   x_retval_x.i         - window x position
  ;        x_retval_y.i         - window y position
  ;        x_retval_width.i     - window width
  ;        x_retval_height.i    - window height
  ;
  GetWindowRect_(WindowID(window_nr),@rect)
  x_retval_x = rect\left
  x_retval_y = rect\top
  x_retval_width = rect\right-rect\left
  x_retval_height = rect\bottom-rect\top
  ;
EndProcedure
GetWindowRect_() may provide another approach. It's anyway worth to be mentioned :-)