MenuHeight(), StatusBarHeight(), ToolBarHeight() returns 0?

Just starting out? Need help? Post your questions and find answers here.
Mistrel
Addict
Addict
Posts: 3415
Joined: Sat Jun 30, 2007 8:04 pm

MenuHeight(), StatusBarHeight(), ToolBarHeight() returns 0?

Post by Mistrel »

Code: Select all

- Changed: MenuHeight(), StatusBarHeight() and ToolBarHeight() are now deprecated (all returns 0)
What is the cross-platform way to create a window with a menu, toolbar, and status bar, and window decorations, that fits the size of the desktop?

On Windows we have AdjustWindowRect/AdjustWindowRectEx() but I don't know what to do for other platforms.
User avatar
kenmo
Addict
Addict
Posts: 1967
Joined: Tue Dec 23, 2003 3:54 am

Re: MenuHeight(), StatusBarHeight(), ToolBarHeight() returns

Post by kenmo »

Mistrel wrote:

Code: Select all

- Changed: MenuHeight(), StatusBarHeight() and ToolBarHeight() are now deprecated (all returns 0)
What is the cross-platform way to create a window with a menu, toolbar, and status bar, and window decorations, that fits the size of the desktop?

On Windows we have AdjustWindowRect/AdjustWindowRectEx() but I don't know what to do for other platforms.
I'm trying to figure this out too.

My first idea is: create a dummy window, add a menu, add a toolbar, add a statusbar, and use WindowHeight() Frame vs. Inner to measure the difference...


EDIT

Code: Select all

Global __MenuHeight.i      = -1
Global __ToolBarHeight.i   = -1
Global __StatusBarHeight.i = -1

