memdc.h 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. #ifndef _MEMDC_H_
  2. #define _MEMDC_H_
  3. //////////////////////////////////////////////////
  4. // CMemDC - memory DC
  5. //
  6. // Author: Keith Rule
  7. // Email: keithr@europa.com
  8. // Copyright 1996-1997, Keith Rule
  9. //
  10. // You may freely use or modify this code provided this
  11. // Copyright is included in all derived versions.
  12. //
  13. // This class implements a memory Device Context
  14. class CMemDC : public CDC
  15. {
  16. private:
  17. CBitmap* m_bitmap;
  18. CBitmap* m_oldBitmap;
  19. CDC* m_pDC;
  20. CRect m_rcBounds;
  21. public:
  22. CMemDC(CDC* pDC, const CRect& rcBounds) : CDC()
  23. {
  24. CreateCompatibleDC(pDC);
  25. m_bitmap = new CBitmap;
  26. m_bitmap->CreateCompatibleBitmap(pDC, rcBounds.Width(), rcBounds.Height());
  27. m_oldBitmap = SelectObject(m_bitmap);
  28. m_pDC = pDC;
  29. m_rcBounds = rcBounds;
  30. }
  31. ~CMemDC()
  32. {
  33. m_pDC->BitBlt(m_rcBounds.left, m_rcBounds.top, m_rcBounds.Width(), m_rcBounds.Height(),
  34. this, m_rcBounds.left, m_rcBounds.top, SRCCOPY);
  35. SelectObject(m_oldBitmap);
  36. if (m_bitmap != NULL)
  37. delete m_bitmap;
  38. }
  39. CMemDC* operator->()
  40. {
  41. return this;
  42. }
  43. };
  44. #endif