PropertyGrid_DrawHelpers.h 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. #pragma once
  2. //////////////////////////////////////////////////////////////////////
  3. // CPGEmptyRect class
  4. class CPGEmptyRect : public CRect
  5. {
  6. public:
  7. CPGEmptyRect()
  8. {
  9. SetRectEmpty();
  10. }
  11. };
  12. //////////////////////////////////////////////////////////////////////
  13. // CPGWindowRect class
  14. class CPGWindowRect : public CRect
  15. {
  16. public:
  17. CPGWindowRect (HWND hWnd)
  18. {
  19. ::GetWindowRect (hWnd, this);
  20. };
  21. CPGWindowRect (const CWnd* pWnd)
  22. {
  23. ::GetWindowRect (pWnd->GetSafeHwnd(), this);
  24. };
  25. };
  26. //////////////////////////////////////////////////////////////////////
  27. // CPGClientRect class
  28. class CPGClientRect : public CRect
  29. {
  30. public:
  31. CPGClientRect (const CWnd* pWnd)
  32. {
  33. ::GetClientRect (pWnd->GetSafeHwnd(), this);
  34. };
  35. };
  36. //////////////////////////////////////////////////////////////////////
  37. // CPGBufferDC class
  38. class CPGBufferDC : public CDC
  39. {
  40. HDC m_hDestDC;
  41. CBitmap m_bitmap; // Bitmap in Memory DC
  42. CRect m_rect;
  43. HGDIOBJ m_hOldBitmap; // Previous Bitmap
  44. public:
  45. CPGBufferDC (HDC hDestDC, const CRect rcPaint) : m_hDestDC (hDestDC)
  46. {
  47. m_rect = rcPaint;
  48. VERIFY(Attach (::CreateCompatibleDC (m_hDestDC)));
  49. m_bitmap.Attach (::CreateCompatibleBitmap (m_hDestDC, m_rect.right, m_rect.bottom));
  50. m_hOldBitmap = ::SelectObject (m_hDC, m_bitmap);
  51. }
  52. ~CPGBufferDC ()
  53. {
  54. // VERIFY(::BitBlt (m_hDestDC, m_rect.left, m_rect.top, m_rect.Width(), m_rect.Height(), m_hDC, m_rect.left, m_rect.top, SRCCOPY));
  55. ::BitBlt (m_hDestDC, m_rect.left, m_rect.top, m_rect.Width(), m_rect.Height(), m_hDC, m_rect.left, m_rect.top, SRCCOPY);
  56. ::SelectObject (m_hDC, m_hOldBitmap);
  57. }
  58. };
  59. //////////////////////////////////////////////////////////////////////
  60. // CPGFontDC class
  61. class CPGFontDC
  62. {
  63. CDC* m_pDC;
  64. CFont* m_pOldFont;
  65. public:
  66. CPGFontDC (CDC* pDC, CFont* pFont) : m_pDC (pDC)
  67. {
  68. m_pOldFont = (CFont*) m_pDC->SelectObject (pFont);
  69. }
  70. ~CPGFontDC()
  71. {
  72. m_pDC->SelectObject (m_pOldFont);
  73. }
  74. };
  75. //////////////////////////////////////////////////////////////////////
  76. // CPGPenDC class
  77. class CPGPenDC
  78. {
  79. protected:
  80. CPen m_pen;
  81. HDC m_hDC;
  82. HPEN m_hOldPen;
  83. public:
  84. CPGPenDC (HDC hDC, COLORREF crColor): m_hDC (hDC)
  85. {
  86. VERIFY(m_pen.CreatePen (PS_SOLID, 1, crColor));
  87. m_hOldPen = (HPEN)::SelectObject (m_hDC, m_pen);
  88. }
  89. ~CPGPenDC ()
  90. {
  91. ::SelectObject (m_hDC, m_hOldPen);
  92. }
  93. };
  94. //////////////////////////////////////////////////////////////////////
  95. // CPGBrushDC class
  96. class CPGBrushDC
  97. {
  98. protected:
  99. CBrush m_brush;
  100. HDC m_hDC;
  101. HBRUSH m_hOldBrush;
  102. public:
  103. CPGBrushDC (HDC hDC, COLORREF crColor): m_hDC (hDC)
  104. {
  105. VERIFY(m_brush.CreateSolidBrush (crColor));
  106. m_hOldBrush = (HBRUSH)::SelectObject (m_hDC, m_brush);
  107. }
  108. ~CPGBrushDC ()
  109. {
  110. ::SelectObject (m_hDC, m_hOldBrush);
  111. }
  112. };