Advertisement
Guest User

Untitled

a guest
Jan 17th, 2017
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.95 KB | None | 0 0
  1. class TColorText : public CStatic
  2. {
  3. protected:
  4. DECLARE_MESSAGE_MAP( )
  5.  
  6. public:
  7. TColorText();
  8. // make the background transparent (or if ATransparent == true, restore the previous background color)
  9. void setTransparent( bool ATransparent = true );
  10. // set background color and make the background opaque
  11. void SetBackgroundColor( COLORREF );
  12. void SetTextColor( COLORREF );
  13.  
  14. protected:
  15. HBRUSH CtlColor( CDC* pDC, UINT nCtlColor );
  16.  
  17. private:
  18. bool MTransparent;
  19. COLORREF MBackgroundColor; // default is white (in case someone sets opaque without setting a color)
  20. COLORREF MTextColor; // default is black. it would be more clean
  21. // to not use the color before set with SetTextColor(..), but whatever...
  22. };
  23.  
  24. #include "stdafx.h"
  25. #include "ColorText.h"
  26.  
  27. TColorText::TColorText()
  28. {
  29. MTransparent = TRUE;
  30. MBackgroundColor = RGB( 255, 255, 255 );
  31. MTextColor = RGB( 0, 0, 0 );
  32. }
  33.  
  34. //~TColorText::TColorText()
  35. //{
  36. //
  37. //}
  38.  
  39. void TColorText::setTransparent( bool ATransparent )
  40. {
  41. MTransparent = ATransparent;
  42. Invalidate( );
  43. }
  44.  
  45. void TColorText::SetBackgroundColor( COLORREF AColor )
  46. {
  47. MBackgroundColor = AColor;
  48. MTransparent = false;
  49. Invalidate( );
  50. }
  51.  
  52. void TColorText::SetTextColor( COLORREF AColor )
  53. {
  54. MTextColor = AColor;
  55. Invalidate( );
  56. }
  57.  
  58. BEGIN_MESSAGE_MAP( TColorText, CStatic )
  59. ON_WM_CTLCOLOR_REFLECT( )
  60. ON_WM_PAINT()
  61. END_MESSAGE_MAP( )
  62.  
  63. HBRUSH TColorText::CtlColor( CDC* pDC, UINT nCtlColor )
  64. {
  65. pDC->SetTextColor( MTextColor );
  66. pDC->SetBkMode( TRANSPARENT ); // we do not want to draw background when drawing text.
  67. // background color comes from drawing the control background.
  68. if( MTransparent )
  69. return NULL; // return nullptr to indicate that the parent object
  70. // should supply the brush. it has the appropriate background color.
  71. else
  72. return (HBRUSH) CreateSolidBrush( MBackgroundColor ); // color for the empty area of the control
  73. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement