• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 183
  • Last Modified:

How to determine the VB6 List values base on the X, Y mouse move position?

How can I get the list value from a VB6 List box from the X, and Y positions in the mouse over event?  No item in the list box is choosen.  However, as the user does a mouse over the control want to display additional information for the value in the listbox the that mouse is over.  

It is very easy to get the X and Y positions from the mouse move event.  Is there an API call or some method to determine the list value based on the X and Y position of the mouse move event?  Actually, I will not just be displaying the list value.  But, based on the list value I will display additional informtion.

  • 3
1 Solution
Mike TomlinsonMiddle School Assistant TeacherCommented:
I'll post a bare bones example later tonight probably...so if you can't make heads or tails of what I have done in the links above just be patient.  ;)
Mike TomlinsonMiddle School Assistant TeacherCommented:
Create a New Project and add a Label and a ListBox:

Option Explicit

Private Const LB_GETITEMHEIGHT = &H1A1

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 Sub Form_Load()
    Dim i As Integer
    For i = 1 To 100
        List1.AddItem "Item" & i
End Sub

Private Sub List1_MouseMove(Button As Integer, Shift As Integer, x As Single, Y As Single)
    Dim index As Integer
    index = listrowcalc(List1, Y)
    Label1.Caption = List1.List(index)
End Sub

Private Function listrowcalc(lstTemp As Control, ByVal Y As Single) As Integer
    Dim ItemHeight As Integer
    ItemHeight = SendMessage(lstTemp.hWnd, LB_GETITEMHEIGHT, 0, 0)
    listrowcalc = min(((Y / Screen.TwipsPerPixelY) \ ItemHeight) + _
        lstTemp.TopIndex, lstTemp.ListCount - 1)
End Function

Private Function min(x As Integer, Y As Integer) As Integer
    If x > Y Then min = Y Else min = x
End Function

Featured Post

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now