(1)
Sure you can create popup menus containing sub menus using API functions. See the VB example below.
___
Option Explicit
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 String) As Long
Private Declare Function DestroyMenu Lib "user32" (ByVal hMenu As Long) 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 Type POINTAPI
x As Long
y As Long
End Type
Const MF_POPUP = &H10&
Dim hMenu As Long, hSubMenu As Long
Private Sub Form_Load()
Caption = "7 Layers of the OSI Model"
hSubMenu = CreatePopupMenu
AppendMenu hSubMenu, 0, 121, "Media Access Control"
AppendMenu hSubMenu, 0, 122, "Logical Link Control"
hMenu = CreatePopupMenu
AppendMenu hMenu, 0, 107, "Application"
AppendMenu hMenu, 0, 106, "Presentation"
AppendMenu hMenu, 0, 105, "Session"
AppendMenu hMenu, 0, 104, "Transport"
AppendMenu hMenu, 0, 103, "Network"
AppendMenu hMenu, MF_POPUP, hSubMenu, "Data Link" 'insert the sub menu
AppendMenu hMenu, 0, 101, "Physical"
End Sub
Private Sub Form_MouseUp(Button As Integer, Shift As Integer, x As Single, y As Single)
If Button = vbRightButton Then
Dim P As POINTAPI
GetCursorPos P
TrackPopupMenu hMenu, 0, P.x, P.y, 0, hwnd, 0
End If
End Sub
Private Sub Form_Unload(Cancel As Integer)
DestroyMenu hSubMenu
DestroyMenu hMenu
End Sub
___
(2)
When a menu item is highlighted, Windows sends a WM_MENUSELECT message to the window that owns the menu. You can subclass the window and filter this message to be notified of such events.
See thread222-506228 that covers this issue in details.