How to determine if a scrollbar for a CListCtrl is displaying?

社会主义新天地 提交于 2019-12-13 03:36:38

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!