Solved

Add dynamic submenu to dynamic item of top-level menu

Posted on 2001-07-21
24
560 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 10
  • 9
  • 3
  • +1
24 Comments
 
LVL 5

Expert Comment

by:KDivad
ID: 6304996
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
ID: 6304997
<<... use API to make your menus. >>

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

Author Comment

by:BlackShark
ID: 6305019
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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 70

Expert Comment

by:Éric Moreau
ID: 6305032
0
 

Author Comment

by:BlackShark
ID: 6305798
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 70

Expert Comment

by:Éric Moreau
ID: 6310018
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
ID: 6310119
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 70

Expert Comment

by:Éric Moreau
ID: 6310346
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
ID: 6310575
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 70

Accepted Solution

by:
Éric Moreau earned 300 total points
ID: 6310680
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
ID: 6310726
are you absolutely sure?
0
 
LVL 70

Expert Comment

by:Éric Moreau
ID: 6310765
I am sure because the parent of the child menu is the form (test it with mnubar(0).parent.caption).
0
 

Author Comment

by:BlackShark
ID: 6310787
i know about this. but i am not sure still.
0
 
LVL 70

Expert Comment

by:Éric Moreau
ID: 6310809
0
 
LVL 5

Expert Comment

by:KDivad
ID: 6310830
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 70

Expert Comment

by:Éric Moreau
ID: 6312093
But a menu is not a parent!
0
 

Author Comment

by:BlackShark
ID: 6312595
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 70

Expert Comment

by:Éric Moreau
ID: 6313154
No!
0
 

Expert Comment

by:GrahamAtJobserve
ID: 6313422
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 70

Expert Comment

by:Éric Moreau
ID: 6313509
<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
ID: 6313905
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
ID: 6316462
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
ID: 6316490
2GrahamAtJobserve,
thanks.
waiting for api guru
0
 
LVL 70

Expert Comment

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

Nothing!
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
MsgBox 2 64
Excel - Save a copy of work book 13 95
Set WorkSheet  not Working 9 62
why PtrSafe before Function on 64bit does not fix the APIs? 2 24
There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…

738 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