[RESOLVED] Minimum height for menu bar to be visible?-VBForums
Results 1 to 10 of 10

Thread: [RESOLVED] Minimum height for menu bar to be visible?

  1. #1

    Thread Starter
    vbuggy krtxmrtz's Avatar
    Join Date
    May 2002
    Location
    [41.5622N-2.0045E]
    Posts
    5,496

    Resolved [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)

  2. #2

    Thread Starter
    vbuggy krtxmrtz's Avatar
    Join Date
    May 2002
    Location
    [41.5622N-2.0045E]
    Posts
    5,496

    Re: Minimum height for menu bar to be visible?

    Quote Originally Posted by krtxmrtz View Post
    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)

  3. #3
    VBaholic & Loving It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    GetWindowRect()
    Posts
    11,938

    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
    Insomnia is just a byproduct of, "It can't be done"

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum. Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts


    {Alpha Image Control} {Memory Leak FAQ} {GDI+ Classes/Samples} {Unicode Open/Save Dialog} {Icon Organizer/Extractor}
    {VBA Control Arrays} {XP/Vista Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  4. #4

    Thread Starter
    vbuggy krtxmrtz's Avatar
    Join Date
    May 2002
    Location
    [41.5622N-2.0045E]
    Posts
    5,496

    Re: [RESOLVED] Minimum height for menu bar to be visible?

    Quote Originally Posted by LaVolpe View Post
    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)

  5. #5
    VBaholic & Loving It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    GetWindowRect()
    Posts
    11,938

    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.
    Insomnia is just a byproduct of, "It can't be done"

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum. Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts


    {Alpha Image Control} {Memory Leak FAQ} {GDI+ Classes/Samples} {Unicode Open/Save Dialog} {Icon Organizer/Extractor}
    {VBA Control Arrays} {XP/Vista Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  6. #6

    Thread Starter
    vbuggy krtxmrtz's Avatar
    Join Date
    May 2002
    Location
    [41.5622N-2.0045E]
    Posts
    5,496

    Re: [RESOLVED] Minimum height for menu bar to be visible?

    Quote Originally Posted by LaVolpe View Post
    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:
    1. Private Type rect
    2.     Left As Long
    3.     Top As Long
    4.     Right As Long
    5.     Bottom As Long
    6. End Type
    7. Private Type MENUBARINFO
    8.   cbSize As Byte
    9.   rcBar As rect
    10.   hMenu As Long
    11.   hwndMenu As Long
    12.   fBarFocused As Boolean
    13.   fFocused As Boolean
    14. End Type
    15. Private MenuInfo As MENUBARINFO
    16. Private Const OBJID_MENU As Long = &HFFFFFFFD
    17. Private Const OBJID_SYSMENU As Long = &HFFFFFFFF
    18. Private Declare Function GetMenuBarInfo Lib "user32" (ByVal hwnd As Long, _
    19. ByVal idObject As Long, ByVal idItem As Long, ByRef pmbi As MENUBARINFO) As Boolean
    20. Private Declare Function GetMenu Lib "user32" (ByVal hwnd As Long) As Long
    21.  
    22. Private Sub Command1_Click()
    23.  
    24.     MenuInfo.cbSize = Len(MenuInfo)
    25.     If GetMenuBarInfo(GetMenu(Me.hwnd), OBJID_MENU, 0, MenuInfo) Then
    26.    
    27.         With MenuInfo.rcBar
    28.        
    29.             Debug.Print "Left: " & CStr(.Left)
    30.             Debug.Print "Right: " & CStr(.Right)
    31.             Debug.Print "Top: " & CStr(.Top)
    32.             Debug.Print "Bottom: " & CStr(.Bottom)
    33.            
    34.         End With
    35.        
    36.     End If
    37.    
    38. 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)

  7. #7
    VBaholic & Loving It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    GetWindowRect()
    Posts
    11,938

    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
    Insomnia is just a byproduct of, "It can't be done"

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum. Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts


    {Alpha Image Control} {Memory Leak FAQ} {GDI+ Classes/Samples} {Unicode Open/Save Dialog} {Icon Organizer/Extractor}
    {VBA Control Arrays} {XP/Vista Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  8. #8

    Thread Starter
    vbuggy krtxmrtz's Avatar
    Join Date
    May 2002
    Location
    [41.5622N-2.0045E]
    Posts
    5,496

    Re: [RESOLVED] Minimum height for menu bar to be visible?

    Quote Originally Posted by LaVolpe View Post
    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)

  9. #9
    VBaholic & Loving It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    GetWindowRect()
    Posts
    11,938

    Re: [RESOLVED] Minimum height for menu bar to be visible?

    Quote Originally Posted by krtxmrtz View Post
    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
    Insomnia is just a byproduct of, "It can't be done"

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum. Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts


    {Alpha Image Control} {Memory Leak FAQ} {GDI+ Classes/Samples} {Unicode Open/Save Dialog} {Icon Organizer/Extractor}
    {VBA Control Arrays} {XP/Vista Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  10. #10

    Thread Starter
    vbuggy krtxmrtz's Avatar
    Join Date
    May 2002
    Location
    [41.5622N-2.0045E]
    Posts
    5,496

    Re: [RESOLVED] Minimum height for menu bar to be visible?

    Quote Originally Posted by LaVolpe View Post
    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:
    1. Private Type rect
    2.     Left As Long
    3.     Top As Long
    4.     Right As Long
    5.     Bottom As Long
    6. End Type
    7. Private Type MENUBARINFO
    8.   cbSize As Long
    9.   rcBar As rect
    10.   hMenu As Long
    11.   hwndMenu As Long
    12.   fBarFocused As Boolean
    13.   fFocused As Boolean
    14. End Type
    15. Private MenuInfo As MENUBARINFO
    16. Private Const OBJID_MENU As Long = &HFFFFFFFD
    17. Private Const OBJID_SYSMENU As Long = &HFFFFFFFF
    18. Private Declare Function GetMenuBarInfo Lib "user32" (ByVal hwnd As Long, _
    19. ByVal idObject As Long, ByVal idItem As Long, ByRef pmbi As MENUBARINFO) As Boolean
    20. Private Declare Function GetMenu Lib "user32" (ByVal hwnd As Long) As Long
    21. Private Sub Command1_Click()
    22.  
    23.     MenuInfo.cbSize = Len(MenuInfo)
    24.    
    25.     If GetMenuBarInfo(Me.hwnd, OBJID_MENU, 0, MenuInfo) Then
    26.    
    27.         With MenuInfo.rcBar
    28.        
    29.             Debug.Print "Left: " & CStr(.Left)
    30.             Debug.Print "Right: " & CStr(.Right)
    31.             Debug.Print "Top: " & CStr(.Top)
    32.             Debug.Print "Bottom: " & CStr(.Bottom)
    33.            
    34.         End With
    35.        
    36.     End If
    37.    
    38. End Sub
    Last edited by krtxmrtz; Feb 25th, 2012 at 10: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
  •  



Featured


Click Here to Expand Forum to Full Width

Survey posted by VBForums.