Main Page | Class Hierarchy | Class List | File List | Class Members | File Members | Related Pages

MemDC.h

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 // MemDC.h : header file
00008 //
00009 
00011 // CMemDC - memory DC
00012 //
00013 // Author: Keith Rule
00014 // Email:  keithr@europa.com
00015 // Copyright 1996-1997, Keith Rule
00016 //
00017 // You may freely use or modify this code provided this
00018 // Copyright is included in all derived versions.
00019 //
00020 // History - 10/3/97 Fixed scrolling bug.
00021 //                   Added print support.
00022 //           25 feb 98 - fixed minor assertion bug
00023 //
00024 // This class implements a memory Device Context
00025 
00026 class CMemDC : public CDC
00027 {
00028 public:
00029 
00030     // constructor sets up the memory DC
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)    // Create a Memory DC
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             // EFW - Bug fix - Fill background in case the user has overridden
00053             // WM_ERASEBKGND.  We end up with garbage otherwise.
00054             // CJM - moved to fix a bug in the fix.
00055             FillSolidRect(m_rect, pDC->GetBkColor());
00056         }
00057         else        // Make a copy of the relevent parts of the current DC for printing
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     // Destructor copies the contents of the mem DC to the original DC
00069     ~CMemDC()
00070     {
00071         if (m_bMemDC)
00072         {
00073             // Copy the offscreen bitmap onto the screen.
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             //Swap back the original bitmap.
00078             SelectObject(m_pOldBitmap);
00079         } else {
00080             // All we need to do is replace the DC with an illegal value,
00081             // this keeps us from accidently deleting the handles associated with
00082             // the CDC that was passed to the constructor.
00083             m_hDC = m_hAttribDC = NULL;
00084         }
00085     }
00086 
00087     // Allow usage as a pointer
00088     CMemDC* operator->() {return this;}
00089         
00090     // Allow usage as a pointer
00091     operator CMemDC*() {return this;}
00092 
00093 private:
00094     CBitmap  m_bitmap;      // Offscreen bitmap
00095     CBitmap* m_pOldBitmap;  // bitmap originally found in CMemDC
00096     CDC*     m_pDC;         // Saves CDC passed in constructor
00097     CRect    m_rect;        // Rectangle of drawing area.
00098     BOOL     m_bMemDC;      // TRUE if CDC really is a Memory DC.
00099 };
00100 
00102 
00103 //{{AFX_INSERT_LOCATION}}
00104 // Microsoft Developer Studio will insert additional declarations immediately before the previous line.
00105 
00106 #endif // !defined(AFX_MEMDC_H__CA1D3541_7235_11D1_ABBA_00A0243D1382__INCLUDED_)

Generated on Tue Feb 17 02:03:07 2004 for harlem by doxygen 1.3.6