Option Explicit
Private Declare Function SendMessageByNum Lib "user32" _
Alias "SendMessageA" (ByVal hwnd As Long, ByVal _
wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Const LB_SETHORIZONTALEXTENT = &H194
Private Sub Command1_Click()
Dim s As String
Static x As Long
s = InputBox("Please enter any text", "List scroll", _
"this is a simple scrollbar sample for demonstration purposes")
List1.AddItem s
If x < TextWidth(s & " ") Then
x = TextWidth(s & " ")
If ScaleMode = vbTwips Then _
x = x / Screen.TwipsPerPixelX ' if twips change to pixels
SendMessageByNum List1.hwnd, LB_SETHORIZONTALEXTENT, x, 0
End If
End Sub
|