Results 1 to 1 of 1

Thread: VB - Set tooltips when setting mouse over an item in a listbox (without clicking)

  1. #1

    Thread Starter
    Super Moderator manavo11's Avatar
    Join Date
    Nov 2002
    Location
    Around the corner from si_the_geek
    Posts
    7,171

    VB - Set tooltips when setting mouse over an item in a listbox (without clicking)

    From this thread. I just found it useful. Feel free to suggest a better title! :

    VB Code:
    1. Private Type POINTAPI
    2.     x As Long
    3.     y As Long
    4. End Type
    5.  
    6. Private Type RECT
    7.         Left As Long
    8.         Top As Long
    9.         Right As Long
    10.         Bottom As Long
    11. End Type
    12.  
    13. Private Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long
    14. Private Declare Function ScreenToClient Lib "user32" (ByVal hwnd As Long, lpPoint As POINTAPI) As Long
    15. Private Declare Function ClientToScreen Lib "user32" (ByVal hwnd As Long, lpPoint As POINTAPI) As Long
    16. 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
    17. Private Declare Function WindowFromPoint Lib "user32" (ByVal xPoint As Long, ByVal yPoint As Long) As Long
    18.  
    19. Private Const LB_GETITEMRECT = &H198
    20. Private Const LB_ITEMFROMPOINT = &H1A9
    21.  
    22.  
    23. Public Function ItemFromPoint(ByRef oList As ListBox, ByVal x As Single, ByVal y As Single) As Long
    24.     Dim tPOINT As POINTAPI
    25.     Dim iIndex As Long
    26.     'Get the Mouse Cursor Position
    27.     Call GetCursorPos(tPOINT)
    28.     'Convert the Coords to be Relative to the Listbox
    29.     Call ScreenToClient(oList.hwnd, tPOINT)
    30.     'Find which Item the Mouse is Over
    31.     iIndex = SendMessage(oList.hwnd, LB_ITEMFROMPOINT, 0&, ByVal ((tPOINT.x And &HFF) Or (&H10000 * (tPOINT.y And &HFF))))
    32.     'Extract the List Index
    33.     ItemFromPoint = iIndex And &HFF
    34. End Function
    35.  
    36. Private Sub Form_Load()
    37.     Dim iIndex As Integer
    38.        
    39.     For iIndex = 1 To 100
    40.         List1.AddItem iIndex & " blankdata " & iIndex
    41.     Next
    42. End Sub
    43.  
    44. Private Sub List1_MouseMove(Button As Integer, Shift As Integer, x As Single, y As Single)
    45.     Dim iIndex As Long
    46.     Static iLastIndex As Long
    47.    
    48.     iIndex = ItemFromPoint(List1, x, y)
    49.     Me.List1.ToolTipText = Me.List1.List(iIndex)
    50. End Sub
    Last edited by manavo11; Dec 29th, 2003 at 07:25 PM.


    Has someone helped you? Then you can Rate their helpful post.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width