WTL里双缓冲避免闪烁

 

 1///////////////////////////////////////////////////////////////////////////////
 2// CDoubleBufferImpl - Provides double-buffer painting support to any window
 3
 4template <class T>
 5class CDoubleBufferImpl
 6{
 7public:
 8// Overrideables
 9    void DoPaint(CDCHandle /*dc*/)
10    {
11        // must be implemented in a derived class
12        ATLASSERT(FALSE);
13    }

14
15// Message map and handlers
16    BEGIN_MSG_MAP(CDoubleBufferImpl)
17        MESSAGE_HANDLER(WM_ERASEBKGND, OnEraseBackground)
18        MESSAGE_HANDLER(WM_PAINT, OnPaint)
19#ifndef _WIN32_WCE
20        MESSAGE_HANDLER(WM_PRINTCLIENT, OnPaint)
21#endif // !_WIN32_WCE
22    END_MSG_MAP()
23
24    LRESULT OnEraseBackground(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/)
25    {
26        return 1;   // no background painting needed
27    }

28
29    LRESULT OnPaint(UINT /*uMsg*/, WPARAM wParam, LPARAM /*lParam*/, BOOL& /*bHandled*/)
30    {
31        T* pT = static_cast<T*>(this);
32        ATLASSERT(::IsWindow(pT->m_hWnd));
33
34        if(wParam != NULL)
35        {
36            RECT rect = 0 };
37            pT->GetClientRect(&rect);
38            CMemoryDC dcMem((HDC)wParam, rect);
39            pT->DoPaint(dcMem.m_hDC);
40        }

41        else
42        {
43            CPaintDC dc(pT->m_hWnd);
44            CMemoryDC dcMem(dc.m_hDC, dc.m_ps.rcPaint);
45            pT->DoPaint(dcMem.m_hDC);
46        }

47
48        return 0;
49    }

50}
;

posted on 2009-03-28 23:06  郁郁思扬  阅读(651)  评论(0编辑  收藏  举报

导航