Link to home
Start Free TrialLog in
Avatar of Siebe
Siebe

asked on

Dynamicly adding sub-sub menu's

Hi, I've checked out this topic:

https://www.experts-exchange.com/questions/20393997/Add-menu-sub-items-dynamically.html

and I managed to get a layout like:

file
 \_ open
 \_ save
 \_ exit

BUT, do you have any idea how to create a menu layout like

file
 \_ new
        \_ normal
        \_ template
 \_ open
 \_ save

(I hope my scheme's make any sence).. Thanks in advance!
Avatar of wuttrain
wuttrain

I usually do this:

Main
....One
.........aOne
....Two
.........aTwo

Be sure that the index property of aOne and aTwo menu items are set to 0.

Then try the code below.

Option Explicit

Private Sub Command1_Click()
  Load mnuaOne(1)
  mnuaOne(1).Visible = True
  mnuaOne(1).Caption = "bOne"
  Load mnuaOne(2)
  mnuaOne(2).Visible = True
  mnuaOne(2).Caption = "cOne"
 
  Load mnuaTwo(1)
  mnuaTwo(1).Visible = True
  mnuaTwo(1).Caption = "bTwo"
End Sub

hope this helps.
Avatar of Siebe

ASKER

I was reffering to the API's like InsertMenu, AppendMenu, DrawMenuBar etc.. This since the menu has to be hooked into a different application...
Listening
Avatar of Siebe

ASKER

Listening?
Anyway, this is some basic code I have so far:

Public Function HookInMSN() As Long
    'Hook into MSN (if possible)
    Dim wMSN As Long, wNMenu As Long, wSubMenu As Long
    wMSN = FindWindow("MSNMSBLClass", vbNullString)
   
    If wMSN > 0 Then
        'Create the menu and fill it with items
        wNMenu = GetMenu(wMSN): DoEvents
        wSubMenu = CreatePopupMenu
       
        'Items...
        Call AppendMenu(wSubMenu, MF_STRING, Offset + 1, "Games")
        Call AppendMenu(wSubMenu, MF_STRING, Offset + 2, vbNullString)
        Call AppendMenu(wSubMenu, MF_STRING, Offset + 3, "About")
        Call AppendMenu(wSubMenu, MF_STRING, Offset + 4, "Exit")
        Call InsertMenu(wNMenu, 7, MF_BYPOSITION Or MF_POPUP, wSubMenu, "BOT2K3"): DoEvents
   
        'Draw the new menubar
        Call DrawMenuBar(wMSN)
       
        'Draw the subitems
        Call DrawSubItems(wNMenu)
       
        'Return true
        HookInMSN = wMSN
    Else
        'Return false
        HookInMSN = 0
    End If
End Function

Now I would like to know how I can create items under the subitem "Games":

BOT2K3
....Games
........PimPamPet
........Trivial Pursuit
....---
....About
....Exit
Avatar of Siebe

ASKER

Correction, at the place of

        'Draw the subitems
        Call DrawSubItems(wNMenu)

there should be nothing (temp. testing something).
ASKER CERTIFIED SOLUTION
Avatar of zzzzzooc
zzzzzooc

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

I've been using this control:

http://www.vbaccelerator.com/home/VB/Code/Controls/Menus/Icon_Menu_Control/article.asp

that lets you do what you need (and other things, also).
Since it is open source, it may be useful for you, too.

HTH
M.
Avatar of Siebe

ASKER

Cheers!
siebe,

how do you hook the created menu to an existing application - say notepad?  I have tried adding my own menu to notepad, but the problem is I don't know how to run a function/code when they click my menu.

thanks!

wuttrain