00001 #if !defined(AFX_MEMDC_H__CA1D3541_7235_11D1_ABBA_00A0243D1382__INCLUDED_)
00002 #define AFX_MEMDC_H__CA1D3541_7235_11D1_ABBA_00A0243D1382__INCLUDED_
00003
00004 #if _MSC_VER >= 1000
00005 #pragma once
00006 #endif // _MSC_VER >= 1000
00007
00008
00009
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026 class CMemDC : public CDC
00027 {
00028 public:
00029
00030
00031 CMemDC(CDC* pDC) : CDC()
00032 {
00033 ASSERT(pDC != NULL);
00034
00035 m_pDC = pDC;
00036 m_pOldBitmap = NULL;
00037 #ifndef _WIN32_WCE_NO_PRINTING
00038 m_bMemDC = !pDC->IsPrinting();
00039 #else
00040 m_bMemDC = FALSE;
00041 #endif
00042
00043 if (m_bMemDC)
00044 {
00045 pDC->GetClipBox(&m_rect);
00046 CreateCompatibleDC(pDC);
00047 m_bitmap.CreateCompatibleBitmap(pDC, m_rect.Width(), m_rect.Height());
00048 m_pOldBitmap = SelectObject(&m_bitmap);
00049 #ifndef _WIN32_WCE
00050 SetWindowOrg(m_rect.left, m_rect.top);
00051 #endif
00052
00053
00054
00055 FillSolidRect(m_rect, pDC->GetBkColor());
00056 }
00057 else
00058 {
00059 #if !defined(_WIN32_WCE) || ((_WIN32_WCE > 201) && !defined(_WIN32_WCE_NO_PRINTING))
00060 m_bPrinting = pDC->m_bPrinting;
00061 #endif
00062 m_hDC = pDC->m_hDC;
00063 m_hAttribDC = pDC->m_hAttribDC;
00064 }
00065
00066 }
00067
00068
00069 ~CMemDC()
00070 {
00071 if (m_bMemDC)
00072 {
00073
00074 m_pDC->BitBlt(m_rect.left, m_rect.top, m_rect.Width(), m_rect.Height(),
00075 this, m_rect.left, m_rect.top, SRCCOPY);
00076
00077
00078 SelectObject(m_pOldBitmap);
00079 } else {
00080
00081
00082
00083 m_hDC = m_hAttribDC = NULL;
00084 }
00085 }
00086
00087
00088 CMemDC* operator->() {return this;}
00089
00090
00091 operator CMemDC*() {return this;}
00092
00093 private:
00094 CBitmap m_bitmap;
00095 CBitmap* m_pOldBitmap;
00096 CDC* m_pDC;
00097 CRect m_rect;
00098 BOOL m_bMemDC;
00099 };
00100
00102
00103
00104
00105
00106 #endif // !defined(AFX_MEMDC_H__CA1D3541_7235_11D1_ABBA_00A0243D1382__INCLUDED_)