Listview flickers in Win32 dialog when deleting and re-adding all items and all columns

Consider a simple Win32 dialog with a list control (in report mode) written in C ++. At a certain event, all elements and all columns are deleted, and new columns and elements are created. Basically, as content changes, columns are automatically generated based on the content.

When old items / columns are removed and new ones added, listview flickers like hell. I tried WM_SETREDRAWand LockWindowUpdate()without changing the visual perception.

I even set the extended list style LVS_EX_DOUBLEBUFFERand it didn't help.

In the parent dialogue is WS_CLIPCHILDREN.

Any suggestions on how to make this work with minimal flicker? I mean the use of two lists, alternating visibility, the use of hidden as a backup buffer, but it sounds like an overkill. There should be an easy way.

+3
source share
2 answers

The default list management picture is pretty erroneous. But there is an easy way to implement your double buffering method:

CMyListCtrl::OnPaint()
{
    CRect rcClient;
    GetClientRect(rcClient);

    CPaintDC dc(this);
    CDC dcMem;
    dcMem.CreateCompatibleDC(&dc);

    CBitmap bmMem;
    bmMem.CreateCompatibleBitmap(&dc, rcClient.Width(), rcClient.Height());
    CBitmap* pbmOld = dcMem.SelectObject(&bmMem);

    dcMem.FillSolidRect(rcClient, ::GetSysColor(COLOR_WINDOW));

    this->DefWindowProc(WM_PAINT, (WPARAM)dcMem.m_hDC, (LPARAM)0);

    dc.BitBlt(0,0,rcClient.Width(), rcClient.Height(), &dcMem, 0, 0, SRCCOPY);
    dcMem.SelectObject(pbmOld);

    CHeaderCtrl*    pCtrl = this->GetHeaderCtrl();
    if (::IsWindow(pCtrl->GetSafeHWnd())
    {
        CRect   aHeaderRect;
        pCtrl->GetClientRect(&aHeaderRect);
        pCtrl->RedrawWindow(&aHeaderRect);
    }
}

This will create a bitmap and then call the default window procedure to draw a list control in the bitmap and then blend the contents of the bitmap in DC paint.

You should also add a handler for WM_ERASEBKGND:

BOOL CMyListCtrl::OnEraseBkgnd(CDC* pDC)
{
    return TRUE;
}

, . OnPaint , - () , ( ).

.

+7

, , humbagumba , . LockWindowUpdate - . , , , , LockWindowUpdate, !

, LockWindowUpdate(hWnd) LockWindowUpdate(NULL), . .

, LockWindowUpdate, .

+1

Source: https://habr.com/ru/post/1752471/


All Articles