问题
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();
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?
回答1:
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);
}
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.
来源:https://stackoverflow.com/questions/48896284/how-to-determine-if-a-scrollbar-for-a-clistctrl-is-displaying