Procedure __GetBarHeights()
  Protected TempWin.i = OpenWindow(#PB_Any, 0, 0, 200, 200, "", #PB_Window_Invisible)
  If (TempWin)
    Protected BaseHeight.i = WindowHeight(TempWin, #PB_Window_FrameCoordinate)
    Protected TempBar.i
    TempBar = CreateMenu(#PB_Any, WindowID(TempWin))
    If (TempBar)
      MenuTitle("")
      CompilerIf (#PB_Compiler_Version >= 560)
        __MenuHeight = WindowHeight(TempWin, #PB_Window_FrameCoordinate) - BaseHeight
      CompilerElse
        __MenuHeight = MenuHeight()
      CompilerEndIf
      FreeMenu(TempBar)
    EndIf
    TempBar = CreateToolBar(#PB_Any, WindowID(TempWin))
    If (TempBar)
      ToolBarStandardButton(0, #PB_ToolBarIcon_New)
      CompilerIf (#PB_Compiler_Version >= 560)
        __ToolbarHeight = WindowHeight(TempWin, #PB_Window_FrameCoordinate) - BaseHeight
      CompilerElse
        __ToolbarHeight = ToolbarHeight(TempBar)
      CompilerEndIf
      FreeToolBar(TempBar)
    EndIf
    TempBar = CreateStatusBar(#PB_Any, WindowID(TempWin))
    If (TempBar)
      AddStatusBarField(100)
      CompilerIf (#PB_Compiler_Version >= 560)
        __StatusbarHeight = WindowHeight(TempWin, #PB_Window_FrameCoordinate) - BaseHeight
      CompilerElse
        __StatusbarHeight = StatusBarHeight(TempBar)
      CompilerEndIf
      FreeStatusBar(TempBar)
    EndIf
    CloseWindow(TempWin)
  EndIf
EndProcedure

Procedure.i StandardMenuHeight()
  If (__MenuHeight = -1)
    __GetBarHeights()
  EndIf
  ProcedureReturn (__MenuHeight)
EndProcedure

Procedure.i StandardToolBarHeight()
  If (__ToolbarHeight = -1)
    __GetBarHeights()
  EndIf
  ProcedureReturn (__ToolbarHeight)
EndProcedure

Procedure.i StandardStatusBarHeight()
  If (__StatusbarHeight = -1)
    __GetBarHeights()
  EndIf
  ProcedureReturn (__StatusbarHeight)
EndProcedure

Debug StandardMenuHeight()
Debug StandardToolbarHeight()
Debug StandardStatusbarHeight()
Last edited by kenmo on Fri Jan 27, 2017 8:27 pm, edited 1 time in total.
freak
PureBasic Team
PureBasic Team
Posts: 5929
Joined: Fri Apr 25, 2003 5:21 pm
Location: Germany

Re: MenuHeight(), StatusBarHeight(), ToolBarHeight() returns

Post by freak »

Mistrel wrote:What is the cross-platform way to create a window with a menu, toolbar, and status bar, and window decorations, that fits the size of the desktop?
Why not simply create a maximized window?
quidquid Latine dictum sit altum videtur
Mistrel
Addict
Addict
Posts: 3415
Joined: Sat Jun 30, 2007 8:04 pm

Re: MenuHeight(), StatusBarHeight(), ToolBarHeight() returns

Post by Mistrel »

freak wrote:Why not simply create a maximized window?
Maybe I want the program to start at the desktop resolution in an unmaximized state? The question is hypothetical.
infratec
Always Here
Always Here
Posts: 6883
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: MenuHeight(), StatusBarHeight(), ToolBarHeight() returns

Post by infratec »

Hi,

the problem is the other way round:

I need a 'freee' inner window area of an exact size maybe 800 by 600.
And I want a menu above and a statusbar at the bottom.

How can I create that window without knowing the height of these two :?:
And my program is runing on all 3 platforms.

I needed already a ResizeWindow() because I was only able to get the StatusBarHeight() after the bar was created.
But now, no idea.

Bernd
infratec
Always Here
Always Here
Posts: 6883
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: MenuHeight(), StatusBarHeight(), ToolBarHeight() returns

Post by infratec »

Upps....

I read the changes after my comment.
My problem should be resolved, because of
- Changed: ToolBar, Menu and StatusBar are now excluded from inner window area for all OS
I'll test it asap.

I think the window will be automatically resized :wink:

Bernd
Fred
Administrator
Administrator
Posts: 16690
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Re: MenuHeight(), StatusBarHeight(), ToolBarHeight() returns

Post by Fred »

Yes it will.

Maximized window is the way to go to have a window which fits the desktop on all 3 OSes. On Linux/OSX some of these functions already returned 0 anyway, so you couldn't use them for that.
infratec
Always Here
Always Here
Posts: 6883
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: MenuHeight(), StatusBarHeight(), ToolBarHeight() returns

Post by infratec »

:D

(I always miss a thump up emoticon)
User avatar
Kurzer
Enthusiast
Enthusiast
Posts: 666
Joined: Sun Jun 11, 2006 12:07 am
Location: Near Hamburg

Re: MenuHeight(), StatusBarHeight(), ToolBarHeight() returns

Post by Kurzer »

infratec wrote::D
(I always miss a thump up emoticon)
Borrow it from the german forum. ;-)

http://forums.purebasic.com/german/imag ... lright.gif

Image
PB 6.02 x64, OS: Win 7 Pro x64 & Win 11 x64, Desktopscaling: 125%, CPU: I7 6500, RAM: 16 GB, GPU: Intel Graphics HD 520, User age in 2024: 56y
"Happiness is a pet." | "Never run a changing system!"
User avatar
skywalk
Addict
Addict
Posts: 4004
Joined: Wed Dec 23, 2009 10:14 pm
Location: Boston, MA

Re: MenuHeight(), StatusBarHeight(), ToolBarHeight() returns

Post by skywalk »

Is this a temporary removal to get the beta out or do we roll our own moving forward?
I have to update my resize events like everyone else who does not run maximized. :cry:
The nice thing about standards is there are so many to choose from. ~ Andrew Tanenbaum
Fred
Administrator
Administrator
Posts: 16690
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Re: MenuHeight(), StatusBarHeight(), ToolBarHeight() returns

Post by Fred »

Could you post an example which should be adjusted ? You shouldn't have to adjust anything now, as all is dynamically adjusted.
User avatar
skywalk
Addict
Addict
Posts: 4004
Joined: Wed Dec 23, 2009 10:14 pm
Location: Boston, MA

Re: MenuHeight(), StatusBarHeight(), ToolBarHeight() returns

Post by skywalk »

Ok, let me dive into it.
I also update statusbars with custom images(progress bar) so I need StatusBarHeight() <> 0.
I manage the overall dimensions of my windows, not just client area.
The nice thing about standards is there are so many to choose from. ~ Andrew Tanenbaum
Dude
Addict
Addict
Posts: 1907
Joined: Mon Feb 16, 2015 2:49 pm

Re: MenuHeight(), StatusBarHeight(), ToolBarHeight() returns

Post by Dude »

My flagship product is now broken because StatusBarHeight() is removed. :(

My product needs to constantly change its window size during runtime to X,Y of 10,10 and the height is to finish just a bit above the taskbar, no matter how high the user sets his taskbar. So, no, NOT a maximized window.

I can't do this now because it relied on StatusBarHeight(). Here's the code which worked wonderfully before, but is now totally BROKEN in the beta:

Code: Select all

OpenWindow(0,0,0,600,0,"test")
CreateStatusBar(0,WindowID(0))
statusheight=StatusBarHeight(0)

GetWindowRect_(FindWindow_("Shell_TrayWnd",0),taskwin.RECT)
taskheight=taskwin\bottom-taskwin\top

screenheight=GetSystemMetrics_(#SM_CYSCREEN)

ResizeWindow(0,10,10,600,screenheight-taskheight-(statusheight*2.5))

Repeat : Until WaitWindowEvent()=#PB_Event_CloseWindow
kenmo wrote:My first idea is: create a dummy window, add a menu, add a toolbar, add a statusbar, and use WindowHeight() Frame vs. Inner to measure the difference.
Such a workaround is massive overkill to fix the removal of the commands.

Please bring MenuHeight(), StatusBarHeight(), ToolBarHeight() back. They ARE needed. Thank you.
Last edited by Dude on Tue Jan 31, 2017 10:11 am, edited 1 time in total.
Fred
Administrator
Administrator
Posts: 16690
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Re: MenuHeight(), StatusBarHeight(), ToolBarHeight() returns

Post by Fred »

I see. Would a flag to ResizWindow() to select between inner and frame coordinate solve this ?
Dude
Addict
Addict
Posts: 1907
Joined: Mon Feb 16, 2015 2:49 pm

Re: MenuHeight(), StatusBarHeight(), ToolBarHeight() returns

Post by Dude »

Not sure. I am willing to test anything you make available. :)
Post Reply