Вы можете создать более одного уровня подменю с помощью функции API
Private Declare Function CreatePopupMenu Lib "user32" () As Long
Private Declare Function AppendMenu Lib "user32" Alias "AppendMenuA" (ByVal hmenu As Long, ByVal wFlags As Long, ByVal wIDNewItem As Long, ByVal lpNewItem As Any) As Long
Private Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long
Private Declare Function TrackPopupMenu Lib "user32" (ByVal hmenu As Long, ByVal wFlags As Long, ByVal X As Long, ByVal Y As Long, ByVal nReserved As Long, ByVal hwnd As Long, lprc As Any) As Long
Private Declare Function DestroyMenu Lib "user32" (ByVal hmenu As Long) As Long
Private Type POINTAPI
X As Long
Y As Long
End Type
Dim hmenu As Long, hSubMenu As Long
Private Const MF_STRING = &H0&
Private Const MF_SEPARATOR = &H800&
hSubMenu = CreatePopupMenu
AppendMenu hSubMenu, 0, 121, "Sub Menu1"
AppendMenu hSubMenu, 0, 122, "Sub Menu2"
hmenu = CreatePopupMenu
AppendMenu hmenu, 0, 107, "Menu1"
AppendMenu hmenu, 0, 106, "Menu2"
AppendMenu hmenu, MF_POPUP, hSubMenu, "Menu3"
AppendMenu hmenu, MF_POPUP, hSubMenu, "Menu4"
AppendMenu hmenu, 0, 101, "Menu5"
Для отображения
If Button = vbRightButton Then
Dim P As POINTAPI
GetCursorPos P
TrackPopupMenu hmenu, 0, P.X, P.Y, 0, hwnd, 0
Меню не отображается до вызова TrackPopupMenu
. Его возвращаемое значение может указывать, какой (если есть) пункт меню был выбран. например, он может возвратить «107», если выбрано «Menu1».