AutoSelector.h
Upload User: zhoushen
Upload Date: 2022-06-15
Package Size: 84k
Code Size: 1k
Category:

Dialog_Window

Development Platform:

Visual C++

  1. ///////////////////////////////////////////
  2. // Saves current graphical drawing object,
  3. // selects a new one, then restores the old
  4. // one upon destruction.
  5. // 
  6. class AutoSelector
  7. {
  8. public:
  9. AutoSelector(CDC* pDC, CGdiObject* pNew)
  10. : m_pOld(pDC->SelectObject(pNew)),
  11.   m_pDC(pDC)
  12. {
  13. ASSERT(m_pOld);
  14. ASSERT(!pNew->IsKindOf(RUNTIME_CLASS(CRgn)));
  15. }
  16. AutoSelector(CDC* pDC, int iStockObject)
  17. : m_pOld(pDC->SelectStockObject(iStockObject)),
  18.   m_pDC(pDC)
  19. {
  20. ASSERT(m_pOld);
  21. }
  22. ~AutoSelector()
  23. {
  24. m_pDC->SelectObject(m_pOld);
  25. }
  26. private:
  27. AutoSelector(const AutoSelector&);
  28. AutoSelector& operator=(const AutoSelector&);
  29. // prevent region selection at compile-time
  30. AutoSelector(CDC* pDC, CRgn* pRgn);
  31. CGdiObject* m_pOld;
  32. CDC* m_pDC;
  33. };