[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 Integer
  '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
  
  xLong1 = SendMessage(hWndListBox, &H1A9&, 0&, (&H10000 * y))
  
  If (xLong1 And &HFFFF0000) = 0& And Not SendMessage(hWndListBox, &H18B&, 0&, 0&) = 0& Then
    xLong1 = xLong1 And &HFFFF&
    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
    Else
    If AlwaysMenu And Not MenuHandle = 0& Then
      TrackListBox = GetAPIPopupMenu(hWndCaller, MenuHandle, 0&)
      Else
      TrackListBox = -1&
      End If
    End If
  End Function
