【发布时间】:2018-02-21 00:33:01
【问题描述】:
我有一个CListCtrl,它会随着对话动态调整大小。我在派生的CListCtrl 中使用了WM_SIZE 消息处理程序来调整列的大小,使总和为控件的宽度 - 4,其中 - 4 表示边框的宽度。
当我使对话变大时,控件会正确调整大小并且我没有得到底部滚动条。但是,当我缩小控件时,有时会出现水平滚动条。
void CMyListCtrl::OnSize(UINT nType, int cx, int cy)
{
CListCtrl::OnSize(nType, cx, cy);
ResizeLastColumn();
}
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);
}
就像WM_SIZE 消息在控件最终调整大小之前到达控件。
这与How to determine if a scrollbar for a CListCtrl is displaying? 有关。但是,这个问题不是在处理右滚动条,而是假设它没有被显示。
【问题讨论】:
标签: mfc