Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

dinamically generated sub menuitems?

Status
Not open for further replies.

gabster

Programmer
Oct 23, 2001
192
0
0
US
Hi all...

I am in a big dilemma and i would need some of your suggestions.

I have an app where one of the menu items will have dynamically generated sub-menu items (collected from an array, etc.).

I figured how to make a control array in the menu editor, and I just set the captions and make those sub-menus visible or not.

example:

For i = 0 To x
mnuTest.Item(i).Caption = arrTempTrOpt(i)
mnuTest(i).Visible = True
Next

Where mnuTest(i) is my menu control array built with the Menu Editor.
arrTempTrOpt(i) is the array for the manu captions.

The problem comes if I want to add a sub-menu to those dynamically generated sub-menus.

Here is a diagram to explain myself:


Tools(main menu item on the menu-bar)
|
|_Submenu 01
| |_Item A
| |_Item B
| |_Item C
|
|_Submenu 02
| |_Item A
| |_Item B
| |_Item C
|
|_Submenu 03
|_Item A
|_Item B
|_Item C



1. As you see, "Submenu 01 - Submenu 03" are my dynamically generated submenu items. Their caption is set whith whatever value I am getting from my array (those values are coming from a server in a delimited string)

2. The sub-menus (Item A-Item C) of the "Submenu 01 - Submenu 03" have the same captions for all 3 submenus same order, etc. The only thing is they will point to different subs.

So I don't know what's the best strategy for this, where to start, etc.

Examples are MORE than welcome!

Thanks a lot,
Gabi.

 
For i = 0 To X
Load sMenu(i)
sMenu(i).Caption = "Dynamic " & i
Next i

If Err.Number = 360 Then
'Menu object already loaded
'Your code ............

 
I think you're saying that you want to dynamically create submenus? You'll have to look into the InsertMenu API and other Menu-related API's to create it.


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
 
thanks a lot ponerse and HJLDoc...

API calls sounds good! I'll look into. Might be back for questions...

Take care,
gabi.

 
Actually the API would not be necessary if you create a generic subMenu with an index of zero in each menu branch. Looping through that subMenu by index starting with zero will allow you to add menus and configure captions and properties etc as required. The API would be required if you do not initialize a subMenu array.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top