Dynamicly adding sub-sub menu's

Hi, I've checked out this topic:


and I managed to get a layout like:

 \_ open
 \_ save
 \_ exit

BUT, do you have any idea how to create a menu layout like

 \_ new
        \_ normal
        \_ template
 \_ open
 \_ save

(I hope my scheme's make any sence).. Thanks in advance!
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

I usually do this:


Be sure that the index property of aOne and aTwo menu items are set to 0.

Then try the code below.

Option Explicit

Private Sub Command1_Click()
  Load mnuaOne(1)
  mnuaOne(1).Visible = True
  mnuaOne(1).Caption = "bOne"
  Load mnuaOne(2)
  mnuaOne(2).Visible = True
  mnuaOne(2).Caption = "cOne"
  Load mnuaTwo(1)
  mnuaTwo(1).Visible = True
  mnuaTwo(1).Caption = "bTwo"
End Sub

hope this helps.
SiebeAuthor Commented:
I was reffering to the API's like InsertMenu, AppendMenu, DrawMenuBar etc.. This since the menu has to be hooked into a different application...
Determine the Perfect Price for Your IT Services

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden with our free interactive tool and use it to determine the right price for your IT services. Download your free eBook now!

SiebeAuthor Commented:
Anyway, this is some basic code I have so far:

Public Function HookInMSN() As Long
    'Hook into MSN (if possible)
    Dim wMSN As Long, wNMenu As Long, wSubMenu As Long
    wMSN = FindWindow("MSNMSBLClass", vbNullString)
    If wMSN > 0 Then
        'Create the menu and fill it with items
        wNMenu = GetMenu(wMSN): DoEvents
        wSubMenu = CreatePopupMenu
        Call AppendMenu(wSubMenu, MF_STRING, Offset + 1, "Games")
        Call AppendMenu(wSubMenu, MF_STRING, Offset + 2, vbNullString)
        Call AppendMenu(wSubMenu, MF_STRING, Offset + 3, "About")
        Call AppendMenu(wSubMenu, MF_STRING, Offset + 4, "Exit")
        Call InsertMenu(wNMenu, 7, MF_BYPOSITION Or MF_POPUP, wSubMenu, "BOT2K3"): DoEvents
        'Draw the new menubar
        Call DrawMenuBar(wMSN)
        'Draw the subitems
        Call DrawSubItems(wNMenu)
        'Return true
        HookInMSN = wMSN
        'Return false
        HookInMSN = 0
    End If
End Function

Now I would like to know how I can create items under the subitem "Games":

........Trivial Pursuit
SiebeAuthor Commented:
Correction, at the place of

        'Draw the subitems
        Call DrawSubItems(wNMenu)

there should be nothing (temp. testing something).
You can do it the same way you did it in your "code". Just supply the itemid as the sub-menu you created. Example below.  Be warned though, you'll need the call-back function of the window procedure to be in a DLL to receive WM_COMMAND messages to know when they click on your menus. :)

Private Const MF_BYPOSITION = &H400&
Private Const MF_POPUP = &H10&
Private Const MFT_STRING = &H0

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 CreatePopupMenu Lib "user32" () As Long
Private Declare Function DrawMenuBar Lib "user32" (ByVal hWnd As Long) As Long
Private Declare Function GetMenu Lib "user32" (ByVal hWnd As Long) As Long
Private Declare Function GetSubMenu Lib "user32" (ByVal hMenu As Long, ByVal nPos As Long) As Long
Private Declare Function InsertMenu Lib "user32" Alias "InsertMenuA" (ByVal hMenu As Long, ByVal nPosition As Long, ByVal wFlags As Long, ByVal wIDNewItem As Long, ByVal lpNewItem As Any) As Long

Private Sub Form_Load()
    Dim hMenu As Long, hSubMenu As Long, hSubSubMenu As Long
    hMenu = GetMenu(Me.hWnd)
    hSubMenu = CreatePopupMenu
    hSubSubMenu = CreatePopupMenu
    Call AppendMenu(hSubSubMenu, MF_STRING, 1, "Game1")
    Call AppendMenu(hSubSubMenu, MF_STRING, 1, "Game2")
    Call AppendMenu(hSubMenu, MF_POPUP, hSubSubMenu, "Games")
    Call AppendMenu(hSubMenu, MF_STRING, 2, vbNullString)
    Call AppendMenu(hSubMenu, MF_STRING, 3, "About")
    Call AppendMenu(hSubMenu, MF_STRING, 4, "Exit")
    Call InsertMenu(hMenu, 0, MF_BYPOSITION Or MF_POPUP, hSubMenu, "BOT2K3")
    Call DrawMenuBar(Me.hWnd)
End Sub

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial

I've been using this control:


that lets you do what you need (and other things, also).
Since it is open source, it may be useful for you, too.

SiebeAuthor Commented:

how do you hook the created menu to an existing application - say notepad?  I have tried adding my own menu to notepad, but the problem is I don't know how to run a function/code when they click my menu.


It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.