ColorStatic.cpp
上传用户:kairuinn
上传日期:2009-02-07
资源大小:2922k
文件大小:3k
源码类别:

图形图象

开发平台:

Visual C++

  1. /* ==========================================================================
  2. Class : CColorStatic
  3. Author : Johan Rosengren, Abstrakt Mekanik AB
  4. Date : 2004-07-25
  5. Purpose : "CColorStatic" is a CStatic-derived class representing 
  6. a colored box 
  7. Description : The control is a "CStatic", overriding "OnPaint".
  8. Usage : The control can be used to display a specific color in 
  9. a dialog. Call "SetColor" to set the color to display.
  10.    ========================================================================*/
  11. #include "stdafx.h"
  12. #include "ColorStatic.h"
  13. #ifdef _DEBUG
  14. #define new DEBUG_NEW
  15. #undef THIS_FILE
  16. static char THIS_FILE[] = __FILE__;
  17. #endif
  18. /////////////////////////////////////////////////////////////////////////////
  19. // CColorStatic
  20. CColorStatic::CColorStatic()
  21. /* ============================================================
  22. Function : CColorStatic::CColorStatic
  23. Description : Constructor
  24. Access : Public
  25. Return : void
  26. Parameters : none
  27. Usage :
  28.    ============================================================*/
  29. {
  30. }
  31. CColorStatic::~CColorStatic()
  32. /* ============================================================
  33. Function : CColorStatic::~CColorStatic
  34. Description : Destructor
  35. Access : Public
  36. Return : void
  37. Parameters : none
  38. Usage :
  39.    ============================================================*/
  40. {
  41. }
  42. BEGIN_MESSAGE_MAP(CColorStatic, CStatic)
  43. //{{AFX_MSG_MAP(CColorStatic)
  44. ON_WM_PAINT()
  45. ON_WM_ERASEBKGND()
  46. //}}AFX_MSG_MAP
  47. END_MESSAGE_MAP()
  48. /////////////////////////////////////////////////////////////////////////////
  49. // CColorStatic message handlers
  50. void CColorStatic::OnPaint() 
  51. /* ============================================================
  52. Function : CColorStatic::OnPaint
  53. Description : Handler for the "WM_PAINT" message.
  54. Access : Protected
  55. Return : void
  56. Parameters : none
  57. Usage : Called from MFC.
  58.    ============================================================*/
  59. {
  60. CPaintDC dc(this); // device context for painting
  61. CRect rect;
  62. CBrush brush;
  63. GetClientRect( rect );
  64. brush.CreateSolidBrush( m_color );
  65. dc.SelectStockObject( BLACK_PEN );
  66. dc.SelectObject( &brush );
  67. dc.Rectangle( rect );
  68. dc.SelectStockObject( WHITE_BRUSH );
  69. }
  70. void CColorStatic::SetColor( COLORREF color )
  71. /* ============================================================
  72. Function : CColorStatic::SetColor
  73. Description : Sets the color of the control
  74. Access : Public
  75. Return : void
  76. Parameters : COLORREF color - Color to display
  77. Usage : Call to set the color of this control.
  78.    ============================================================*/
  79. {
  80. m_color = color;
  81. if( m_hWnd )
  82. RedrawWindow();
  83. }
  84. BOOL CColorStatic::OnEraseBkgnd( CDC* /*pDC*/ ) 
  85. /* ============================================================
  86. Function : CColorStatic::OnEraseBkgnd
  87. Description : Handler for the "WM_ERASEBKGND" message.
  88. Access : Protected
  89. Return : BOOL - Always "TRUE"
  90. Parameters : CDC* pDC - "CDC" to erase
  91. Usage : Called from MFC.
  92.    ============================================================*/
  93. {
  94. return TRUE;
  95. }