Colored Static Controls

Description

CColorStaticST is a class derived from MFC CStatic class.

This class lets put static controls inside your applications
and easly make them colored or even blinking!
CColorStaticST image



CColorStaticST features:


  • Standard CStatic properties
  • Customizable background color
  • Customizable text color
  • Background color can blink
  • Text can blink
  • Notification message can be sent on rising blinks
  • Written in Visual C++ v5.0
  • Full source code included!
  • It’s free!



You are encouraged to use this class everywhere you want; there is no fee
required for CColorStaticST. Freely add modifications and/or fix bugs, but please,
send any of these to SoftechSoftware!

How to integrate CColorStaticST in your application

In your project include the following files:

   ColorStaticST.h
ColorStaticST.cpp

With dialog editor create a static text called, for example, IDC_DANGER
and create a member variable for it:

   CColorStaticST m_stcDanger;

Now attach the static text to CColorStaticST. In your OnInitDialog procedure:

   // Call the base method
   CDialog::OnInitDialog();

   // Create the IDC_DANGER text
   m_stcDanger.SubclassDlgItem(IDC_DANGER, this);

By default the static text will have the standard system colors. Both
text and backgroud color can be customized:

   // Change the text color to White
   m_stcDanger.SetTextColor(RGB(255, 255, 255));
   // Change the background color to Green
   m_stcDanger.SetBkColor(RGB(0, 255, 0));

The text and/or the background can blink! Two colors must be
supplied for text and background blinks. First color will be
used for blink OFF state and second color for blink ON state (called also rising blink):

   // Set blink colors for text
   m_stcDanger.SetBlinkTextColors(RGB(128, 0, 0), RGB(255, 255, 255));

   // Set blink colors for background
   m_stcDanger.SetBlinkBkColors(RGB(128, 0, 0), RGB(255, 0, 0));

   // Start text blinking
   m_stcDanger.StartTextBlink(TRUE, CColorStaticST::ST_FLS_FAST);

   // Start background blinking
   m_stcDanger.StartBkBlink(TRUE, CColorStaticST::ST_FLS_FAST);

CColorStaticST can send a message to the parent window each time it has a
rising blink. To do this a user defined message and a parent window must be
supplied:

   // Enable notification message
   m_stcDanger.EnableNotify(this, WM_USER + 10);

Your static text is now a CColorStaticST!

Look inside the demo program to learn more about CColorStaticST. This is the best way!

CColorStaticST members

void SetTextColor(COLORREF crTextColor = 0xffffffff);

Set color for text (when not blinking)
Input values:


  • crTextColor

    The new text color

Example:


m_stcDanger.SetTextColor(RGB(255, 255, 255));

m_stcDanger.SetTextColor(); // To restore the default system color

COLORREF GetTextColor();

Get current text color
Example:


COLORREF crRetValue = m_stcDanger.GetTextColor();

void SetBkColor(COLORREF crBkColor = 0xffffffff);

Set color for background (when not blinking)
Input values:


  • crBkColor

    The new background color

Example:


m_stcDanger.SetBkColor(RGB(255, 0, 0));

m_stcDanger.SetBkColor(); // To restore the default system color

COLORREF GetBkColor();
Get current background color

Example:


COLORREF crRetValue = m_stcDanger.GetBkColor();


void SetBlinkTextColors(COLORREF crBlinkTextColor1, COLORREF crBlinkTextColor2);

Set colors for text (when blinking)

Input values:


  • crBlinkTextColor1

    Text color for blink OFF state
  • crBlinkTextColor2

    Text color for blink ON state (rising blink)

Example:


m_stcDanger.SetBlinkTextColors(RGB(128, 0, 0), RGB(255, 255, 255));


void StartTextBlink(BOOL bStart = TRUE, UINT nElapse = ST_FLS_NORMAL);


Start/stop text blinking

Input values:


  • bStart

    TRUE starts blinking

    FALSE stops blinking

  • nElapse

    Defines the text blinking intervall. Possible values are:

    ST_FLS_SLOW (2000 ms)

    ST_FLS_NORMAL (1000 ms)

    ST_FLS_FAST (500 ms)


Example:


m_stcDanger.StartTextBlink(TRUE, CColorStaticST::ST_FLS_FAST);

m_stcDanger.StartTextBlink(TRUE, 250); // To blink with custom intervall

m_stcDanger.StartTextBlink(); // To stop blinking


void SetBlinkBkColors(COLORREF crBlinkBkColor1, COLORREF crBlinkBkColor2);


Set colors for background (when blinking)

Input values:


  • crBlinkBkColor1

    Background color for blink OFF state
  • crBlinkBkColor2

    Background color for blink ON state (rising blink)

Example:


m_stcDanger.SetBlinkBkColors(RGB(128, 0, 0), RGB(255, 0, 0));


void StartBkBlink(BOOL bStart = TRUE, UINT nElapse = ST_FLS_NORMAL);


Start/stop background blinking

See StartTextBlink for possible input values

Example:


m_stcDanger.StartBkBlink(TRUE, CColorStaticST::ST_FLS_FAST);

m_stcDanger.StartBkBlink(TRUE, 250); // To blink with custom intervall

m_stcDanger.StartBkBlink(); // To stop blinking


void EnableNotify(CWnd* pParent = NULL, UINT nMsg = WM_USER);


Enable/Disable sending notification message on rising blinks

Input values:


  • pParent

    Parent window of the static text
  • nMsg

    Message to send

Example:


m_stcDanger.EnableNotify(this, WM_USER + 10);

m_stcDanger.EnableNotify(); // To disable message sending


static const short GetVersionI()

static const char* GetVersionC()


Return CColorStaticST version

Example:


int nVer = CColorStaticST::GetVersionI(); // Divide by 10 to get actual version

char szVer[20];

strcpy(szVer, CColorStaticST::GetVersionC());

Download the demo project (99Kb).

History


  • CColorStaticST v1.0

    First release

Things to do


  • Any suggestion?

Contact addresses

SoftechSoftware E-Mail:

[email protected]

SoftechSoftware homepage:

http://members.tripod.com/~SoftechSoftware/index.html

CColorStaticST homepage:

http://members.tripod.com/~SoftechSoftware/colorstc.html

More by Author

Must Read