Click here to Skip to main content
15,887,683 members
Please Sign up or sign in to vote.
3.86/5 (3 votes)
Hey,

is there a way to check if the vertical scrollbar is visible in a CListBox.
I've tried this solution but it doesen't seem to work:

C++
if(GetLBox().GetStyle() & WS_VSCROLL)
{
    // some Actions here
}


Thanks a lot for quick answers :)
Posted
Updated 28-Jan-14 20:47pm
v5

Try this

C++
bool bHScroll = (m_List.GetStyle()&WS_HSCROLL)!=0;
bool bVScroll = (m_List.GetStyle()&WS_VSCROLL)!=0;


// if not answer look at source :-)

source[+]
 
Share this answer
 
Comments
olid4 17-Jan-14 7:20am    
Sorry, I didn't mean CListCtrl. Instead I need the corresponding function for a CListBox.
You may use GetScrollBarInfo()[^]:
C++
bool bVisible = false;
SCROLLBARINFO SbVert;
SbVert.cbSize = sizeof(SbVert);
if (GetLBox().GetScrollBarInfo(OBJID_VSCROLL, &SbVert))
{
    // Index 0 of rgstate is the scrollbar itself
    // See SCROLLBARINFO in the MSDN
    if (0 == sbi.rgstate[0] & (STATE_SYSTEM_INVISIBLE | STATE_SYSTEM_UNAVAILABLE))
        bVisible = true;
}


[UPDATE]
For windows that did not have the WS_VSCROLL style set upon creation, the GetScrollBarCtrl()[^] function may be used:
C++
bool bVisible = false;
CWnd *pScrollWnd = GetLBox()->GetScrollBarCtrl(SB_VERT);
if (pScrollWnd && pScrollWnd->IsKindOf(RUNTIME_CLASS(CScrollBar)))
{
    if (pScrollWnd->IsWindowVisible())
        bVisible = true;
}
 
Share this answer
 
v2
Comments
olid4 17-Jan-14 7:20am    
Sorry, I didn't mean CListCtrl. Instead I need the corresponding function for a CListBox.
Jochen Arndt 17-Jan-14 7:25am    
Than you should update your question (use the green 'Improve question' link) so that others know it.

Have you tried my code?
I'm not sure but it may also work with CListBox.

Has your list box the WS_VSCROLL style set?
If not, you can use GetScrollBarCtrl(). I will update my answer with an example.
olid4 17-Jan-14 7:29am    
I updated my question.
I will try to work with GetScrollBarCtrl().
Jochen Arndt 17-Jan-14 7:39am    
Yes, but you forgot to update the title (which I checked when wroting my comment).
olid4 17-Jan-14 7:55am    
Sorry again!
=> Updated!
When there's no better way, I think this is the best way to solve the problem:

if(rectListBox.Height() > GetLBox().GetCount() *  GetLBox().GetItemHeight(0))


There may be some problems with borders and stuff like that. But IMHO this should work appropriate in most cases.
 
Share this answer
 
v3

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900