Solved

Dynamicly adding sub-sub menu's

Posted on 2003-11-05
9
328 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
 

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
Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

 

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

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

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…
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…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

746 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

11 Experts available now in Live!

Get 1:1 Help Now