Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class TColorText : public CStatic
- {
- protected:
- DECLARE_MESSAGE_MAP( )
- public:
- TColorText();
- // make the background transparent (or if ATransparent == true, restore the previous background color)
- void setTransparent( bool ATransparent = true );
- // set background color and make the background opaque
- void SetBackgroundColor( COLORREF );
- void SetTextColor( COLORREF );
- protected:
- HBRUSH CtlColor( CDC* pDC, UINT nCtlColor );
- private:
- bool MTransparent;
- COLORREF MBackgroundColor; // default is white (in case someone sets opaque without setting a color)
- COLORREF MTextColor; // default is black. it would be more clean
- // to not use the color before set with SetTextColor(..), but whatever...
- };
- #include "stdafx.h"
- #include "ColorText.h"
- TColorText::TColorText()
- {
- MTransparent = TRUE;
- MBackgroundColor = RGB( 255, 255, 255 );
- MTextColor = RGB( 0, 0, 0 );
- }
- //~TColorText::TColorText()
- //{
- //
- //}
- void TColorText::setTransparent( bool ATransparent )
- {
- MTransparent = ATransparent;
- Invalidate( );
- }
- void TColorText::SetBackgroundColor( COLORREF AColor )
- {
- MBackgroundColor = AColor;
- MTransparent = false;
- Invalidate( );
- }
- void TColorText::SetTextColor( COLORREF AColor )
- {
- MTextColor = AColor;
- Invalidate( );
- }
- BEGIN_MESSAGE_MAP( TColorText, CStatic )
- ON_WM_CTLCOLOR_REFLECT( )
- ON_WM_PAINT()
- END_MESSAGE_MAP( )
- HBRUSH TColorText::CtlColor( CDC* pDC, UINT nCtlColor )
- {
- pDC->SetTextColor( MTextColor );
- pDC->SetBkMode( TRANSPARENT ); // we do not want to draw background when drawing text.
- // background color comes from drawing the control background.
- if( MTransparent )
- return NULL; // return nullptr to indicate that the parent object
- // should supply the brush. it has the appropriate background color.
- else
- return (HBRUSH) CreateSolidBrush( MBackgroundColor ); // color for the empty area of the control
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement