-
Feb 22nd, 2012, 12:29 PM
#1
[RESOLVED] Minimum height for menu bar to be visible?
I want to start an application with the main form shrunken such that only the title bar and the menu bar are visible. Later on the full form height is to be restored.
How do I figure out the height of the menu bar avoiding manual trial and error at design time?
Lottery is a tax on people who are bad at maths
If only mosquitoes sucked fat instead of blood...
To do is to be (Descartes). To be is to do (Sartre). To be do be do (Sinatra)
-
Feb 22nd, 2012, 12:37 PM
#2
Re: Minimum height for menu bar to be visible?
Originally Posted by krtxmrtz
I want to start an application with the main form shrunken such that only the title bar and the menu bar are visible. Later on the full form height is to be restored.
How do I figure out the height of the menu bar avoiding manual trial and error at design time?
Oh, well, I've just realized that
Me.Height = Me.Height - Screen.TwipsPerPixelY * Me.ScaleHeight
allows the menu bar to be visible (I'd thought only the title bar would)
Resolved!
Lottery is a tax on people who are bad at maths
If only mosquitoes sucked fat instead of blood...
To do is to be (Descartes). To be is to do (Sartre). To be do be do (Sinatra)
-
Feb 22nd, 2012, 01:00 PM
#3
Re: [RESOLVED] Minimum height for menu bar to be visible?
As long as your form initially has a client area, your solution should work fine. But if form starts out where .ScaleHeight is zero, your form won't resize using that logic. Just FYI
-
Feb 23rd, 2012, 03:29 AM
#4
Re: [RESOLVED] Minimum height for menu bar to be visible?
Originally Posted by LaVolpe
As long as your form initially has a client area, your solution should work fine. But if form starts out where .ScaleHeight is zero, your form won't resize using that logic. Just FYI
Thanks, I wasn't aware of that of course.
In order to have a visible menu I have tried
Me.Height = CInt(1.6 * Me.Height)
where Me.Height is the design time form height with SceleHeight=0 and the munus are visible. But it seems to me an ugly way to do it and I'd rather find out the correct menu height in case it's available from some metrics related api function.
Lottery is a tax on people who are bad at maths
If only mosquitoes sucked fat instead of blood...
To do is to be (Descartes). To be is to do (Sartre). To be do be do (Sinatra)
-
Feb 23rd, 2012, 08:42 AM
#5
Re: [RESOLVED] Minimum height for menu bar to be visible?
GetMenuBarInfo API (Win2K and higher) can do it for you. It should take into consideration the font/size used which can be different from computer to computer.
-
Feb 24th, 2012, 11:19 AM
#6
Re: [RESOLVED] Minimum height for menu bar to be visible?
Originally Posted by LaVolpe
GetMenuBarInfo API (Win2K and higher) can do it for you. It should take into consideration the font/size used which can be different from computer to computer.
Searching around I found some examples from which I tried this code on a form with a menu bar with 2 main menus, one of them with 2 submenus:
VB Code:
Private Type rect
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type
Private Type MENUBARINFO
cbSize As Byte
rcBar As rect
hMenu As Long
hwndMenu As Long
fBarFocused As Boolean
fFocused As Boolean
End Type
Private MenuInfo As MENUBARINFO
Private Const OBJID_MENU As Long = &HFFFFFFFD
Private Const OBJID_SYSMENU As Long = &HFFFFFFFF
Private Declare Function GetMenuBarInfo Lib "user32" (ByVal hwnd As Long, _
ByVal idObject As Long, ByVal idItem As Long, ByRef pmbi As MENUBARINFO) As Boolean
Private Declare Function GetMenu Lib "user32" (ByVal hwnd As Long) As Long
Private Sub Command1_Click()
MenuInfo.cbSize = Len(MenuInfo)
If GetMenuBarInfo(GetMenu(Me.hwnd), OBJID_MENU, 0, MenuInfo) Then
With MenuInfo.rcBar
Debug.Print "Left: " & CStr(.Left)
Debug.Print "Right: " & CStr(.Right)
Debug.Print "Top: " & CStr(.Top)
Debug.Print "Bottom: " & CStr(.Bottom)
End With
End If
End Sub
But GetMenuBarInfo returns False for some reason
Lottery is a tax on people who are bad at maths
If only mosquitoes sucked fat instead of blood...
To do is to be (Descartes). To be is to do (Sartre). To be do be do (Sinatra)
-
Feb 24th, 2012, 12:40 PM
#7
Re: [RESOLVED] Minimum height for menu bar to be visible?
1. cbSize As Long, not as Byte
2. The call would look like this to get your form's menubar size
GetMenuBarInfo(Me.hwnd, OBJID_MENU, 0, MenuInfo)
3. Submenus are not a player. Submenus are only shown if the menu is activated. Where submenus may come into play is if you want to get the size of the menu box that the submenu will display in once activated
-
Feb 24th, 2012, 03:48 PM
#8
Re: [RESOLVED] Minimum height for menu bar to be visible?
Originally Posted by LaVolpe
1. cbSize As Long, not as Byte
2. The call would look like this to get your form's menubar size
GetMenuBarInfo(Me.hwnd, OBJID_MENU, 0, MenuInfo)
3. Submenus are not a player. Submenus are only shown if the menu is activated. Where submenus may come into play is if you want to get the size of the menu box that the submenu will display in once activated
Still False. Have you tried if it works?
Lottery is a tax on people who are bad at maths
If only mosquitoes sucked fat instead of blood...
To do is to be (Descartes). To be is to do (Sartre). To be do be do (Sinatra)
-
Feb 25th, 2012, 10:41 AM
#9
Re: [RESOLVED] Minimum height for menu bar to be visible?
Originally Posted by krtxmrtz
Still False. Have you tried if it works?
Yes, I've used it before. Though I used Integer instead of Boolean for the structure members and Long as the the API's return value. Ensure you are passing the window Hwnd not a menu handle as the 1st parameter. I cannot give you an example today -- rebuilding my PC & won't have VB up & running until late today or tomorrow
-
Feb 25th, 2012, 11:45 AM
#10
Re: [RESOLVED] Minimum height for menu bar to be visible?
Originally Posted by LaVolpe
1. cbSize As Long, not as Byte
2. The call would look like this to get your form's menubar size
GetMenuBarInfo(Me.hwnd, OBJID_MENU, 0, MenuInfo)...
I can't say I did as you suggested... I used Me.hwnd but then forgot to change long to byte in the cbSize declaration. Sheer absent-mindedness, sorry.
Now it works. I assume the returned values are the rectangle coordinates relative to the screen's upper left corner.
I attach the final typo-free working version for someone's future reference.
VB Code:
Private Type rect Left As Long Top As Long Right As Long Bottom As Long End Type Private Type MENUBARINFO cbSize As Long rcBar As rect hMenu As Long hwndMenu As Long fBarFocused As Boolean fFocused As Boolean End Type Private MenuInfo As MENUBARINFO Private Const OBJID_MENU As Long = &HFFFFFFFD Private Const OBJID_SYSMENU As Long = &HFFFFFFFF Private Declare Function GetMenuBarInfo Lib "user32" (ByVal hwnd As Long, _ ByVal idObject As Long, ByVal idItem As Long, ByRef pmbi As MENUBARINFO) As Boolean Private Declare Function GetMenu Lib "user32" (ByVal hwnd As Long) As Long Private Sub Command1_Click() MenuInfo.cbSize = Len(MenuInfo) If GetMenuBarInfo(Me.hwnd, OBJID_MENU, 0, MenuInfo) Then With MenuInfo.rcBar Debug.Print "Left: " & CStr(.Left) Debug.Print "Right: " & CStr(.Right) Debug.Print "Top: " & CStr(.Top) Debug.Print "Bottom: " & CStr(.Bottom) End With End If End Sub
Last edited by krtxmrtz; Feb 25th, 2012 at 11:52 AM.
Lottery is a tax on people who are bad at maths
If only mosquitoes sucked fat instead of blood...
To do is to be (Descartes). To be is to do (Sartre). To be do be do (Sinatra)
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|