Click here to Skip to main content
Email Password   helpLost your password?
  • Download demo project - 176 Kb
  • Sample Image - ScrollingCredits.gif

    Introduction

    I wanted to have one of those fancy scrolling credits for an application I have been working on, and I couldn't find anything suitable. So I did what most of us end up doing when we can't find someone else's code to rip... I made my own. I wanted to be able to scroll text and bitmaps transparently over a bitmapped background.

    This code uses the CGDIThread class from the MTGDI MFC sample source code for the interface thread. The transparent blitting is accomplished using the "True Mask Method" explained in the article "Transparent Bitmap - True Mask Method" by Paul Reynolds.

    The text and bitmaps of the credits are printed on a memory bitmapped during initialization. The memory bitmap is then blitted to the screen repeatedly, each time starting at the next row, giving the effect of scrolling.

    The CCreditsThread class does all of the initialization and drawing of the credits. The fonts and colors that will be used are initialized, followed by the actual contents of the credits.

    The demo uses a dialog with an image covering it's entire surface. The credits can be displayed anywhere on the dialog. Whatever is behind the area the credits are displayed in will be used for the background of the scrolling.

    The transparent color in the demo is white, but it can be changed to whatever you like by changing the MASK_RGB #define in the CreditsThread.cpp file. Anything that uses the transparent color will not show up. This includes text and areas on bitmaps. If you wanted to use text that is the same color as the transparent color then use a color that is close to the transparent color.

    Example:

    RGB(255, 255, 255);   // transparent color
    
    RGB(250, 250, 250);   // text color
    
    

    Any available font face can be used. The fonts are initialized in the InitFonts() function using the LOGFONT structure and are added to an array of CFonts for quick retrieval. This also allows a large number of different fonts to be used.

    The font colors are initialized in the InitColors() function. Font color is independent of the font face being used. Any color can be used with any face, without having to create a new font. The font colors are also added to an array for quick retrieval.

    The actual contents of the credits are initialized in the InitText() function. The credits are stored as text strings describing the attributes and the content of each line.

    void CCreditsThread::InitText()
    {
    	// 1st pair of digits identifies the font to use
    
    	// 2nd pair of digits identifies the color to use
    
    	// B = Bitmap
    
    	// S = Space (moves down the specified number of pixels)
    
    
    	CString sTmp;
    
    	// start at the bottom of the screen
    
    	sTmp.Format(_T("S:%d"), m_rectScreen.Height());
    	m_arCredits.Add(sTmp);
    
    	m_arCredits.Add(_T("02:04:Transparent"));
    	m_arCredits.Add(_T("02:04:Scrolling Credits"));
    	m_arCredits.Add(_T("S:35"));
    	m_arCredits.Add(_T("01:00:Insert Bitmaps"));
    	m_arCredits.Add(_T("S:10"));
    	m_arCredits.Add(_T("B:JENNIFER"));
    	m_arCredits.Add(_T("S:35:"));
    
    	// pause before repeating
    
    	m_arCredits.Add(_T("S:30"));
    }
    

    Text Lines

    If the line in the credits is a text string, it has the following format:
    "02:04:Text to display"
    

    The first 2 digits are in index into the array of fonts to describe the font face to use for that line. Each line of text must specify the font to use. The font number must always be formatted as a 2 digit number at the beginning of the string. Following the font number is a colon.

    The next pair of digits are an index into the array of font colors, specifying the color to use for that line of text. The color index must also be formatted as a 2 digit number. The color index is followed by a colon.

    The next part of the string is the actual text to display.

    Bitmaps

    If the line in the credits is a bitmap, it will have the following format:
    "B:BALL"
    

    The bitmap resource must have a quoted name, like "BALL", instead of the customary style ID like IDB_BALL.

    Spacing

    You can specify the amount of spacing between lines in the credits.
    "S:25"
    

    The number specifies the number of pixels to move down. Lines of text are automatically spaced one line. You can also use spacing to cause the credits to start scrolling from the bottom of the screen initially, or to simulate a pause before the next section of credits is displayed, or until the credits are repeated.


    To use in your own projects


    You must Sign In to use this message board.
     
     
    Per page   
     FirstPrevNext
    Generalmemory leak!
    wwstudio_cn
    23:03 7 Dec '08  
    i use these code in my ppc program( show the scroll info in my about dialog) but every i open the dialog, the used memory will increase about ten kbyte.
    would u please give me some advice, thanks!
    GeneralBuild under VC9 (Orcas)
    rgallahan
    2:48 4 Dec '07  
    Although it throws a few warnings as expected, this compiles and runs OK under Vista when built with Microsoft Visual Studio Codename Orcas:

    Version 9.0.20404.0 Beta1
    Microsoft .NET Framework
    Version 2.0.50727
    Installed Edition: Professional
    Microsoft Visual C++ Codename "Orcas" 77626-xxx-xxxxxxx-xxxxx

    Thanks for a good starting place! I intend to use this as the basis for a video bulletin board for K-12 schools.
    General谢谢
    rensheng3
    6:24 24 Sep '07  
    我从中学到很多知识.

    GeneralGreat work!
    MaIron-cool
    21:42 13 Mar '07  
    Smile Smile Smile
    GeneralSmall prob.
    sumit siddheshwar
    20:01 8 Aug '06  


    I need to draw two overlapping rectangles with transparent colors. So the border of both rectangle and color effect is visible.

    Sumit Siddheshwar

    GeneralThanks, it is a good basis !!!
    2pers
    9:46 7 Mar '06  
    nothing more Wink
    GeneralThanks!
    WolfSupernova
    7:17 8 Nov '03  
    Great work! Smile

    There's a few things that I'd like to do with this. I'd like to add hyperlinks and the ability to scroll horizontally. For the hyperlinks, I suppose the easiest way would be to add another attribute to the array (which will be stored as elements in an XML file), but I think hit testing on the elements will be the difficult part.

    In terms of the horizontal scrolling, it looks like it's just a matter of changing the coordinates in the EnterCriticalSection(&CGDIThread::m_csGDILock) section and calculating widths instead of heights?

    If you have any ideas/recommendations/suggestions/thoughts about what I'm trying to accomplish, I'd love to hear them! Thanks again for the great article!

    Don
    GeneralModeless dialog?
    Ogi
    4:38 5 Sep '03  
    Your code works great, but I need to use my About Box as a splash screen. So, I need a modeless dialog (with Create() instead of DoModal() function). At first try the modeless dialog was unable to create a memory CDC in the CCreditsThread initialization. (dcMem.CreateCompatibleDC(&m_dc) just returns zero.)

    Any advise?
    GeneralRe: Modeless dialog?
    Ogi
    7:57 8 Sep '03  
    I found a solution for the modeless case.

    I just moved all of the Init functions from CCreditsThread to CCreditsDlg class, started a timer /SetTimer(1, m_nDelay, NULL)/ in the CCreditsDlg::OnInitDialog() function and placed the SingleStep() in the CCreditsDlg::OnTimer(UINT nIDEvent) function. Now, the About Box works fine either as a modal or a modeless dialog.

    In other words instead of a new thread with while { Sleep(m_nDelay) } I used a Timer with m_nDelay in the CCreditsDlg.
    GeneralGreat work - its is free??
    asfur
    7:23 1 Jul '03  
    Hello,

    It's work is free?????
    GeneralRe: Great work - its is free??
    Jim Connor
    16:43 1 Jul '03  
    Or course it's free. Smile
    GeneralNice work!
    Alvaro Mendez
    4:51 21 Mar '02  
    That's one nice looking demo.

    Great work, and thanks.

    Regards,
    Alvaro

    A priest, a minister and a rabbi walk into a bar. The bartender says, "What is this, a joke?"
    GeneralLooks great
    Giles
    6:19 2 Mar '02  
    Nice work.

    Thanks,


    Giles
    Generalin other window
    andrea
    1:22 2 Oct '00  
    can i insert the credit scrolling in my about windows?
    how???
    thank you
    GeneralTranslucent bitmap
    Qing Zhao
    10:11 18 Apr '00  
    Can you handle the translucent bitmap? Please let me know.

    Thanks,

    Qing
    GeneralRe: Translucent bitmap
    Portatofe
    7:02 2 Oct '08  
    Good Question


    GeneralPalette Handling
    Llew
    16:22 16 Apr '00  
    These are great classes. The only minor point is that they are not palette aware and thus the display looked pretty horrible when I tested it under 256 colours.

    A difficulty is that one has no control over what sort of bitmaps might be displayed. They might be true colour or use incompatible palettes. A complete solution would be to use the DrawDib functions. However, this involves quite a fair bit of new code... :->
    The easy compromise is to force palette aware users to share a halftone palette. This should involve relatively little exta code
    GeneralRe: Palette Handling
    Aaron Sulwer
    9:29 11 Jul '00  
    how would a person do that
    GeneralRe: Palette Handling
    Llew
    12:27 11 Jul '00  
    >>A complete solution would be to
    >>use the DrawDib
    >>functions. However, this involves quite a fair bit of new >>code... :->
    >>The easy compromise is to force palette aware users to
    >>share a halftone palette. This should involve relatively
    >>little exta code.

    >how would a person do that?
    I presume you mean how to force users to share a halftone palette. (The Drawdib stuff does halftoning and dithering automatically. For more info, do a search of www.codeguru.com)

    Well the easiest solution is to choose the "web safe palette" when creating /saving the artwork. There are 216 web safe colours common across different OS which is just the 216 permutations arrived at by dividing each rgb component into 6 discreet levels (0, 20, 40, 60, 80 and 100%). 6 * 6 * 6 = 216. Note that this does not partition the perceptual colour space evenly, since the eye is much less sensitive to blue than red or green and ignoring gamma. As a first appromximation, it is more than satisfactory.

    Alternately, one can obtain the standard windows halftone palette, write out the values to a text file, load that into photoshop or whatever graphics editor you are using..
    GeneralRe: Palette Handling
    Aaron Sulwer
    9:09 12 Jul '00  
    I have photoshop. Can I load each picture into photoshop and then resave them selecting the "web safe palette"? Is this what you are saying? If not then I really don't understand you. Could please be more specific? This may sound like a simple thing you are saying but I am fairly new at bitmaps and such.

    I can obtain the windows halftone palette and write out the values to a text file, load into photoshop and do what with it once its there?

    Thanks for being understanding and replying to my question so quickly
    GeneralRe: Palette Handling
    Llew
    9:43 12 Jul '00  
    If you are using photoshop, things are really easy. Start off with a full colour (24-bit) bitmap. Select
    Image | Mode | Indexed Colour ...
    Select in the Palette combo box "System (Windows)". Experiment with the dither and colour matching settings to produce the best results. Save your file...

    somewhere do

    m_halftonePalette.Attach(CreateHalftonePalette(dc.m_hDC));

    When displaying the bitmap in eg. wm_paint, bracket the drawing code with:
    CPalette* oldPalette = dc.SelectPalette(&m_halftonePalette, false);
    dc.RealizePalette();

    and

    dc.SelectPalette(oldPalette, true);
    GeneralMake it building under VC50
    George
    17:58 12 Apr '00  
    If you remove the line:
    #include // MFC support for Internet Explorer 4 Common Controls

    In your stdafx.h then it will build under VC50. Apprently it doesn't need it..


    Last Updated 15 Apr 2000 | Advertise | Privacy | Terms of Use | Copyright © CodeProject, 1999-2010