Click to See Complete Forum and Search --> : List box


rvspanand
January 21st, 2000, 12:32 PM
Dear sir,

i want to show a tool tip in mouse move event for a list box. when a user moves the mouse over an item in list box, he should be able to see same item name as a tool tip for the list box.

thanks in advance,
anand

Aaron Young
January 21st, 2000, 01:41 PM
Try this:

private Type POINTAPI
X as Long
Y 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 SendMessage Lib "user32" Alias "SendMessageA" (byval hWnd as Long, byval wMsg as Long, byval wParam as Long, lParam as Long) as Long

private Const LB_ITEMFROMPOINT = &H1A9

private Sub Form_Load()
Dim iIndex as Integer
'Fill the List with Dummy Values
for iIndex = 1 to 100
List1.AddItem "Really Long List Item " & iIndex
next
End Sub

private Sub List1_MouseMove(Button as Integer, Shift as Integer, X as Single, Y as Single)
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(List1.hWnd, tPOINT)
'Find which Item the Mouse is Over
iIndex = SendMessage(List1.hWnd, LB_ITEMFROMPOINT, 0&, byval ((tPOINT.X And &HFF) Or (&H10000 * (tPOINT.Y And &HFF))))
If iIndex >= 0 then
'Extract the List Index
iIndex = iIndex And &HFF
'set the Lists ToolTipText
List1.ToolTipText = List1.List(iIndex)
End If
End Sub




Aaron Young
Analyst Programmer
ajyoung@pressenter.com
aarony@redwingsoftware.com