Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 571
  • Last Modified:

Add dynamic submenu to dynamic item of top-level menu

Hello all!

I've created one top-level menu item (mnuPad(0)) and one submenu item (mnuBar(0)) in menu designer. I use such code to use dynamic menu:

Private Sub cmdAddMenu_Click
   Load mnuPad(mnuPad.Count)
   'bla-bla-bla
End Sub

Private Sub cmdAddSubMenu_Click
   Load mnuBar(mnuBar.Count)
   'bla-bla-bla
End Sub

All new submenu items added to first top-level menu item (mnuPad(0)). How can I add submenu to other top-level items (mnuPad(1), mnuPad(2),..)?
0
BlackShark
Asked:
BlackShark
  • 10
  • 9
  • 3
  • +1
1 Solution
 
KDivadCommented:
I don't think you can do this using menu arrays in VB. You may have to break down and use API to make your menus.
0
 
KDivadCommented:
<<... use API to make your menus. >>

Which I've never done, so I can't help you there.
0
 
BlackSharkAuthor Commented:
Hello KDivad,

Thanks, but I would like to put all my code into mnuBar_Click. If it's impossible I have to change a lot of my subs.
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
Éric MoreauSenior .Net ConsultantCommented:
0
 
BlackSharkAuthor Commented:
hi emoreau,

thanks, but
1) vb5 runtime files are required
2) "Load will successfully add a new menu, but the menu will not be under cPopMenu's control and you will not be able to set icons for it."

still looking for solution using standard menu. dont offer a toolbar with button_click please.
0
 
Éric MoreauSenior .Net ConsultantCommented:
1) only msvbvm50.dll is required and in most case will already be there.
2) you didn't ask for icons!
0
 
BlackSharkAuthor Commented:
2 emoreau
1) i have msvbvm50.dll in C:\WINNT\system32, but control does not work :(
2) sorry, i was wrong. i can't read only type :)
0
 
Éric MoreauSenior .Net ConsultantCommented:
Have you read: http://vbaccelerator.com/install.htm

Have you downloaded
From the http://vbaccelerator.com/codelib/cpopmenu/cnewmenu.htm page:
<Before you Begin    
   These projects require the SSubTmr.DLL component. Make sure you have loaded and registered this before trying any project.  >
0
 
BlackSharkAuthor Commented:
2 emoreau.
sorry, can't read only type :)
thank you very much!
please give your points at http://www.experts-exchange.com/jsp/qShow.jsp?ta=visualbasic&qid=20155808
(hope it's correct url)

still looking for solution using standard menu
0
 
Éric MoreauSenior .Net ConsultantCommented:
The standard menu can items loaded at run-time if you use menu arrays but a sub-menu cannot be created on a newly created item.
0
 
BlackSharkAuthor Commented:
are you absolutely sure?
0
 
Éric MoreauSenior .Net ConsultantCommented:
I am sure because the parent of the child menu is the form (test it with mnubar(0).parent.caption).
0
 
BlackSharkAuthor Commented:
i know about this. but i am not sure still.
0
 
KDivadCommented:
emoreau,

<<... parent of the child menu ...>>

If that's the case, then can the parent be changed? I know it can be done with other controls but you need the hWnd for SetParent. Any thoughts?
0
 
Éric MoreauSenior .Net ConsultantCommented:
But a menu is not a parent!
0
 
BlackSharkAuthor Commented:
2emoreau,
the PlanetsSource code looks nice. But there is only dublication of submenus in the sample. Do you have any ideas how to remake it for my needs?
0
 
Éric MoreauSenior .Net ConsultantCommented:
No!
0
 
GrahamAtJobserveCommented:
OK so this isnt an answer, but could be a very good workaround.

If there are only going to be a limited number of the TOP level menus, you could create them ALL at design time , with a sub-menu each.

Hey presto, when loading the sub-menu items, they will be under the appropriate Top level menu, and you can just make the unwanted toplevel menu items invisible.

Graham.
0
 
Éric MoreauSenior .Net ConsultantCommented:
<OK so this isnt an answer,>

Why have you posted it as an answer? Since you are new here, take some time to read http://www.experts-exchange.com/jsp/cmtyQuestAnswer.jsp
0
 
BlackSharkAuthor Commented:
2emoreau,
sorry.. still playing with samples. how many points do i owe you for links?

2GrahamAtJobserve,
sorry, it a wrong way.

prob is not solved
0
 
GrahamAtJobserveCommented:
Emoreau and Black..

No, its not an answer, but it IS a solution to a problem, after all most applications only have a few top-level menu items, probably about 20 as a maximum. Theres more than 1 way to skin a cat, and in this case I'd make sure that there were only up to 20 top level menus. Presumably theres some sort of database or text file that will be used to populate your menus. Can you control this so that its limited to 20 top levels only?

Black shark..
Thinking a bit more, it definiately IS possible to do this. After all, its what VB is doing for us behind the scenes. If you have a helpful C programmer(unlikely I know) and an API book to hand, then you may be able to do it. Might be far more trouble than its worth though, and not something I'd fancy doing myself so I'll wish you luck on that one.

Graham.


0
 
BlackSharkAuthor Commented:
2GrahamAtJobserve,
thanks.
waiting for api guru
0
 
Éric MoreauSenior .Net ConsultantCommented:
<2emoreau,
sorry.. still playing with samples. how many points do i owe you for links? >

Nothing!
0

Featured Post

Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

  • 10
  • 9
  • 3
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now