Solved

Dynamicly adding sub-sub menu's

Posted on 2003-11-05
9
345 Views
Last Modified: 2010-08-05
Hi, I've checked out this topic:

http://www.experts-exchange.com/Programming/Programming_Languages/Visual_Basic/VB_Controls/Q_20393997.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!
0
Comment
Question by:Siebe
9 Comments
 
LVL 2

Expert Comment

by:wuttrain
ID: 9686369
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.
0
 

Author Comment

by:Siebe
ID: 9686386
I was reffering to the API's like InsertMenu, AppendMenu, DrawMenuBar etc.. This since the menu has to be hooked into a different application...
0
 
LVL 9

Expert Comment

by:Dang123
ID: 9686581
Listening
0
Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

 

Author Comment

by:Siebe
ID: 9686609
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
0
 

Author Comment

by:Siebe
ID: 9686614
Correction, at the place of

        'Draw the subitems
        Call DrawSubItems(wNMenu)

there should be nothing (temp. testing something).
0
 
LVL 17

Accepted Solution

by:
zzzzzooc earned 250 total points
ID: 9686828
You can do it the same way you did it in your "code". Just supply the itemid as the sub-menu you created. Example below.  Be warned though, you'll need the call-back function of the window procedure to be in a DLL to receive WM_COMMAND messages to know when they click on your menus. :)

Private Const MF_BYPOSITION = &H400&
Private Const MF_POPUP = &H10&
Private Const MFT_STRING = &H0

Private Declare Function AppendMenu Lib "user32" Alias "AppendMenuA" (ByVal hMenu As Long, ByVal wFlags As Long, ByVal wIDNewItem As Long, ByVal lpNewItem As Any) As Long
Private Declare Function CreatePopupMenu Lib "user32" () As Long
Private Declare Function DrawMenuBar Lib "user32" (ByVal hWnd As Long) As Long
Private Declare Function GetMenu Lib "user32" (ByVal hWnd As Long) As Long
Private Declare Function GetSubMenu Lib "user32" (ByVal hMenu As Long, ByVal nPos As Long) As Long
Private Declare Function InsertMenu Lib "user32" Alias "InsertMenuA" (ByVal hMenu As Long, ByVal nPosition As Long, ByVal wFlags As Long, ByVal wIDNewItem As Long, ByVal lpNewItem As Any) As Long

Private Sub Form_Load()
    Dim hMenu As Long, hSubMenu As Long, hSubSubMenu As Long
    hMenu = GetMenu(Me.hWnd)
    hSubMenu = CreatePopupMenu
    hSubSubMenu = CreatePopupMenu
    Call AppendMenu(hSubSubMenu, MF_STRING, 1, "Game1")
    Call AppendMenu(hSubSubMenu, MF_STRING, 1, "Game2")
   
    Call AppendMenu(hSubMenu, MF_POPUP, hSubSubMenu, "Games")
    Call AppendMenu(hSubMenu, MF_STRING, 2, vbNullString)
    Call AppendMenu(hSubMenu, MF_STRING, 3, "About")
    Call AppendMenu(hSubMenu, MF_STRING, 4, "Exit")
    Call InsertMenu(hMenu, 0, MF_BYPOSITION Or MF_POPUP, hSubMenu, "BOT2K3")
    Call DrawMenuBar(Me.hWnd)
End Sub
0
 
LVL 6

Expert Comment

by:marconovaro
ID: 9686895

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.
0
 

Author Comment

by:Siebe
ID: 9686950
Cheers!
0
 
LVL 2

Expert Comment

by:wuttrain
ID: 10658191
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
0

Featured Post

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

Suggested Solutions

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

813 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

10 Experts available now in Live!

Get 1:1 Help Now