How I add a menuitem to a new submenu ?

I have a problem with adding a menuitem to new submenu or new subsubmenu at run time, specially handling the parameters in AppendMenu-API-function and other API-functions for creating menu.

First I created three menuitems in menubar at design time with the menu editor. In the third menubaritem I created a new menuitem, first with index = 0

hMenu0 = GetMenu(Me.hWnd)
hSubMenu0 = GetSubMenu(hMenu0, 2) '2 = Third Menuitem in the menubar
b = AppendMenu(hSubMenu0, MF_POPUP, hMenu1, "1")

Where I find the handling result for going on ? Do I find it in hmenu1 ?
What I have to do with that to add a submenu to the first new added item in this submenu.
Can anyone either point me to some code which shows how to realize it, or maybe indicate what I'm doing wrong.
kairaviAsked:
Who is Participating?
 
MarineConnect With a Mentor Commented:
You can't do that chengman. There is no way VB can add a submenuitem. He needs to use API's to do so. I'll post an answer in a bit later. I have a code lieing around someplace here.
0
 
chengmanCommented:
Why so difficult.
You're adding a new menuitem on a submenu. You can do this with creating a Menu control array and using the Load keyword.

You first create a sub-sub menuitem with index 0 menubar at design time with the menu editor.

You can add a new menu item like this

    Dim nNrItems As Integer
    nNrItems = mnuSubSub.Count
    nNrItems = nNrItems + 1
    Load mnuSubSub(nNrItems)
    mnuSubSub(nNrItems).Caption = mnuSubSub(0).Caption & CStr(nNrItems)

0
 
twardCommented:
It seems to work the way you have it, as long as you have at least ONE menu option under the main drop down menu.

What I would suggest is to put at least one menu item under the drop down menu and them use the ModifyMenu API Call to simply modify the first one, then use the AppendMenu to add other menu items.
0
Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

 
kairaviAuthor Commented:
Please explain, how to use the API-function AppendMenu to add other menu items in a subsubmenu. I have no idear how I set the parameters or handle it.
0
 
kairaviAuthor Commented:
You're right. Please post me sample code as quick as possible.
Maybe you send it directly to kairavi@gmx.net.
My problems begins at run time !
Please explain, how to use the API-function AppendMenu to add other menu items in a subsubmenu. I have no idear how I set the parameters or handle it.
0
 
chengmanCommented:
In VB6 (no idea if it works with older versions) you can add menuitems dynamically just the same way as  adding  other controls dynamically.
That means in designtime create a control or menu with index 0 and in runtime add new control or menuitems with the Load command.

I will eat my shoe if it doesn't work

0
All Courses

From novice to tech pro — start learning today.