
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