
VB4, list boxes, and horizontal scroll bars CHALLENGE!
On Tue, 19 Mar 1996 16:38:49 -0500, Desi Richards
Quote:
>Microsoft has an app note out for VB 3 and below that explains how to make a
>horizontal scroll bar visible for a list box, using the SendMessage command and
>LB_SETHORIZONTALEXTENT.
> <snip>
>To make the horizontal scroll bar on a standard VB list box visible using 32 bit VB
>4.0 (Pro, if it matters).
>Any takers?
>Desi
Gee, must be a trick question. I copied the example directly into VB
4.0 (32 bit) under Windows 95, changed the API calls to the
appropriate 32-bit counterparts, and wahlah (how IS that spelled?), I
have a scroll bar on my list box. Here is the code:
Declare Function SendMessage Lib "user32" Alias "SendMessageA" _
(ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, _
lParam As Long) As Long
Declare Function GetFocus Lib "user32" () As Long
Sub Command1_Click()
Const LB_SETHORIZONTALEXTENT = &H400 + 21
Const NUL = 0&
' wParam is in PIXEL(3).
ScaleMode = 3
' Get the handle.
List1.SetFocus
ListHwnd% = GetFocus()
' This string will show up initially.
ListString1$ = "Derek is a great "
' You can scroll to see this portion.
ListString2$ = "little boy "
' You cannot scroll to see this string.
ListString3$ = "but can be a problem sometimes"
ExtraPixels% = TextWidth(ListString2$)
BoxWidth% = TextWidth(ListString1$)
' Resize the text box.
List1.Move List1.Left, List1.Top, BoxWidth%
' Add the scroll bar.
X& = SendMessage(ListHwnd%, LB_SETHORIZONTALEXTENT, _
BoxWidth% + ExtraPixels%, NUL)
' Add the example string to the list box.
List1.AddItem ListString1$ + ListString2$ + ListString3$
End Sub
Let me know if this doesn't work...
Jeff