Option Explicit
'=======================================================
' Declarations
'=======================================================
Private Type lvwMsgInfo
x As Long
y As Long
Flgs As Long
Itm As Long
SubItm As Long
End Type
Private Declare Function SendMessage _
Lib "user32" Alias "SendMessageA" ( _
ByVal hwnd As Long, _
ByVal lMsg As Long, _
ByVal wParam As Long, _
lParam As Any) As Long
Dim lvwMsg As lvwMsgInfo
'=======================================================
' Procedures
'=======================================================
Private Sub ListView1_MouseDown(Button As Integer, _
Shift As Integer, x As Single, y As Single)
'Setup the API call
lvwMsg.x = x / Screen.TwipsPerPixelX
lvwMsg.y = y / Screen.TwipsPerPixelY
'Make the API call
SendMessage ListView1.hwnd, 4153, 0, lvwMsg
'Test for a valid click
If lvwMsg.Flgs And 14 Then
'The Item returned is 0 based and
' there is no 0 ListItem - so + 1
Label1 = "Item " & CStr(lvwMsg.Itm + 1)
'There is no such thing as SubItem 0
If lvwMsg.SubItm Then
Label1 = Label1 & ", SubItem " _
& CStr(lvwMsg.SubItm)
End If
End If
End Sub
Private Sub Form_Load()
'Position and size the controls
Move 1000, 1000, 4800, 3600
ListView1.Move 120, 120, 4440, 2500
Label1.Move 720, 2760, 2655, 375
Dim j%, k%
Dim l As ListItem
'Add the ListView ColumnHeaders
For j = 1 To 6
ListView1.ColumnHeaders.Add , , _
"Column " & CStr(j), 1000
Next
For j = 1 To 6
'Add a ListItem
Set l = _
ListView1.ListItems.Add(, , "Item " & CStr(j))
'Add the SubItems
For k = 1 To 5
l.ListSubItems.Add , , "SubItem " & CStr(k)
Next
Next
End Sub
|