-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathBufferDC.cpp
More file actions
120 lines (92 loc) · 2.43 KB
/
BufferDC.cpp
File metadata and controls
120 lines (92 loc) · 2.43 KB
1
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
#include "StdAfx.h"
#include "BufferDC.h"
IMPLEMENT_DYNAMIC(CBufferDC, CPaintDC)
CBufferDC::CBufferDC(CWnd* pWnd) : CPaintDC(pWnd)
{
if (pWnd != NULL && CPaintDC::m_hDC != NULL)
{
m_hOutputDC = CPaintDC::m_hDC;
m_hAttributeDC = CPaintDC::m_hAttribDC;
pWnd->GetClientRect(&m_ClientRect);
m_hMemoryDC = ::CreateCompatibleDC(m_hOutputDC);
m_hPaintBitmap =
::CreateCompatibleBitmap(
m_hOutputDC,
m_ClientRect.right - m_ClientRect.left,
m_ClientRect.bottom - m_ClientRect.top);
m_hOldBitmap = (HBITMAP)::SelectObject(m_hMemoryDC, m_hPaintBitmap);
CPaintDC::m_hDC = m_hMemoryDC;
CPaintDC::m_hAttribDC = m_hMemoryDC;
}
m_bBoundsUpdated = FALSE;
}
CBufferDC::~CBufferDC(void)
{
Flush();
::SelectObject(m_hMemoryDC, m_hOldBitmap);
::DeleteObject(m_hPaintBitmap);
CPaintDC::m_hDC = m_hOutputDC;
CPaintDC::m_hAttribDC = m_hAttributeDC;
::DeleteDC(m_hMemoryDC);
}
void CBufferDC::Flush()
{
::BitBlt(
m_hOutputDC,
m_ClientRect.left, m_ClientRect.top,
m_ClientRect.right - m_ClientRect.left,
m_ClientRect.bottom - m_ClientRect.top,
m_hMemoryDC,
0, 0,
SRCCOPY);
}
UINT CBufferDC::SetBoundsRect( LPCRECT lpRectBounds, UINT flags )
{
if (lpRectBounds != NULL)
{
if (m_ClientRect.right - m_ClientRect.left > lpRectBounds->right - lpRectBounds->left ||
m_ClientRect.bottom - m_ClientRect.top > lpRectBounds->bottom - lpRectBounds->top)
{
lpRectBounds = &m_ClientRect;
}
HBITMAP bmp =
::CreateCompatibleBitmap(
m_hOutputDC,
lpRectBounds->right - lpRectBounds->left,
lpRectBounds->bottom - lpRectBounds->top);
HDC tmpDC = ::CreateCompatibleDC(m_hOutputDC);
HBITMAP oldBmp = (HBITMAP)::SelectObject(tmpDC, bmp);
::BitBlt(
tmpDC,
m_ClientRect.left, m_ClientRect.top,
m_ClientRect.right - m_ClientRect.left,
m_ClientRect.bottom - m_ClientRect.top,
m_hMemoryDC,
0, 0,
SRCCOPY);
::SelectObject(tmpDC, oldBmp);
::DeleteDC(tmpDC);
HBITMAP old = (HBITMAP)::SelectObject(m_hMemoryDC, bmp);
if (old != NULL && old != m_hPaintBitmap)
{
::DeleteObject(old);
}
if (m_hPaintBitmap != NULL)
{
::DeleteObject(m_hPaintBitmap);
}
m_hPaintBitmap = bmp;
m_ClientRect = *lpRectBounds;
m_bBoundsUpdated = TRUE;
}
return CPaintDC::SetBoundsRect(lpRectBounds, flags);
}
BOOL CBufferDC::RestoreDC( int nSavedDC )
{
BOOL ret = CPaintDC::RestoreDC(nSavedDC);
if (m_bBoundsUpdated)
{
SelectObject(m_hPaintBitmap);
}
return ret;
}