P.T.A.M. Administrator

Joined: 08 Oct 2003 Posts: 752 Location: Greece
|
Posted: Dec 29th, 2003 07:25 PM Post subject: Set tooltips when setting mouse over an item in a listbox (w |
|
|
Feel free to suggest a better title! :
| 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 |
_________________ No one is completely useless. They can at least be an example of what to avoid. |
|