WinXPButtonST.cpp 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. #include "stdafx.h"
  2. #include "WinXPButtonST.h"
  3. #ifdef _DEBUG
  4. #undef THIS_FILE
  5. static char THIS_FILE[]=__FILE__;
  6. #define new DEBUG_NEW
  7. #endif
  8. CWinXPButtonST::CWinXPButtonST()
  9. {
  10. // No rounded borders
  11. m_bIsRounded = FALSE;
  12. }
  13. CWinXPButtonST::~CWinXPButtonST()
  14. {
  15. }
  16. // This function is called every time the button border needs to be painted.
  17. // This is a virtual function that can be rewritten in CButtonST-derived classes
  18. // to produce a whole range of buttons not available by default.
  19. //
  20. // Parameters:
  21. // [IN] pDC
  22. // Pointer to a CDC object that indicates the device context.
  23. // [IN] pRect
  24. // Pointer to a CRect object that indicates the bounds of the
  25. // area to be painted.
  26. //
  27. // Return value:
  28. // BTNST_OK
  29. // Function executed successfully.
  30. //
  31. DWORD CWinXPButtonST::OnDrawBorder(CDC* pDC, CRect* pRect)
  32. {
  33. return BTNST_OK;
  34. } // End of OnDrawBorder
  35. // This function is called every time the button background needs to be painted.
  36. // If the button is in transparent mode this function will NOT be called.
  37. // This is a virtual function that can be rewritten in CButtonST-derived classes
  38. // to produce a whole range of buttons not available by default.
  39. //
  40. // Parameters:
  41. // [IN] pDC
  42. // Pointer to a CDC object that indicates the device context.
  43. // [IN] pRect
  44. // Pointer to a CRect object that indicates the bounds of the
  45. // area to be painted.
  46. //
  47. // Return value:
  48. // BTNST_OK
  49. // Function executed successfully.
  50. //
  51. DWORD CWinXPButtonST::OnDrawBackground(CDC* pDC, CRect* pRect)
  52. {
  53. if (!m_bMouseOnButton && !m_bIsPressed)
  54. return BASE_BUTTONST::OnDrawBackground(pDC, pRect);
  55. // Create and select a solid brush for button background
  56. CBrush brushBK(m_crColors[BTNST_COLOR_BK_IN]);
  57. CBrush* pOldBrush = pDC->SelectObject(&brushBK);
  58. // Create and select a thick black pen for button border
  59. CPen penBorder;
  60. penBorder.CreatePen(PS_SOLID, 1, RGB(0, 0, 0));
  61. CPen* pOldPen = pDC->SelectObject(&penBorder);
  62. if (m_bIsRounded)
  63. pDC->RoundRect(pRect, CPoint(8, 8));
  64. else
  65. pDC->Rectangle(pRect);
  66. // Put back the old objects
  67. pDC->SelectObject(pOldBrush);
  68. pDC->SelectObject(pOldPen);
  69. return BTNST_OK;
  70. } // End of OnDrawBackground
  71. // This function enables or disables the rounded border for the button.
  72. //
  73. // Parameters:
  74. // [IN] bRounded
  75. // If TRUE the button will have a round border.
  76. // [IN] bRepaint
  77. // If TRUE the button will be repainted.
  78. //
  79. // Return value:
  80. // BTNST_OK
  81. // Function executed successfully.
  82. //
  83. DWORD CWinXPButtonST::SetRounded(BOOL bRounded, BOOL bRepaint)
  84. {
  85. m_bIsRounded = bRounded;
  86. if (bRepaint) Invalidate();
  87. return BTNST_OK;
  88. } // End of SetRounded
  89. #undef BASE_BUTTONST