Results 1 to 5 of 5

Thread: Creating menus at run time

  1. #1

    Thread Starter
    New Member
    Join Date
    Feb 2000
    Location
    London, UK
    Posts
    6

    Unhappy


    I need to be able to create a control array of menu items created dynamically in code rather than at design time using the menu editor.

    Any help gratefully received!

    Matt
    --
    Matt Jones

  2. #2
    Guest

    Talking

    Have all the option on the menu and set them to invisible... when you need.. make them visible

  3. #3
    Guest
    Try this:

    Code:
    'Code from Megatron
    
    
    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 DestroyMenu Lib "user32" (ByVal hMenu As Long) As Long
    Private Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long
    Private Declare Function TrackPopupMenu Lib "user32" (ByVal hMenu As Long, ByVal wFlags As Long, ByVal x As Long, ByVal y As Long, ByVal nReserved As Long, ByVal hwnd As Long, ByVal lprc As Any) As Long
    Const MF_STRING = &H0&
    Private Type POINTAPI
        x As Long
        y As Long
    End Type
    Private hMenu As Long
    Private PT As POINTAPI
    
    Private Sub Form_Load()
        hMenu = CreatePopupMenu()
        AppendMenu hMenu, MF_STRING, 0, "New Menu"
    End Sub
    
    Private Sub Form_MouseUp(Button As Integer, Shift As Integer, x As Single, y As Single)
        Call GetCursorPos(PT)
        If Button = 2 Then
            TrackPopupMenu hMenu, 0, PT.x, PT.y, 0, hwnd, 0&
        End If
    End Sub
    
    Private Sub Form_Unload(Cancel As Integer)
        DestroyMenu hMenu
    End Sub

  4. #4
    Frenzied Member
    Join Date
    Jan 2000
    Location
    Bellevue, WA, USA
    Posts
    1,357

    Try this article for your answer...

    http://msdn.microsoft.com/library/de...satruntime.htm

    Tells you how to do it. If you haven't already, bookmark MSDN's web site. It is an invaluable source of information for programming questions!

    Hope that helps,
    ~seaweed

  5. #5
    Guest
    You said you wanted to create it from a Control Array? In order to do this, you must have at least one instance of that menu.

    Make a menu with a sub menu and call the sub menu mnuSub. Add the following code to a CommandButton to allow for more menus to be added.
    Code:
    Private Sub Command1_Click()
    
        i = mnuSub.Count
        Load mnuSub(i)
        mnuSub(i).Caption = "New Menu"
        
    End Sub

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width