Option ExplicitDemikian Class ListBox untuk memilih item melalui klik kanan pada VB6, semoga bermanfaat.
Private WithEvents lst As ListBox
Private Type POINTAPI
X As Long
Y As Long
End Type
Private Const LB_ITEMFROMPOINT As Long = &H1A9
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 Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (Destination As Any, Source As Any, ByVal Length As Long)
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
Public Function LoWord(dwValue As Long) As Integer
CopyMemory LoWord, dwValue, 2
End Function
Public Function MAKELONG(wLow As Long, wHigh As Long) As Long
MAKELONG = LoWord(wLow) Or (&H10000 * LoWord(wHigh))
End Function
Public Function MAKELPARAM(wLow As Long, wHigh As Long) As Long
MAKELPARAM = MAKELONG(wLow, wHigh)
End Function
Public Property Let ListBox(New_List As ListBox)
Set lst = New_List
End Property
Private Sub lst_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
If Button = vbRightButton Then
Dim lParam As Long
Dim curritem As Long
Dim r As Long
Dim pt As POINTAPI
Call GetCursorPos(pt)
Call ScreenToClient(lst.hWnd, pt)
lParam = MAKELPARAM(pt.X, pt.Y)
r = SendMessage(lst.hWnd, LB_ITEMFROMPOINT, 0&, ByVal lParam)
If r > -1 Then
curritem = LoWord(r)
lst.Selected(curritem) = True
End If
End If
End Sub
Thursday, June 14, 2012
Class ListBox - Untuk Memilih Item Pada Saat Klik Kanan
Labels:
ListBox