4 IMPLEMENT_DYNAMIC(CBufferDC
, CPaintDC
)
6 CBufferDC::CBufferDC(CWnd
* pWnd
) : CPaintDC(pWnd
)
8 if (pWnd
&& CPaintDC::m_hDC
)
10 m_hOutputDC
= CPaintDC::m_hDC
;
11 m_hAttributeDC
= CPaintDC::m_hAttribDC
;
13 pWnd
->GetClientRect(&m_ClientRect
);
15 m_hMemoryDC
= ::CreateCompatibleDC(m_hOutputDC
);
18 ::CreateCompatibleBitmap(
20 m_ClientRect
.right
- m_ClientRect
.left
,
21 m_ClientRect
.bottom
- m_ClientRect
.top
);
23 m_hOldBitmap
= (HBITMAP
)::SelectObject(m_hMemoryDC
, m_hPaintBitmap
);
25 CPaintDC::m_hDC
= m_hMemoryDC
;
26 CPaintDC::m_hAttribDC
= m_hMemoryDC
;
31 m_hAttributeDC
= nullptr;
32 m_hOutputDC
= nullptr;
33 m_hMemoryDC
= nullptr;
34 m_hPaintBitmap
= nullptr;
35 m_hOldBitmap
= nullptr;
36 m_ClientRect
.right
= 0;
37 m_ClientRect
.left
= 0;
39 m_ClientRect
.bottom
= 0;
42 m_bBoundsUpdated
= FALSE
;
45 CBufferDC::~CBufferDC(void)
49 ::SelectObject(m_hMemoryDC
, m_hOldBitmap
);
50 ::DeleteObject(m_hPaintBitmap
);
52 CPaintDC::m_hDC
= m_hOutputDC
;
53 CPaintDC::m_hAttribDC
= m_hAttributeDC
;
55 ::DeleteDC(m_hMemoryDC
);
58 void CBufferDC::Flush()
62 m_ClientRect
.left
, m_ClientRect
.top
,
63 m_ClientRect
.right
- m_ClientRect
.left
,
64 m_ClientRect
.bottom
- m_ClientRect
.top
,
70 UINT
CBufferDC::SetBoundsRect( LPCRECT lpRectBounds
, UINT flags
)
74 if (m_ClientRect
.right
- m_ClientRect
.left
> lpRectBounds
->right
- lpRectBounds
->left
||
75 m_ClientRect
.bottom
- m_ClientRect
.top
> lpRectBounds
->bottom
- lpRectBounds
->top
)
77 lpRectBounds
= &m_ClientRect
;
81 ::CreateCompatibleBitmap(
83 lpRectBounds
->right
- lpRectBounds
->left
,
84 lpRectBounds
->bottom
- lpRectBounds
->top
);
86 HDC tmpDC
= ::CreateCompatibleDC(m_hOutputDC
);
88 HBITMAP oldBmp
= (HBITMAP
)::SelectObject(tmpDC
, bmp
);
92 m_ClientRect
.left
, m_ClientRect
.top
,
93 m_ClientRect
.right
- m_ClientRect
.left
,
94 m_ClientRect
.bottom
- m_ClientRect
.top
,
99 ::SelectObject(tmpDC
, oldBmp
);
102 HBITMAP old
= (HBITMAP
)::SelectObject(m_hMemoryDC
, bmp
);
104 if (old
&& old
!= m_hPaintBitmap
)
111 ::DeleteObject(m_hPaintBitmap
);
114 m_hPaintBitmap
= bmp
;
116 m_ClientRect
= *lpRectBounds
;
117 m_bBoundsUpdated
= TRUE
;
120 return CPaintDC::SetBoundsRect(lpRectBounds
, flags
);
123 BOOL
CBufferDC::RestoreDC( int nSavedDC
)
125 BOOL ret
= CPaintDC::RestoreDC(nSavedDC
);
127 if (m_bBoundsUpdated
)
129 SelectObject(m_hPaintBitmap
);