How to disable the horizontal ScrollBar of a CList

2019-06-07 20:55发布

问题:

I have a CListCtrl control in my MFC project, I don't want the horizontal ScrollBar to be shown at any time. But the vertical one needs to be shown normally. I used VS2010, any solutions?

回答1:

You can do that by deriving your List control and having something like this:

void CListCtrlEx::OnNcCalcSize(BOOL bCalcValidRects, NCCALCSIZE_PARAMS FAR* lpncsp) 
{
    ModifyStyle( WS_HSCROLL, 0 );

    CListCtrl::OnNcCalcSize(bCalcValidRects, lpncsp);
}

Or if you don't want to derive your List control, you can do this:

if ( Style & WS_HSCROLL )
{
    Style &= ~WS_HSCROLL;
    ::SetWindowLong(m_list.GetSafeHwnd(),GWL_STYLE,Style);
}