[API]
RECT

[INCLUDE]
SendMessage
GetAPIPopupMenu

[CODE]
Public Function TrackListBox(ByVal hWndCaller As Long, ByVal hWndListBox As Long, ByVal y As Long, ByVal AlwaysMenu As Boolean, ByVal MenuHandle As Long, ByVal ListMode As Long) As Long
  'flags:
  ' 0=alwaysmenu
  ' 1=menuifselected etc
  ' 2=
  ' 1=Menu if out of bounds or empty
  ' 2=SingleSel or checkboxmode
  ' 4=NoProcessSelection
  Dim xLong1 As Long
  Dim xLong2 As Long
  Dim xType1 As RECT
  
  xLong1 = SendMessage(hWndListBox, &H198&, 0&, VarPtr(xType1))
  If Not xLong1 = -1& Then
    xLong1 = xType1.Bottom - xType1.Top
    If xLong1 > 0& Then
      xLong1 = Fix((y - xType1.Top) / xLong1)
      y = SendMessage(hWndListBox, &H18B&, 0&, 0&)
      If y > 0& And xLong1 < y Then
        'If Not xLong1 < y Then
        '  xLong1 = y - 1&
        '  End If
        If ListMode = 1& Then
          If SendMessage(hWndListBox, &H187&, xLong1, 0&) = 0& Then
            Call SendMessage(hWndListBox, &H185, 0&, -1&)
            Call SendMessage(hWndListBox, &H185, 1&, xLong1)
            End If
          Else
          If Not SendMessage(hWndListBox, &H188&, 0&, 0&) = xLong1 Then
            If ListMode = 2& Then
              Call SendMessage(hWndListBox, &H19E&, xLong1, 0&)
              Else
              Call SendMessage(hWndListBox, &H186&, xLong1, 0&)
              End If
            End If
          End If
        
        If MenuHandle = 0& Then
          TrackListBox = xLong1
          Else
          TrackListBox = GetAPIPopupMenu(hWndCaller, MenuHandle, 0&)
          End If
        Exit Function
        End If
      End If
    End If
  If AlwaysMenu And Not MenuHandle = 0& Then
    TrackListBox = GetAPIPopupMenu(hWndCaller, MenuHandle, 0&)
    Else
    TrackListBox = -1&
    End If
  End Function