PDA

Click to See Complete Forum and Search --> : PopUpMenu?


m i k e l
Dec 3rd, 1999, 02:43 AM
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.

Compwiz
Dec 3rd, 1999, 02:48 AM
Make an invisible menu, call it lstMenu and use this 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 (http://wwp.icq.com/15743470) Add Me (http://wwp.icq.com/scripts/search.dll?to=15743470) ICQ Me (http://wwp.icq.com/scripts/contact.dll?msgto=15743470)
AIM: TomY10 (http://www.aol.com/aim/aim30.html)
PERL, JavaScript and VB Programmer

m i k e l
Dec 3rd, 1999, 02:52 AM
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

Aaron Young
Dec 3rd, 1999, 03:07 AM
Try this:

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

m i k e l
Dec 3rd, 1999, 03:24 AM
thank you mr young, but still the click feature for the popupmenu still will not corroperate...

Aaron Young
Dec 3rd, 1999, 03:27 AM
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