Download demo project - 95 Kb
Download source files - 3 Kb
<!-- Article Starts -->
This article presents a
CStatic derived class that gently fades text into view.
To use the class simply declare a
CStaticFader object, and then have that object
CStatic control on a dialog or form. The control can display a single line of
text, or two separate test strings on a single line (the "Main Text" and "SubText").
CStaticFader class was designed to be used in a ticker app that I
was in the process of writing (at the time of this post). I pulled it out, neatened it up
and documented it purely for CodeProject enthusiasts.
The member functions of
CStaticFader are as follows
void Initialise( COLORREF crBackground, COLORREF crMainText, COLORREF crSubText)
void SetDrawShadow(bool bShadow)
void SetDrawBorder(bool bBorder)
void SetBackgroundColour(COLORREF crColour)
void SetSubTextColour(COLORREF crColour)
void SetMainTextColour(COLORREF crColour)
void Display(CString strText, CString strSubText, int nFadePercent, bool bResetColours,
CString strSubFont, CString strMainFont)
Most of the functions are self-explanatory, with the exeption of
Display. Initialise takes 3 parameters representing the colours of the control
background, the Main Text colour, and the SubText colour respectively.
The Display method accepts the Main Text, the Sub Text, the fade percent (the
fraction of a second it takes to fade the text), and a flag specifying whether or
not colours should be reset to default values. If the SubText string is not empty,
it is displayed in a separate field (as shown in the screenshot), otherwise the entire
control is used for the MainText.
Display() function's last two parameters are designed for optional
use with Jamie's
CAutoFont::ExtractFont() function. These have not been
To use the class, assume you have a
CStaticFader object called
For this example we will set the background, Main Text, and SubText colours, set shadow
drawing as ON, center the text, then display some text and some SubText. We'll set the
nFadePercent value to 100 so that it takes a full second to fade the text into view:
m_stcFader.Initialise( RGB(100,100,150), RGB(200,200,0), RGB(0,220,0) );
m_stcFader.Display("This demonstrates the changing of all the colours (plus shadow)",
Other Cool Classes Used: