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

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50
