如何确定是否显示CListCtrl的滚动条? [英] How to determine if a scrollbar for a CListCtrl is displaying?
问题描述
我有一个从CListCtrl派生的类.我希望所有列的宽度总计显示窗口的宽度,以免出现底部滚动条.我可以通过GetSystemMetrics(SM_CXVSCROLL)
调用获取标准滚动条的宽度,但是我不知道如何确定垂直滚动条是否处于活动状态.我尝试使用:
I have a class that is derived from a CListCtrl. I want the widths of all the columns to total the width of the display Window, so that I don't get the bottom scrollbar. I can get the width of standard scrollbars vai the GetSystemMetrics(SM_CXVSCROLL)
call, but I don't know how to tell if the vertical scrollbar is active. I've tried to use:
auto pScrollbar = GetScrollBarCtrl(SB_VERT);
auto is_visible = pScrollbar && pScrollbar->IsWindowVisible();
但是pScrollbar
始终是nullptr
.我四处张望,有些人说滚动条并不总是窗口,可能是手工绘制的(嗯!),可能根本不是窗口.这会使我的生活更加困难.想法?
But pScrollbar
is always a nullptr
. I've looked around and some ppl are saying that the scrollbars are not always windows and may be draw in by hand (ugh!) and may not be a Window at all. This will make my life more difficult. Ideas?
推荐答案
From my linked question (How to stop the bottom scrollbar from a CListCtrl from displaying?), I was using:
void CMyListCtrl::ResizeLastColumn()
{
LVCOLUMN column;
column.mask = LVCF_WIDTH;
LONG maxWidth = 0;
for (int i = 0; i < lastColumnIndex; ++i)
{
GetColumn(i, &column);
maxWidth += column.cx;
}
CRect wndRect;
GetWindowRect(&wndRect);
SetColumnWidth(lastColumnIndex, wndRect.Width() - maxWidth - 4);
}
将列的大小调整为客户区的宽度.事实证明,通过使用GetClientRect()
代替,我不必减去-4
或垂直滚动条宽度,这不再是问题.
to resize the columns to the width of the client area. Turns out, by using GetClientRect()
instead, I don't have to subtract -4
or the vertical scrollbar width, making this no longer an issue.
这篇关于如何确定是否显示CListCtrl的滚动条?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!