Click here to Skip to main content
Click here to Skip to main content

CStaticFader

, 27 Dec 1999
Rate this:
Please Sign up or sign in to vote.
A CStatic class that gently fades text into view
  • Download demo project - 95 Kb
  • Download source files - 3 Kb
  • Sample Image - static_fader.gif

    <!-- 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 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 Wink | ;)

    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:

    License

    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

    Share

    About the Author

    Jason Troitsky

    United Kingdom United Kingdom
    No Biography provided

    Comments and Discussions

     
    GeneralVery nice - thanks PinmemberPaul Roberts5-Mar-09 2:55 
    Generalthanks.. this i's exactly what I want Pinmemberbektek20-Nov-04 14:29 
    GeneralMemory leak PinsussDavid Coffman14-Sep-00 9:37 
    GeneralRe: Memory leak PinmemberDave Sitar4-Feb-01 13:47 
    GeneralError in Resizing Pinsussleonardo16-May-00 17:46 
    GeneralRe: Error in Resizing PinmemberDmitry Rizshkov9-Jul-01 22:19 
    GeneralRe: Error in Resizing PinmemberAnonymous13-Mar-02 1:53 

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

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

    | Advertise | Privacy | Terms of Use | Mobile
    Web02 | 2.8.1411023.1 | Last Updated 28 Dec 1999
    Article Copyright 1999 by Jason Troitsky
    Everything else Copyright © CodeProject, 1999-2014
    Layout: fixed | fluid