Solved

Add dynamic submenu to dynamic item of top-level menu

Posted on 2001-07-21
24
547 Views
Last Modified: 2008-01-09
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
Comment
Question by:BlackShark
  • 10
  • 9
  • 3
  • +1
24 Comments
 
LVL 5

Expert Comment

by:KDivad
Comment Utility
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
 
LVL 5

Expert Comment

by:KDivad
Comment Utility
<<... use API to make your menus. >>

Which I've never done, so I can't help you there.
0
 

Author Comment

by:BlackShark
Comment Utility
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
 
LVL 69

Expert Comment

by:Éric Moreau
Comment Utility
0
 

Author Comment

by:BlackShark
Comment Utility
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
 
LVL 69

Expert Comment

by:Éric Moreau
Comment Utility
1) only msvbvm50.dll is required and in most case will already be there.
2) you didn't ask for icons!
0
 

Author Comment

by:BlackShark
Comment Utility
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
 
LVL 69

Expert Comment

by:Éric Moreau
Comment Utility
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
 

Author Comment

by:BlackShark
Comment Utility
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
 
LVL 69

Accepted Solution

by:
Éric Moreau earned 300 total points
Comment Utility
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
 

Author Comment

by:BlackShark
Comment Utility
are you absolutely sure?
0
 
LVL 69

Expert Comment

by:Éric Moreau
Comment Utility
I am sure because the parent of the child menu is the form (test it with mnubar(0).parent.caption).
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 

Author Comment

by:BlackShark
Comment Utility
i know about this. but i am not sure still.
0
 
LVL 69

Expert Comment

by:Éric Moreau
Comment Utility
0
 
LVL 5

Expert Comment

by:KDivad
Comment Utility
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
 
LVL 69

Expert Comment

by:Éric Moreau
Comment Utility
But a menu is not a parent!
0
 

Author Comment

by:BlackShark
Comment Utility
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
 
LVL 69

Expert Comment

by:Éric Moreau
Comment Utility
No!
0
 

Expert Comment

by:GrahamAtJobserve
Comment Utility
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
 
LVL 69

Expert Comment

by:Éric Moreau
Comment Utility
<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
 

Author Comment

by:BlackShark
Comment Utility
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
 

Expert Comment

by:GrahamAtJobserve
Comment Utility
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
 

Author Comment

by:BlackShark
Comment Utility
2GrahamAtJobserve,
thanks.
waiting for api guru
0
 
LVL 69

Expert Comment

by:Éric Moreau
Comment Utility
<2emoreau,
sorry.. still playing with samples. how many points do i owe you for links? >

Nothing!
0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now