Link to home
Start Free TrialLog in
Avatar of StewartJ
StewartJ

asked on

Creating SubMenus at RunTime in VB6

In VB6, I need to dynamically create submenus which themselves have submenus so as to achieve something like :

File
    Recent Doc 1
         Open
         Print
         Delete
    Recent Doc 2
         Open
....

etc depending on how many docs (or whatever) found

I can create the first level (Recent Doc x) easily using the InsertMenuItem API and sub-class to detect when it's clicked but I can't get a handle to it from GetSubMenu so as to be able to insert the next level (Open / Print etc).  Thus,

    InsertMenuItem ByVal l_hFileMenu, ByVal 1, ByVal True, l_uMenuInfo
    l_hSubMenu = GetSubMenu(ByVal l_hFileMenu, ByVal 0)

l_hSubMenu always is returned as zero regardless of the value of the position parameter.

Any advice would be much appreciated.
Avatar of Dirk Haest
Dirk Haest
Flag of Belgium image

Avatar of StewartJ
StewartJ

ASKER

Thanks for the quick reply, but this only works at the first level.  I need to add further submenus to those that I create.  So, I will create an item 'File1' but, when the user clicks it, I want a further submenu to appear, for example, giving her the options of 'Edit', 'Print' or 'Delete'.
Hi StewartJ:
https://www.experts-exchange.com/questions/20800278/How-do-I-add-subitems-to-a-at-runtime-generated-popup-menu.html "How do I add subitems to a at runtime generated popup menu"


Dabas
Thanks, this is what I am doing but I can get it to work only for one level.  I cannot find any way to get the handle of the item that I've added so that I can give IT further sub-menus.
StewartJ:
I suppose upgrading to .NET is out of the question?
Its quite easy there as illustrated in my answer in https://www.experts-exchange.com/questions/21051123/Dynamically-implementing-a-context-menu-on-a-grpBox's-button-click-event-in-VB-NET.html "Dynamically implementing a context menu on a grpBox's button click event in VB.NET"


Dabas
On this occassion, regrettably not !
SOLUTION
Avatar of dbrckovi
dbrckovi
Flag of Croatia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
That looks promising, thanks.  I have an urgent task to complete at the moment but will try it later and report results.
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
That looks good too, but Morpheus has caught up with me as well!  I'll get back to it tomorrow.  Thanks all for your help.