Results 1 to 6 of 6

Thread: PopUpMenu?

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Aug 1999
    Posts
    22

    Post

    Hello,

    I am in search for a correct coding procedure for a pop up menu for a list box.

    The coding I am searching for will select an item from the listbox when your right click it. Also, when you right click the list for the menu to pop up, and then right click the list again, it will pop the menu up from the point you clicked at.

  2. #2
    Hyperactive Member
    Join Date
    Jul 1999
    Location
    NY, USA
    Posts
    270

    Post

    Make an invisible menu, call it lstMenu and use this code:

    Code:
    Private Sub List1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
        If Button = vbRightButton Then Me.PopupMenu lstMenu
    End Sub
    ------------------
    Tom Young, 14 Year Old
    tyoung@stny.rr.com
    ICQ: 15743470 Add Me ICQ Me
    AIM: TomY10
    PERL, JavaScript and VB Programmer

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Aug 1999
    Posts
    22

    Post

    that did not help me any better than where I was, that is nothing more than a generic command to pop a menu up on a list box

    what I am in search for is this. A pop up menu that will select the line you right clicked. second, when you right click once, then click once more with the menu already poped up...it will pop up

  4. #4
    Guru Aaron Young's Avatar
    Join Date
    Jun 1999
    Location
    Red Wing, MN, USA
    Posts
    2,176

    Post

    Try this:
    Code:
    Private Type POINTAPI
        x As Long
        y As Long
    End Type
    
    Private Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long
    Private Declare Function ScreenToClient Lib "user32" (ByVal hWnd As Long, lpPoint As POINTAPI) As Long
    Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Long) As Long
    
    Private Const LB_ITEMFROMPOINT = &H1A9
    
    Private Sub Form_Load()
        Dim iIndex As Integer
        For iIndex = 0 To 99
            List1.AddItem "Item" & iIndex
        Next
    End Sub
    
    Private Sub List1_MouseDown(Button As Integer, Shift As Integer, x As Single, y As Single)
        Dim tPOINT As POINTAPI
        Dim iIndex As Long
        
        If Button = vbRightButton Then
            Call GetCursorPos(tPOINT)
            Call ScreenToClient(List1.hWnd, tPOINT)
            iIndex = SendMessage(List1.hWnd, LB_ITEMFROMPOINT, 0&, ByVal ((tPOINT.x And &HFF) Or (&H10000 * (tPOINT.y And &HFF))))
            If iIndex > -1 Then
                iIndex = iIndex And &HFF
                If List1.Selected(iIndex) And Shift <> -1 Then
                    PopupMenu mnuPopup
                Else
                    List1.Selected(iIndex) = True
                End If
            End If
        End If
    End Sub
    
    Private Sub List1_MouseMove(Button As Integer, Shift As Integer, x As Single, y As Single)
        Call List1_MouseDown(Button, -1, x, y)
    End Sub

    ------------------
    Aaron Young
    Analyst Programmer
    aarony@redwingsoftware.com
    adyoung@win.bright.net

  5. #5

    Thread Starter
    Junior Member
    Join Date
    Aug 1999
    Posts
    22

    Post

    thank you mr young, but still the click feature for the popupmenu still will not corroperate...

  6. #6
    Guru Aaron Young's Avatar
    Join Date
    Jun 1999
    Location
    Red Wing, MN, USA
    Posts
    2,176

    Post

    I don't understand what it is you are trynig to achieve then?

    The code I posted will select a List Item if Right Clicked, if you then Right Click the item again, a Popup menu will appear. (Provided you have actually created the PopupMenu called mnuPopup

    ------------------
    Aaron Young
    Analyst Programmer
    aarony@redwingsoftware.com
    adyoung@win.bright.net

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