You can map the hierarchical menu structure of a form into a treeview control. See the code below. It scans the whole menu tree recursively and populates a treeview control.
Start a new VB project and create the desired menu structure for your from using the Menu Editor.
Add Microsoft Windows Common Controls to your toolbox and place a treeview control on your form.
Insert the following code in your form.
___
[tt]
Option Explicit
Private Declare Function GetMenuItemCount Lib "user32" (ByVal hMenu As Long) As Long
Private Declare Function GetMenuString Lib "user32" Alias "GetMenuStringA" (ByVal hMenu As Long, ByVal wIDItem As Long, ByVal lpString As String, ByVal nMaxCount As Long, ByVal wFlag As Long) As Long
Private Declare Function GetSubMenu Lib "user32" (ByVal hMenu As Long, ByVal nPos As Long) As Long
Private Declare Function GetMenu Lib "user32" (ByVal hwnd As Long) As Long
Const MF_BYPOSITION = &H400&
Private Sub Form_Load()
PopulateMenus TreeView1.Nodes.Add(Text:=Caption), GetMenu(hwnd)
End Sub
Sub PopulateMenus(Node As Node, hMenu As Long)
Dim N As Long, S As String * 1000
For N = 0 To GetMenuItemCount(hMenu) - 1
GetMenuString hMenu, N, S, Len(S), MF_BYPOSITION
PopulateMenus TreeView1.Nodes.Add(Node, tvwChild, , S), GetSubMenu(hMenu, N)
Next
Node.Expanded = True
End Sub
Private Sub Form_Resize()
TreeView1.Move 0, 0, ScaleWidth, ScaleHeight
End Sub[/tt]
___
Run the program, the treeview will be filled hierarchically with the menu structure of the form.