Solved

Dynamicly adding sub-sub menu's

Posted on 2003-11-05
9
376 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
[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
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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 

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

Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

Question has a verified solution.

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

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…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
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…
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…
Suggested Courses
Course of the Month10 days, 9 hours left to enroll

631 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