WTL里双缓冲避免闪烁
1
///////////////////////////////////////////////////////////////////////////////
2
// CDoubleBufferImpl - Provides double-buffer painting support to any window
3
4
template <class T>
5
class CDoubleBufferImpl
6
{
7
public:
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
};
///////////////////////////////////////////////////////////////////////////////2
// CDoubleBufferImpl - Provides double-buffer painting support to any window3

4
template <class T>5
class CDoubleBufferImpl6
{7
public:8
// Overrideables9
void DoPaint(CDCHandle /*dc*/)10
{11
// must be implemented in a derived class12
ATLASSERT(FALSE);13
}14

15
// Message map and handlers16
BEGIN_MSG_MAP(CDoubleBufferImpl)17
MESSAGE_HANDLER(WM_ERASEBKGND, OnEraseBackground)18
MESSAGE_HANDLER(WM_PAINT, OnPaint)19
#ifndef _WIN32_WCE20
MESSAGE_HANDLER(WM_PRINTCLIENT, OnPaint)21
#endif // !_WIN32_WCE22
END_MSG_MAP()23

24
LRESULT OnEraseBackground(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/)25
{26
return 1; // no background painting needed27
}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
else42
{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
};



浙公网安备 33010602011771号