Log inUsernamePassword
Log me on automatically each visit    
Register
Register
Log in to check your private messages
Log in to check your private messages
Visual Basic Forum for Visual Basic Programmers VB Forum Index » Knowledge Base

Post new topic   Reply to topic
Set tooltips when setting mouse over an item in a listbox (w
View previous topic :: View next topic  
Author Message
P.T.A.M.
Administrator


Joined: 08 Oct 2003
Posts: 752
Location: Greece

PostPosted: Dec 29th, 2003 07:25 PM    Post subject: Set tooltips when setting mouse over an item in a listbox (w Reply with quote

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.
Back to top
View user's profile Send private message Send e-mail Visit poster's website ICQ Number
Display posts from previous:   
Post new topic   Reply to topic    Visual Basic Forum for Visual Basic Programmers VB Forum Index » Knowledge Base All times are GMT - 5 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Visual Basic Forum runs phpBB | Forum Template © iOptional
VB Resources | SSL | Visual Basic