Scrolling credits using CStatic



Download source file or
demo project
.

This static subclass is based on the
Scrolling credits dialog by Mark Findlay.
I have made some modifications
to enable the use of resource strings, and added some functionality to make
the background look more professional.
By implementing the functionality through a CStatic subclass it is no
longer dependant on a dialog and can more
easily be used in different circumstances.

The control lets you scroll text and bitmaps in an like you see in movies.
It will continue to loop the text
for as long as it is active. The speed of the scrolling can be set by the
programmer. The control has the
following features:

  • The text/bitmap sequence can be set using a character string or through
    am ID to a string table entry.

  • The text/bitmap sequence is formatted with different colours and fonts
    through using special characters in the
    text. The mapping between the special characters and given colours and
    fonts can be set by the programmer

    NB! The bitmaps are given as quoted bitmap resources (ID as “IDB_BITMAP”
    instead of just IDB_BITMAP).

  • The background can be given a special colour or a background bitmap can
    be set.

    NB! While bitmaps in the
    text/bitmap sequence are restricted to 16 colours, the background bitmap
    have no such restriction.)

    If a solid colour background is used, it can be given a gradient to black
    or white, left-to-right or vice-versa.

  • The background of the bitmaps in the text/bitmap sequence can be made
    transparent to allow for non-square
    shapes. By setting a flag, the parts of the bitmaps that have the
    standard dialog colour (RGB(192,192,192))
    will be transparent.

    NB! There is a slight difference in how this functionality is implemented
    when using a background image
    instead of colour. Because of the way the addition of a background image
    is implemented all parts of the
    text/sequence that have the standard dialog colour will be transparent,
    not only the bitmaps. Also, when
    the transparent colour is _not_ set, all parts of the text/bitmap
    sequence that match the otherwise
    not active background colour, will be transparent as well. So, to
    disallow transparency when using a
    background image, set the background colour so an unused colour.

    NB! Because there is several bitblt’s involved when using a background
    image, the scrolling is slowed
    down considerably. But it does look good!! (If anyone can find ways of
    speeding up this process, please
    contact me!)

  • If not scrolling is started, a still picture of the text/bitmap sequence
    is displayed (That’s how the
    figure was created).

    Beware of the following differences between this implementation and the one
    of Mark Findlay:

  • Instead of an array of strings, this control uses a single string. This
    is to allow the use of resource strings.

    A delimiter character (standard ‘|’) is given to mark the beginning of a
    new line.

  • The special character denoting “normal” text has been removed. A line
    without any special character will be
    formatted according to the “normal text” rules.

  • Several of the default special characters have been changed, This was
    necessary because the string table
    resources did not understand all the original escape sequences.

To use CCreditStatic a member variable must be added to the dialog:

protected:
CCreditStatic m_static;

In OnInitDialog the static control is subclassed and the credit text is
added. Optionally a background image
can be added:

char *pArrCredit = { "NETBAS FOR WINDOWS NT\t||Copyright (c) 1998|"
        "Test Data AS|All Rights Reserved||"
        "BITMAP1^|||"    // this is a quoted bitmap resource 
        "Project Lead\r||Kjetil Kvamme|||"
        "Technical Lead\r||Kjetil Kvamme|||"
        "Engineering Lead\r||Paul K. Tonder|||"
        "Product Lead\r||Tom Rotting|||"
        "Engineering\r||Paul K. Tonder,  Rolf T. Wold,  Sigbjorn Helset|"
        "Reidar Ognedal,  Kjetil Kvamme, Arne Bakken|||"
        "BITMAP2^|||"  // this is a quoted bitmap resource 
        "QA\r||Mary Hech,  Sam Bamnm,  Ron Fonn,  Steve Waeve|"
        "Igor Borisnoff,  FellaB |||"
        "Documentation\r||"
        "Arvid Molnvik,  Joanne Hone,  Annette Fune|||"
        "Technical Program Office\r||Burf Murphy, Foll Roller||||"
        "Systems Support\r||Bendy Land|||"
        "Administrative Support\r||Donna Fonna|||"
        "* * * * * * * * *\t|||"
        "BITMAP3^||"
        "Project Manager\r||Dwain Kinghorn|||"
        "Engineering\r||"
        "Hank Bank,  Ray Fay,  Bill Sill,  Mark Dark,  Peter Leter|"
        "Lev Bef|||Quality Assurance\r||"
        "Biff Bin||||"
        "BITMAP4^|||||"
        };

BOOL CMyDialog::OnInitDialog()
{
        CDialog::OnInitDialog();

        m_static.SubclassDlgItem(IDC_DISPLAY_STATIC,this);
        m_static.SetCredits(pArrCredit);
        // m_static.SetCredits(IDS_CREDITS);  // Use with string resource
        m_static.SetSpeed(DISPLAY_FAST);
        m_static.SetColor(BACKGROUND_COLOR, RGB(0, 0, 255)); // Background Colour
        m_static.SetTransparent(); // Set parts of bitmaps with RGB(192,192,192) transparent
        m_static.SetGradient(GRADIENT_RIGHT_DARK);  // Background goes from blue to black from left to right
        // m_static.SetBkImage(IDB_BITMAP1); // Background image
        m_static.StartScrolling();
        return TRUE;  // return TRUE unless you set the focus to a control
                      // EXCEPTION: OCX Property Pages should return FALSE
}

Note: Keith Rule was kind enough to fix a number of resource leaks that can
bring the App down on Windows95. The fixes have mostly been to select the
original GDI objects back into the device context.

The example project shows one use of the
control. A Credits dialog is displayed when the user double-click in the view window.
In addition to showing the basics for using the control, the project also shows how
cycling of background images can be implemented. The background image is periodically
switched (every 5 seconds). This background image cycling management is implemented
in the dialog box rather than in the control itself. The background image is switched
through repeated calls to the BkImage method of the CCreditStatic object.

More by Author

Get the Free Newsletter!

Subscribe to Developer Insider for top news, trends & analysis

Must Read