123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960 |
- // CacheDC.cpp : 实现文件
- //
- #include "stdafx.h"
- #include "HJHomework.h"
- #include "CacheDC.h"
- // CCacheDC
- CCacheDC::CCacheDC(CDC *pDC,CRect rect/* = CRect(0, 0, 0, 0)*/, BOOL bCopyFirst/* = TRUE*/)
- :CDC(), m_oldBitmap(NULL), m_pDC(pDC)
- {
- ASSERT(m_pDC != NULL); // 断言参数不为空
- m_bMemDC = !pDC->IsPrinting(); // 判断设备是否用于打印
- if (m_bMemDC)
- {
- CreateCompatibleDC(pDC); // 创建一个内存DC
- if (rect == CRect(0, 0, 0, 0)) // 判断绘画区域
- {
- pDC->GetClipBox(&m_rect); // 得到一个能够完整包含当前可见区域的最小矩形的大小
- }else
- {
- m_rect = rect;
- }
- //创建兼容位图
- m_bitmap.CreateCompatibleBitmap(pDC, m_rect.Width(), m_rect.Height());
- m_oldBitmap = SelectObject(&m_bitmap); // 保留旧位图对象
- SetWindowOrg(m_rect.left, m_rect.top); // 移动窗口原点
- if (bCopyFirst) // 初次复制
- {
- this->BitBlt(m_rect.left, m_rect.top, m_rect.Width(), m_rect.Height(), m_pDC, m_rect.left, m_rect.top, SRCCOPY);
- }
- }
- else
- {
- //创建一个跟当前DC绘制有关的副本
- m_bPrinting = pDC->m_bPrinting;
- m_hDC = pDC->m_hDC;
- m_hAttribDC = pDC->m_hAttribDC;
- }
- }
- CCacheDC::~CCacheDC()
- {
- if (m_bMemDC)
- {
- // 复制屏幕外位图到屏幕内
- m_pDC->BitBlt(m_rect.left, m_rect.top, m_rect.Width(), m_rect.Height(), this, m_rect.left, m_rect.top, SRCCOPY);
- SelectObject(m_oldBitmap); //交换原来的位图
- }else
- {
- m_hDC = m_hAttribDC = NULL;
- }
- }
|