如何停止CListCtrl底部的滚动条显示? [英] How to stop the bottom scrollbar from a CListCtrl from displaying?

查看:85
本文介绍了如何停止CListCtrl底部的滚动条显示?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个CListCtrl,它随对话框动态调整大小.我在派生的CListCtrl中使用了WM_SIZE消息处理程序来调整列的大小,以使总计为控件的宽度-4,其中-4表示边框的宽度.

I have a CListCtrl which is dynamically resized with the dialogue. I used a WM_SIZE message handler in the derived CListCtrl to resize the columns such that the total is the width of the control - 4, where the - 4 is to indicate the width of the border.

当我增加对话框的大小时,控件将正确调整大小,而我没有得到底部的滚动条.但是,当我缩小控件时,有时会出现水平滚动条.

When I make the dialogue bigger, the control resizes correctly and I don't get the bottom scrollbar. However when I shrink the control, I sometimes get the horizontal scrollbar showing up.

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消息在控件最终调整大小之前到达控件一样.

It is like the WM_SIZE message is getting to the control before the control is finally resized.

这与如何确定是否显示CListCtrl的滚动条?.但是,此问题未解决右侧滚动条,并假定未显示该滚动条.

This is related to How to determine if a scrollbar for a CListCtrl is displaying?. However, this question is not dealing with the right scrollbar, and is assuming that it is not being displayed.

推荐答案

调整窗口大小会生成一条消息,以测试水平滚动. SetColumnWidth也将生成相同的消息.这取决于ListView在内部如何处理此问题,但是垂直滚动也可以进出,这将更改工作区,因此代码可能必须进行递归调用才能确定滚动是否可见.您可以看到这很容易遇到问题.

Resizing the window generates a message to test for horizontal scroll. SetColumnWidth will also generate the same message. It depends how ListView handles this internally, but a vertical scroll could also come in and go, this will change the client area, so the code may have to make recursive calls to figure out if the scroll should be visible or not. You can see this can easily run in to problems.

在调用默认过程之前,尝试调整WM_WINDOWPOSCHANGED中各列的大小.使用SetRedraw停止多余的绘画消息.

Try resizing the columns in WM_WINDOWPOSCHANGED, before calling the default procedure. Use SetRedraw to stop redundant paint messages.

ON_WM_WINDOWPOSCHANGED()
...
void CMyListCtrl::OnWindowPosChanged(WINDOWPOS *wpos)
{
    SetRedraw(FALSE);
    ResizeLastColumn();
    SetRedraw(TRUE);
    CListCtrl::OnWindowPosChanged(wpos);
}

您可以将GetClientRect用于工作区,然后无需减去边框粗细(并不总是4).

You can use GetClientRect for the client area, then you don't need to subtract the border thickness (which is not always 4).

void ResizeLastColumn()
{
    int maxwidth = 0;
    int index = GetHeaderCtrl()->GetItemCount() - 1;
    for(int i = 0; i < index; ++i)
        maxwidth += GetColumnWidth(i);
    CRect rc;
    GetClientRect(&rc);
    SetColumnWidth(index, rc.Width() - maxwidth);
}

GetHeaderCtrl()->GetItemCount()返回列数.

这篇关于如何停止CListCtrl底部的滚动条显示?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