Click here to Skip to main content
15,922,407 members
Articles / Desktop Programming / MFC


Rate me:
Please Sign up or sign in to vote.
5.00/5 (11 votes)
27 Dec 1999 93.3K   3.5K   53   7
A CStatic class that gently fades text into view
  • Download demo project - 95 Kb
  • Download source files - 3 Kb
  • Sample Image - static_fader.gif

    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.Display("This demonstrates the changing of all the colours (plus shadow)",
                       "119:71", 100);

    Other Cool Classes Used:


    This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

    A list of licenses authors might use can be found here

    Written By
    United Kingdom United Kingdom
    This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

    Comments and Discussions

    GeneralVery nice - thanks Pin
    Paul Roberts5-Mar-09 1:55
    Paul Roberts5-Mar-09 1:55 
    Generalthanks.. this i's exactly what I want Pin
    bektek20-Nov-04 13:29
    bektek20-Nov-04 13:29 
    GeneralMemory leak Pin
    David Coffman14-Sep-00 8:37
    sussDavid Coffman14-Sep-00 8:37 
    GeneralRe: Memory leak Pin
    4-Feb-01 12:47
    suss4-Feb-01 12:47 
    GeneralError in Resizing Pin
    Member 240716-May-00 16:46
    Member 240716-May-00 16:46 
    GeneralRe: Error in Resizing Pin
    Dmitry Rizshkov9-Jul-01 21:19
    Dmitry Rizshkov9-Jul-01 21:19 
    GeneralRe: Error in Resizing Pin
    13-Mar-02 0:53
    suss13-Mar-02 0:53 

    General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

    Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.