4 IMPLEMENT_DYNAMIC(CBufferDC
, CPaintDC
)
6 CBufferDC::CBufferDC(CWnd
* pWnd
) : CPaintDC(pWnd
)
8 if (pWnd
!= NULL
&& CPaintDC::m_hDC
!= NULL
)
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
;
29 m_bBoundsUpdated
= FALSE
;
32 CBufferDC::~CBufferDC(void)
36 ::SelectObject(m_hMemoryDC
, m_hOldBitmap
);
37 ::DeleteObject(m_hPaintBitmap
);
39 CPaintDC::m_hDC
= m_hOutputDC
;
40 CPaintDC::m_hAttribDC
= m_hAttributeDC
;
42 ::DeleteDC(m_hMemoryDC
);
45 void CBufferDC::Flush()
49 m_ClientRect
.left
, m_ClientRect
.top
,
50 m_ClientRect
.right
- m_ClientRect
.left
,
51 m_ClientRect
.bottom
- m_ClientRect
.top
,
57 UINT
CBufferDC::SetBoundsRect( LPCRECT lpRectBounds
, UINT flags
)
59 if (lpRectBounds
!= NULL
)
61 if (m_ClientRect
.right
- m_ClientRect
.left
> lpRectBounds
->right
- lpRectBounds
->left
||
62 m_ClientRect
.bottom
- m_ClientRect
.top
> lpRectBounds
->bottom
- lpRectBounds
->top
)
64 lpRectBounds
= &m_ClientRect
;
68 ::CreateCompatibleBitmap(
70 lpRectBounds
->right
- lpRectBounds
->left
,
71 lpRectBounds
->bottom
- lpRectBounds
->top
);
73 HDC tmpDC
= ::CreateCompatibleDC(m_hOutputDC
);
75 HBITMAP oldBmp
= (HBITMAP
)::SelectObject(tmpDC
, bmp
);
79 m_ClientRect
.left
, m_ClientRect
.top
,
80 m_ClientRect
.right
- m_ClientRect
.left
,
81 m_ClientRect
.bottom
- m_ClientRect
.top
,
86 ::SelectObject(tmpDC
, oldBmp
);
89 HBITMAP old
= (HBITMAP
)::SelectObject(m_hMemoryDC
, bmp
);
91 if (old
!= NULL
&& old
!= m_hPaintBitmap
)
96 if (m_hPaintBitmap
!= NULL
)
98 ::DeleteObject(m_hPaintBitmap
);
101 m_hPaintBitmap
= bmp
;
103 m_ClientRect
= *lpRectBounds
;
104 m_bBoundsUpdated
= TRUE
;
107 return CPaintDC::SetBoundsRect(lpRectBounds
, flags
);
110 BOOL
CBufferDC::RestoreDC( int nSavedDC
)
112 BOOL ret
= CPaintDC::RestoreDC(nSavedDC
);
114 if (m_bBoundsUpdated
)
116 SelectObject(m_hPaintBitmap
);