MemDC.h
上传用户:tintim
上传日期:2022-05-14
资源大小:1573k
文件大小:2k
源码类别:

网络截获/分析

开发平台:

Visual C++

  1. #if !defined(AFX_MEMDC_H__CA1D3541_7235_11D1_ABBA_00A0243D1382__INCLUDED_)
  2. #define AFX_MEMDC_H__CA1D3541_7235_11D1_ABBA_00A0243D1382__INCLUDED_
  3. #if _MSC_VER >= 1000
  4. #pragma once
  5. #endif // _MSC_VER >= 1000
  6. //////////////////////////////////////////////////
  7. // CMemDC 实现一个内存DC
  8. class CMemDC : public CDC
  9. {
  10. private:
  11.     CBitmap  m_bitmap;      // 实际的bitmap
  12.     CBitmap* m_pOldBitmap;  // 原先在CMemDC中的位图
  13.     CDC*     m_pDC;         // 保存从构造函数中传来的CDC
  14.     CRect    m_rect;        // 画的矩形区域
  15.     BOOL     m_bMemDC;      // 如果CDC是一个内存DC,则为TRUE
  16. public:
  17.     CMemDC(CDC* pDC) : CDC()
  18.     {
  19.         ASSERT(pDC != NULL);
  20.         m_pDC = pDC;
  21.         m_pOldBitmap = NULL;
  22.         m_bMemDC = !pDC->IsPrinting();//判断是否是一个内存DC
  23.               
  24.         if (m_bMemDC)    // 创建一个内存DC
  25.         {
  26.             pDC->GetClipBox(&m_rect);
  27.             CreateCompatibleDC(pDC);
  28.             m_bitmap.CreateCompatibleBitmap(pDC, m_rect.Width(), m_rect.Height());
  29.             m_pOldBitmap = SelectObject(&m_bitmap);
  30.             SetWindowOrg(m_rect.left, m_rect.top);
  31.         }
  32.         else  // 这不是一个内存DC,我们只拷贝相关的DC部分以备打印
  33.         {
  34.             m_bPrinting = pDC->m_bPrinting;
  35.             m_hDC       = pDC->m_hDC;
  36.             m_hAttribDC = pDC->m_hAttribDC;
  37.         }
  38.     }
  39.    
  40.     ~CMemDC()
  41.     {
  42.         if (m_bMemDC) 
  43.         {    
  44.             // 拷贝实际的位图到屏幕上
  45.             m_pDC->BitBlt(m_rect.left, m_rect.top, m_rect.Width(), m_rect.Height(),
  46.                           this, m_rect.left, m_rect.top, SRCCOPY);
  47.             //装入原始的位图
  48.             SelectObject(m_pOldBitmap);
  49.         } 
  50. else 
  51. {
  52.             m_hDC = m_hAttribDC = NULL;
  53.         }
  54.     }
  55.     // 允许作为指针
  56.     CMemDC* operator->() {return this;}
  57.     operator CMemDC*() {return this;}
  58. };
  59. /////////////////////////////////////////////////////////////////////////////
  60. //{{AFX_INSERT_LOCATION}}
  61. // Microsoft Developer Studio will insert additional declarations immediately before the previous line.
  62. #endif // !defined(AFX_MEMDC_H__CA1D3541_7235_11D1_ABBA_00A0243D1382__INCLUDED_)