Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

How to check that scrollbar of CListCtrl is being visible?

2,522 views
Skip to first unread message

Saitama

unread,
Dec 10, 2008, 1:19:01 AM12/10/08
to
Hi All !
Anybody knows how to check that scrollbar is being showed in CListCtrl? I
have used GetScrollInfo and tried to see the nMin and nMax value if they were
both 0, but NOT, although scrollbar is not being showed.

Thank you for any helps!

Serge Wautier

unread,
Dec 10, 2008, 3:15:08 AM12/10/08
to
bool bHScroll = (m_List.GetStyle()&WS_HSCROLL)!=0;
bool bVScroll = (m_List.GetStyle()&WS_VSCROLL)!=0;

HTH,

Serge.
http://www.apptranslator.com - Localization tool for your MFC applications


"Saitama" <Sai...@discussions.microsoft.com> wrote in message
news:5F374768-9F19-40E4...@microsoft.com...

Joseph M. Newcomer

unread,
Dec 14, 2008, 2:18:46 AM12/14/08
to
That;s only part of the answer. It *can* have, for example, WS_VSCROLL set, but the
control is not displayed, because the scrollbar options are set to not display the
scrollbar because no scrolling is required at the moment.

Unfortunately, the OP merely said the values were not 0, and did not feel it was
worthwhile to state what the values actually were. Why is it so hard to give complete
information?
joe

Joseph M. Newcomer [MVP]
email: newc...@flounder.com
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm

RainMan

unread,
Dec 17, 2008, 12:01:03 PM12/17/08
to
Joe, I am not sure what control you are referring to. List view control
(SysListView32) does not use scroll bar control. Scroll bars are drawn as
they are needed.

If list view style is LVS_NOSCROLL then no scroll bars are used.

Using code presented by Serge is perfectly legal and will return proper
information.
However, GetScrollBarInfo gives all information about scrollbars.
I thing Saitama’s problem is not initializing SCROLLBARINFO structure.
At least cbSize should be initialized to a sizeof(SCROLLBARINFO).
On successful call to GetScrollBarInfo region[0] member returns state and if
state shows that bar is visible other members will show valid information.

--
RainMan

Joseph M. Newcomer

unread,
Dec 17, 2008, 4:43:22 PM12/17/08
to
Scroll bar controls are either separate controls, or are implicit (SB_HORZ, SB_VERT) of
the window itself. They are fake controls and are essentially nonclient areas drawn with
the same subroutine that is used to draw scrollbars.

So you should be able to ask for SB_HORZ or SB_VERT as appropriate. I do this, and see my
essay on working around a bug in the SysListView32 control as far as dealing with
horizontal scrolling.
joe


On Wed, 17 Dec 2008 09:01:03 -0800, RainMan <Rai...@online.nospam> wrote:

>Joe, I am not sure what control you are referring to. List view control
>(SysListView32) does not use scroll bar control. Scroll bars are drawn as
>they are needed.
>
>If list view style is LVS_NOSCROLL then no scroll bars are used.
>
>Using code presented by Serge is perfectly legal and will return proper
>information.
>However, GetScrollBarInfo gives all information about scrollbars.
>I thing Saitama’s problem is not initializing SCROLLBARINFO structure.
>At least cbSize should be initialized to a sizeof(SCROLLBARINFO).
>On successful call to GetScrollBarInfo region[0] member returns state and if
>state shows that bar is visible other members will show valid information.

Joseph M. Newcomer

unread,
Dec 17, 2008, 4:44:56 PM12/17/08
to
On Wed, 17 Dec 2008 09:01:03 -0800, RainMan <Rai...@online.nospam> wrote:

>Joe, I am not sure what control you are referring to. List view control
>(SysListView32) does not use scroll bar control. Scroll bars are drawn as
>they are needed.

****
At no point did I actually refer to "scroll bar controls", I referred to scroll bar
information, which would be true if the window has scrolling capability.
joe
****


>
>If list view style is LVS_NOSCROLL then no scroll bars are used.
>
>Using code presented by Serge is perfectly legal and will return proper
>information.
>However, GetScrollBarInfo gives all information about scrollbars.
>I thing Saitama’s problem is not initializing SCROLLBARINFO structure.
>At least cbSize should be initialized to a sizeof(SCROLLBARINFO).
>On successful call to GetScrollBarInfo region[0] member returns state and if
>state shows that bar is visible other members will show valid information.

Alec S.

unread,
Dec 18, 2008, 5:10:22 PM12/18/08
to
"Joseph M. Newcomer" <newc...@flounder.com> wrote in message

> That;s only part of the answer. It *can* have, for example, WS_VSCROLL set,
but the
> control is not displayed, because the scrollbar options are set to not display
the
> scrollbar because no scrolling is required at the moment.


Actually, that does not seem to be the case. I just did a test, and the code
that Serge gave worked as expected. Whenever the scrollbar was displayed, the
list control had the scroll style, and when it was not displayed, it did not. I
guess that the control sets or clears that style when it determines whether or
not it needs to display the scrollbar; makes sense.


Here’s another solution that works:

int w = 0;
for (int i = 0; i < m_List.GetHeaderCtrl()->GetItemCount(); i++)
w+=m_List.GetColumnWidth(i);
CRect rect(0,0,0,0);
m_List.GetClientRect(&rect);
bool bHScroll = w <= rect.Width();
bool bVScroll = m_List.GetItemCount() <= m_List.GetCountPerPage();


HTH

--
Alec S.
news/alec->synetech/cjb/net

> On Wed, 10 Dec 2008 09:15:08 +0100, "Serge Wautier" <se...@wautier.nospam.net>
wrote:
>
> > bool bHScroll = (m_List.GetStyle()&WS_HSCROLL)!=0;
> > bool bVScroll = (m_List.GetStyle()&WS_VSCROLL)!=0;
>

> >"Saitama" <Sai...@discussions.microsoft.com> wrote in message

0 new messages