CodeGuru
Earthweb Search
Forums Wireless Jars Gamelan Developer.com
CodeGuru Navigation
Member Sign In
User ID:
Password:
Remember Me:
Forgot Password?
Not a member?
Click here for more information and to register.

Become a Marketplace Partner

jobs.internet.com

internet.commerce
Partners & Affiliates
















RSS Feeds

RSSAll

RSSVC++/C++

RSS.NET/C#

RSSVB

See more EarthWeb Network feeds

Home >> Visual C++ / C++ >> Controls >> Static Control


Colored Static Controls
Rating:

Davide Calabro (view profile)
February 1, 1999


(continued)



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:
davide_calabro@yahoo.com
SoftechSoftware homepage:
http://members.tripod.com/~SoftechSoftware/index.html
CColorStaticST homepage:
http://members.tripod.com/~SoftechSoftware/colorstc.html

Tools:
Add www.codeguru.com to your favorites
Add www.codeguru.com to your browser search box
IE 7 | Firefox 2.0 | Firefox 1.5.x
Receive news via our XML/RSS feed







RATE THIS ARTICLE:   Excellent  Very Good  Average  Below Average  Poor  

(You must be signed in to rank an article. Not a member? Click here to register)

Latest Comments:
I have added stopTextBlinking() function - easy cock (03/29/2006)
Instant colored static control - Ovidiu Vlad (11/11/2005)
Error without using class wizzard - Legacy CodeGuru (01/19/2004)
Tool Tips / Quick Info? - Legacy CodeGuru (12/10/2003)
readonly - Legacy CodeGuru (10/21/2003)

View All Comments
Add a Comment:
Title:
Comment:
Pre-Formatted: Check this if you want the text to display with the formatting as typed (good for source code)



(You must be signed in to comment on an article. Not a member? Click here to register)


JupiterOnlineMedia

internet.comearthweb.comDevx.commediabistro.comGraphics.com

Search:

Jupitermedia Corporation has two divisions: Jupiterimages and JupiterOnlineMedia

Jupitermedia Corporate Info


Legal Notices, Licensing, Reprints, & Permissions, Privacy Policy.

Advertise | Newsletters | Tech Jobs | Shopping | E-mail Offers