Results 1 to 3 of 3

Thread: Menu at Runtime

  1. #1

    Thread Starter
    Hyperactive Member Dorothy's Avatar
    Join Date
    Feb 2001
    Posts
    310

    Question

    How do I add a menu item to an already existing menu at runtime?

  2. #2
    Frenzied Member Vlatko's Avatar
    Join Date
    Aug 2000
    Location
    Skopje, Macedonia
    Posts
    1,409
    use the
    Code:
    Private Declare Function GetMenu Lib "user32" (ByVal hWnd As Long) As Long
    Private Declare Function GetMenuItemID Lib "user32" (ByVal hMenu As Long, ByVal nPos As Long) As Long
    Private Declare Function GetSubMenu Lib "user32" (ByVal hMenu As Long, ByVal nPos As Long) As Long
    to get the menu handle(hmenu) and than use AppendMenu API.
    Code:
    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
    Const MF_CHECKED = &H8&
    Const MF_APPEND = &H100&
    Const TPM_LEFTALIGN = &H0&
    Const MF_DISABLED = &H2&
    Const MF_GRAYED = &H1&
    Const MF_SEPARATOR = &H800&
    Const MF_STRING = &H0&
      AppendMenu hMenu, MF_STRING, ByVal 0&, "Hello !"
        AppendMenu hMenu, MF_GRAYED Or MF_DISABLED, ByVal 0&, "Testing ..."
        AppendMenu hMenu, MF_SEPARATOR, ByVal 0&, ByVal 0&
        AppendMenu hMenu, MF_CHECKED, ByVal 0&, "TrackPopupMenu"
    I am become death, the destroyer of worlds.
    mail:[email protected]

    • Visual Basic 6.0 & .NET
    • Visual C++ 6.0 & .NET
    • ASP
    • LISP
    • PROLOG
    • C
    • Pascal

  3. #3

    U can code like this..

    'First take a menu name it mnuFile then under it take a sub menu mnuFirst setting its Index property to 0 then add the below code to a command button.



    Private Sub Command1_Click()
    Static i As Integer
    i = i + 1
    Load mnuFirst(i)
    mnuFirst(i).Visible = True
    mnuFirst(i).Caption = "Menu Number" & i
    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