VERSION 1.0 CLASS
BEGIN
  MultiUse = -1  'True
  Persistable = 0  'NotPersistable
  DataBindingBehavior = 0  'vbNone
  DataSourceBehavior  = 0  'vbNone
  MTSTransactionMode  = 0  'NotAnMTSObject
END
Attribute VB_Name = "CLBHScroll"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = True
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = False
Option Explicit

Private Declare Function SendMessageByLong Lib "user32" Alias "SendMessageA" _
   (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Private Const LB_SETHORIZONTALEXTENT = &H194
Private Const WM_VSCROLL = &H115
Private Const SB_BOTTOM = 7
Private Declare Function GetSystemMetrics Lib "user32" (ByVal nIndex As Long) As Long
Private Const SM_CXVSCROLL = 2

Private mvarListBox As ListBox
Private m_lMaxItemWidth As Long

Public Sub Init(ByRef pListBox As ListBox)
   Set mvarListBox = pListBox
   mvarListBox.Clear
   m_lMaxItemWidth = 0
End Sub

' The following routine adds a string to a specified list box
' and displays the horizontal scroll bar in it if required
Public Sub AddItem(ByRef psItemText As String)
   Dim m As Long
   
   mvarListBox.AddItem psItemText
   
   m = mvarListBox.Parent.TextWidth(psItemText)
   
   If m > m_lMaxItemWidth Then
      m_lMaxItemWidth = m
      SendMessageByLong mvarListBox.hwnd, LB_SETHORIZONTALEXTENT, _
         m / Screen.TwipsPerPixelX + GetSystemMetrics(SM_CXVSCROLL) + 2, 0
   End If
   
   SendMessageByLong mvarListBox.hwnd, WM_VSCROLL, SB_BOTTOM, 0
End Sub
