如何检查CListBox中的Vertical Scrollbar [英] How to check if Vertical Scrollbar in CListBox
问题描述
嘿,
有办法检查CListBox中是否有垂直滚动条。
我试过这个解决方案,但它似乎没有工作:
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:
if(GetLBox().GetStyle() & WS_VSCROLL)
{
// some Actions here
}
非常感谢您的快速解答:)
Thanks a lot for quick answers :)
推荐答案
试试这个
Try this
bool bHScroll = (m_List.GetStyle()&WS_HSCROLL)!=0;
bool bVScroll = (m_List.GetStyle()&WS_VSCROLL)!=0;
//如果不回答请看源:-)
< a href =https://groups.google.com/forum/#!topic/microsoft.public.vc.mfc/ITZDFS-4Lbc>来源 [ + ]
您可以使用 GetScrollBarInfo() [ ^ ]:
You may use GetScrollBarInfo()[^]:
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;
}
[更新]
对于没有<$ c $的窗户c> WS_VSCROLL 创建时设置的样式, GetScrollBarCtrl() [可以使用 ^ ]功能:
[UPDATE]
For windows that did not have the WS_VSCROLL
style set upon creation, the GetScrollBarCtrl()[^] function may be used:
bool bVisible = false;
CWnd *pScrollWnd = GetLBox()->GetScrollBarCtrl(SB_VERT);
if (pScrollWnd && pScrollWnd->IsKindOf(RUNTIME_CLASS(CScrollBar)))
{
if (pScrollWnd->IsWindowVisible())
bVisible = true;
}
当没有更好的方法时,我认为这是解决问题的最佳方法:
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.
这篇关于如何检查CListBox中的Vertical Scrollbar的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!