解决MFC控件闪烁问题的小模板

#pragma once


template <class T>
struct XFlickerFree : public T
{
    DECLARE_MESSAGE_MAP()

    afx_msg BOOL OnEraseBkgnd(CDC* pDC)
    {
        return FALSE;
    }


    afx_msg  void OnPaint()
    {
        CPaintDC dc(this); // device context for painting

#if 0
        CRect headerRect;
        GetDlgItem(0)->GetWindowRect(&headerRect);
        ScreenToClient(&headerRect);
        dc.ExcludeClipRect(&headerRect);
#endif
        CMemDC dcMem(dc, this);

        CDC& memDC = dcMem.GetDC();

        DefWindowProc(WM_ERASEBKGND, (WPARAM)memDC.m_hDC, (LPARAM)0);
        DefWindowProc(WM_PAINT, (WPARAM)memDC.m_hDC, (LPARAM)0);
    }

};

BEGIN_TEMPLATE_MESSAGE_MAP(XFlickerFree, T, T)
    ON_WM_ERASEBKGND()
    ON_WM_PAINT()
END_MESSAGE_MAP()

你可能感兴趣的:(解决MFC控件闪烁问题的小模板)