Board index » cppbuilder » Hiding the vertical scrollbar of a List Box

Hiding the vertical scrollbar of a List Box

I put the following code in my constructor for a form that has a
TListBox name ListBox1.  I expected that this would remove the
vertical scrollbar from the list box, but it didn't.

long value;
value = GetWindowLong(ListBox1->Handle,GWL_STYLE);
SetWindowLong(ListBox1->Handle,GWL_STYLE,value & ~WS_VSCROLL);

 

Re:Hiding the vertical scrollbar of a List Box


Quote
Fishface wrote:
> Add this line to force Windows to repaint it to reflect the style change:

> SetWindowPos(ListBox1->Handle, 0, 0, 0, 0, 0, 0x667);

This works fine until I scroll the list box programatically and then the
scrollbar reappears.

Re:Hiding the vertical scrollbar of a List Box


Quote
Richard Casten wrote:
> I put the following code in my constructor for a form that has a
> TListBox name ListBox1.  I expected that this would remove the
> vertical scrollbar from the list box, but it didn't.

> long value;
> value = GetWindowLong(ListBox1->Handle,GWL_STYLE);
> SetWindowLong(ListBox1->Handle,GWL_STYLE,value & ~WS_VSCROLL);

Add this line to force Windows to repaint it to reflect the style change:

SetWindowPos(ListBox1->Handle, 0, 0, 0, 0, 0, 0x667);

0x667 is a combination of flags, I forget exactly which.  You could
decipher it from the information in winuser.h if you so desire, or
combine a bunch of constants yourself with the | operator.  I find
it is easier to type...

Re:Hiding the vertical scrollbar of a List Box


Quote
Richard Casten wrote:
> This works fine until I scroll the list box programatically and then the
> scrollbar reappears.

Ack!  So that whole combination is probably easier accomplished by:

ShowScrollBar(ListBox1->Handle, SB_VERT, false );

...but unfortunately the List Box control itself must be turning the style
bit back on.  Why can't you just do normal stuff?!  OK, I have more ideas.

1) Get rid of the borders and put it on a TPanel so that the scroll bar is
    beyond the right edge.
2) Use SetWindowRgn() to clip the scroll bar.

For both of those, you would need to work on the borders a bit.

3) Subclass or derive from the TListBox and handle the WM_NCPAINT
    message and paint the frame yourself without scroll bars.  See the API
    function DrawFrameControl().

Any or all of these might work, but you have to ask yourself one question:
"How badly do I want it?"

Re:Hiding the vertical scrollbar of a List Box


Quote
Fishface wrote:
> ShowScrollBar(ListBox1->Handle, SB_VERT, false );

> ...but unfortunately the List Box control itself must be turning the style
> bit back on.

Actually, I found that in the subclassed window proc for ListBox1 all you need
is:
     if(Message.Msg == WM_PAINT)
          ShowScrollBar(ListBox2->Handle,SB_VERT,false);

Thanks for the help!

Re:Hiding the vertical scrollbar of a List Box


Quote
Richard Casten wrote:
> Actually, I found that in the subclassed window proc for
> ListBox1 all you need is:
>      if(Message.Msg == WM_PAINT)
>           ShowScrollBar(ListBox2->Handle,SB_VERT,false);

Excellent, much simpler!  Thanks for sharing...

FF

Other Threads