VBA hWnd ListBox handle / scroll bar

VBA hWnd ListBox handle / scroll bar

Anonymous
Not applicable
3,870 Views
5 Replies
Message 1 of 6

VBA hWnd ListBox handle / scroll bar

Anonymous
Not applicable
In VBA (which doesn't have an hWnd property in ListBoxes)
I am trying to add a horizontal scrollbar to a listbox but need to get
the hwnd so I can set them. Anyone know how to get it?
or
anyone know how to add a horizontal scrollbar to a lisbox other than
using SendMessage?
0 Likes
3,871 Views
5 Replies
Replies (5)
Message 2 of 6

Anonymous
Not applicable
In doing a bit more, I tried running the following code with a Spy trace
window running. The LB_SETHORIZONTALEXTENT message is getting to the
list box but doesn't add a scroll bar. Perhaps it isn't supported in
VBA but it seems like there should be a way.

Private Declare Function GetFocus Lib "user32" () As Long
Private Const LB_SETHORIZONTALEXTENT = &H194
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA"
(ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As
Any) As Long

Private Sub CommandButton1_Click()

Dim hwnd As Long
ListBox1.SetFocus

hwnd = GetFocus
Call SendMessageBynum(hwnd, LB_SETHORIZONTALEXTENT, 400, 0)
End Sub

Charles Bliss wrote:

> In VBA (which doesn't have an hWnd property in ListBoxes)
> I am trying to add a horizontal scrollbar to a listbox but need to get
> the hwnd so I can set them. Anyone know how to get it?
> or
> anyone know how to add a horizontal scrollbar to a lisbox other than
> using SendMessage?
>
0 Likes
Message 3 of 6

Anonymous
Not applicable
Charles

Haven't tried it but does this help

http://www.developerfusion.com/show/1800/

and if not it looks like there are some others that might here

http://www.google.com/search?sourceid=navclient&q=vba+listbox+scrollbar

--
Kent
Assistant Moderator
Autodesk Discussion Forum Moderator Program


"Charles Bliss" wrote in message news:3EF863BB.4030101@cbliss.com...
> In doing a bit more, I tried running the following code with a Spy trace
> window running. The LB_SETHORIZONTALEXTENT message is getting to the
> list box but doesn't add a scroll bar. Perhaps it isn't supported in
> VBA but it seems like there should be a way.
>
> Private Declare Function GetFocus Lib "user32" () As Long
> Private Const LB_SETHORIZONTALEXTENT = &H194
> Private Declare Function SendMessage Lib "user32" Alias "SendMessageA"
> (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As
> Any) As Long
>
> Private Sub CommandButton1_Click()
>
> Dim hwnd As Long
> ListBox1.SetFocus
>
> hwnd = GetFocus
> Call SendMessageBynum(hwnd, LB_SETHORIZONTALEXTENT, 400, 0)
> End Sub
>
> Charles Bliss wrote:
>
> > In VBA (which doesn't have an hWnd property in ListBoxes)
> > I am trying to add a horizontal scrollbar to a listbox but need to get
> > the hwnd so I can set them. Anyone know how to get it?
> > or
> > anyone know how to add a horizontal scrollbar to a lisbox other than
> > using SendMessage?
> >
>
0 Likes
Message 4 of 6

Anonymous
Not applicable
Charles, this is what I use in VB to force the horizontal to adjust to length of the info in the listbox.

Private Const LB_SETHORIZONTALEXTENT = &H194 Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hWnd As Long, _
ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long longest$ = List1.List(x) Rtn = SendMessage(List1.hWnd, LB_SETHORIZONTALEXTENT, Config.TextWidth(longest$) * 0.75 / 10, ByVal 0) (place this in a .bas file) Public longest$, Rtn As Long "Config.TextWidth" in this code is the string added to my listbox. The * 0.75/10 is basically a percentage over the length of the string that the scroll bar will create. Let me know it this helps. Mike
0 Likes
Message 5 of 6

Anonymous
Not applicable
Charles,

Scrollbars in a VBA ListBox control are automatic. There are 2 ways you can go about it. First, change the column width to be greater than the width of the ListBox. Or second, if you do have more than 1 column changes the widths of the columns so that they are wider than the ListBox width. There you have it!

Joe
--
0 Likes
Message 6 of 6

Anonymous
Not applicable
Thanks, that is exactly what I am looking for.

joesu wrote:

> Charles,
>
> Scrollbars in a VBA ListBox control are automatic. There are 2 ways
> you can go about it. First, change the column width to be greater than
> the width of the ListBox. Or second, if you do have more than 1 column
> changes the widths of the columns so that they are wider than the
> ListBox width. There you have it!
>
> Joe
> --
>
0 Likes