Option Explicit
Private Declare Function SendMessage _
Lib "user32" Alias "SendMessageA" ( _
ByVal hwnd As Long, ByVal wMsg As Long, _
ByVal wParam As Long, ByVal lParam As Long) As Long
Private Const LB_ITEMFROMPOINT = 425
Private Sub Form_Load()
Dim i As Long
For i = 0 To 10
List1.AddItem i
Next i
End Sub
Private Sub List1_MouseMove( _
Button As Integer, Shift As Integer, X As Single, Y As Single)
Dim X_ As Integer, Y_ As Integer
Dim Coord As Long
Dim RetVal As Long
X_ = X \ Screen.TwipsPerPixelX
Y_ = Y \ Screen.TwipsPerPixelY
Coord = MakeDWord(X_, Y_)
RetVal = SendMessage( _
List1.hwnd, LB_ITEMFROMPOINT, 0&, Coord)
If HiWord(RetVal) = 1 Then
'Курсора е извън list box-a -> outside the client area
End If
If HiWord(RetVal) = 0 Then
Me.Caption = List1.List(LoWord(RetVal))
End If
End Sub
Function MakeDWord(LoWord As Integer, HiWord As Integer) As Long
MakeDWord = (HiWord * &H10000) Or (LoWord And &HFFFF&)
End Function
Function LoWord(DWord As Long) As Integer
If DWord And &H8000& Then ' &H8000& = &H00008000
LoWord = DWord Or &HFFFF0000
Else
LoWord = DWord And &HFFFF&
End If
End Function
Function HiWord(DWord As Long) As Integer
HiWord = (DWord And &HFFFF0000) \ &H10000
End Function
Редактирано от Щиpлиц на 30.09.03 20:28.