Download demo project - 95 KbDownload source files - 3 Kb
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
subclass a 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").
The 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 SetAlignLeft()
void SetAlignRight()
void SetAlignCentre()
void SetDrawShadow(bool bShadow)
void SetDrawBorder(bool bBorder)
COLORREF GetBackgroundColour()
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 Initialise
and
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.
The Display()
function's last two parameters are designed for optional
use with Jamie's CAutoFont::ExtractFont()
function. These have not been
tested ;)
To use the class, assume you have a CStaticFader
object called
m_stcFader
.
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.SetDrawShadow();
m_stcFader.SetAlignCentre();
m_stcFader.Display("This demonstrates the changing of all the colours (plus shadow)",
"119:71", 100);
Other Cool Classes Used:
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.