Option Explicit
Private Declare Function SendMessage Lib "user32" _
Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg _
As Long, ByVal wParam As Long, lParam As Any) As Long
Private Const LB_GETSELITEMS = &H191
Private Sub Command1_Click()
Dim ItemIndexes() As Long, x As Integer, iNumItems As Integer
iNumItems = List1.SelCount
If iNumItems Then
ReDim ItemIndexes(iNumItems - 1)
SendMessage List1.hwnd, LB_GETSELITEMS, iNumItems, ItemIndexes(0)
End If
For x = 0 To iNumItems - 1
MsgBox List1.List(ItemIndexes(x)) '弹出对话框
Next x
End Sub
Private Sub Form_Load()
Dim i As Integer
With List1
For i = 0 To 10
.AddItem "Item " & i
Next
End With
End Sub
After being passed to the SendMessage function, iNumItems holds the total number of selected items, and the ItemIndexes array holds the selected item index values. Notice, that you must pass a pointer to the ItemIndexes array, and not the array itself. Thus, we passed ItemIndexes(0) into the SendMessage function, not ItemIndexes().