Page 1 of 3

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

Posted: Fri Jan 27, 2017 7:12 pm
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.

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

Posted: Fri Jan 27, 2017 7:23 pm
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()

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

Posted: Fri Jan 27, 2017 7:27 pm
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?

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

Posted: Fri Jan 27, 2017 7:37 pm
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.

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

Posted: Fri Jan 27, 2017 7:50 pm
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

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

Posted: Fri Jan 27, 2017 7:55 pm
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

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

Posted: Fri Jan 27, 2017 8:55 pm
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.

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

Posted: Fri Jan 27, 2017 11:39 pm
by infratec
:D

(I always miss a thump up emoticon)

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

Posted: Sat Jan 28, 2017 6:13 pm
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

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

Posted: Mon Jan 30, 2017 5:43 pm
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:

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

Posted: Mon Jan 30, 2017 6:00 pm
by Fred
Could you post an example which should be adjusted ? You shouldn't have to adjust anything now, as all is dynamically adjusted.

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

Posted: Mon Jan 30, 2017 6:19 pm
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.

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

Posted: Tue Jan 31, 2017 9:42 am
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.

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

Posted: Tue Jan 31, 2017 9:51 am
by Fred
I see. Would a flag to ResizWindow() to select between inner and frame coordinate solve this ?

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

Posted: Tue Jan 31, 2017 10:12 am
by Dude
Not sure. I am willing to test anything you make available. :)