From this thread. I just found it useful. Feel free to suggest a better title! :
VB Code:
Private Type POINTAPI x As Long y As Long End Type Private Type RECT Left As Long Top As Long Right As Long Bottom 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 ClientToScreen 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 Any) As Long Private Declare Function WindowFromPoint Lib "user32" (ByVal xPoint As Long, ByVal yPoint As Long) As Long Private Const LB_GETITEMRECT = &H198 Private Const LB_ITEMFROMPOINT = &H1A9 Public Function ItemFromPoint(ByRef oList As ListBox, ByVal x As Single, ByVal y As Single) As Long Dim tPOINT As POINTAPI Dim iIndex As Long 'Get the Mouse Cursor Position Call GetCursorPos(tPOINT) 'Convert the Coords to be Relative to the Listbox Call ScreenToClient(oList.hwnd, tPOINT) 'Find which Item the Mouse is Over iIndex = SendMessage(oList.hwnd, LB_ITEMFROMPOINT, 0&, ByVal ((tPOINT.x And &HFF) Or (&H10000 * (tPOINT.y And &HFF)))) 'Extract the List Index ItemFromPoint = iIndex And &HFF End Function Private Sub Form_Load() Dim iIndex As Integer For iIndex = 1 To 100 List1.AddItem iIndex & " blankdata " & iIndex Next End Sub Private Sub List1_MouseMove(Button As Integer, Shift As Integer, x As Single, y As Single) Dim iIndex As Long Static iLastIndex As Long iIndex = ItemFromPoint(List1, x, y) Me.List1.ToolTipText = Me.List1.List(iIndex) End Sub


Reply With Quote