Results 1 to 5 of 5

Trying to understand PopUp Menus!

Threaded View

  1. #1
    Registered User
    Join Date
    04-02-2012
    Location
    Guatemala, Guatemala
    MS-Off Ver
    Excel 2010
    Posts
    31

    Trying to understand PopUp Menus!

    Hi All!

    I'm an amateur programmer and just recently came across a piece of code to build popup menus with the right-click of the mouse. It works!, I think I can adapt it and use it to enhance my own code however, since I don't fully understand how it works, I'd feel like the Apes in Planet of the apes when they pulled a car with horses not knowing any better . What I understand is this:

    1) A bunch of functions (I think, pre-built for usage on almost any programming language) are used to build the menu, destroy it when no longer needed, etc.
    2) There are other ways to build the PopUp menus, I think, but I'm not sure if they would be quiet as effective or at least as easy and flexible to use.
    3) What really confuses me the most is the usage of things like: * <-----------------------

    Private Type POINTAPI
        X As Long
        Y As Long
    End Type
    '
    Private Declare Function CreatePopupMenu Lib "user32" () As Long
    Private Declare Function TrackPopupMenuEx Lib "user32" _
            (ByVal hMenu As Long, ByVal wFlags As Long, ByVal X As Long, ByVal Y As Long, _
    ByVal hWnd As Long, ByVal lptpm As Any) As Long
    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 DestroyMenu Lib "user32" (ByVal hMenu As Long) As Long
    Private Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long
    Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" _
            (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
    '
    Const MF_CHECKED = &H8&         '   <------------------------------------     THIS IS SO WEIRD, WELL, AT LEAST FOR ME HEHEHE.
    Const MF_APPEND = &H100&        '   <------------------------------------     THIS IS SO WEIRD, WELL, AT LEAST FOR ME HEHEHE.
    Const TPM_LEFTALIGN = &H0&      '   <------------------------------------     THIS IS SO WEIRD, WELL, AT LEAST FOR ME HEHEHE.
    Const MF_SEPARATOR = &H800&     '   <------------------------------------     THIS IS SO WEIRD, WELL, AT LEAST FOR ME HEHEHE.
    Const MF_STRING = &H0&          '   <------------------------------------     THIS IS SO WEIRD, WELL, AT LEAST FOR ME HEHEHE.
    Const TPM_RETURNCMD = &H100&    '   <------------------------------------     THIS IS SO WEIRD, WELL, AT LEAST FOR ME HEHEHE.
    Const TPM_RIGHTBUTTON = &H2&    '   <------------------------------------     THIS IS SO WEIRD, WELL, AT LEAST FOR ME HEHEHE.
    '
    Dim hMenu As Long
    Dim hWnd As Long
    '
    Private Sub UserForm_Initialize()
        hWnd = FindWindow(vbNullString, Me.Caption)
    End Sub
    '
    Private Sub UserForm_MouseUp(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
     Dim Pt As POINTAPI
        Dim ret As Long
        If Button = 2 Then
            hMenu = CreatePopupMenu()
            AppendMenu hMenu, MF_STRING, 1, "Menu - 1"
            AppendMenu hMenu, MF_STRING, 2, "Menu - 2"
            AppendMenu hMenu, MF_SEPARATOR, 3, ByVal 0&
            AppendMenu hMenu, MF_STRING, 4, "About"
            GetCursorPos Pt
            ret = TrackPopupMenuEx(hMenu, TPM_LEFTALIGN Or TPM_RETURNCMD Or _
                                   TPM_RIGHTBUTTON, Pt.X, Pt.Y, hWnd, ByVal 0&)
            DestroyMenu hMenu
            
                Select Case ret
                    Case 1
                    Call MenuProc1
                    Case 2
                    Call MenuProc2
                    Case 4
                    Call MenuProc3
                End Select
        End If
    End Sub
    '
    Private Sub MenuProc1()
        MsgBox "PopUp menu-1 is activated !"
    End Sub
    '
    Private Sub MenuProc2()
        MsgBox "PopUp menu-2 is activated !"
    End Sub
    '
    Private Sub MenuProc3()
        MsgBox "Prepared by Raider ®"
    End Sub
    MF_SEPARATOR = &H800& <---------- What is this? some sort of hexadecimal notation? what is it used for? is there any advantage for using this?

    for any help or guidance Thanks a lot !



















    Const MF_SEPARATOR = &H800&, then later a parameter in other words, why the need of constants instead of just
    Last edited by Leith Ross; 09-07-2012 at 08:42 PM. Reason: Set Type Size To Normal

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1