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! Pin
    wwstudio_cn
    23:03 7 Dec '08  
    GeneralBuild under VC9 (Orcas) Pin
    rgallahan
    2:48 4 Dec '07  
    General谢谢 Pin
    rensheng3
    6:24 24 Sep '07  
    GeneralGreat work! Pin
    MaIron-cool
    21:42 13 Mar '07  
    GeneralSmall prob. Pin
    sumit siddheshwar
    20:01 8 Aug '06  
    GeneralThanks, it is a good basis !!! Pin
    2pers
    9:46 7 Mar '06  
    GeneralThanks! Pin
    WolfSupernova
    7:17 8 Nov '03  
    GeneralModeless dialog? Pin
    Ogi
    4:38 5 Sep '03  
    GeneralRe: Modeless dialog? Pin
    Ogi
    7:57 8 Sep '03  
    GeneralGreat work - its is free?? Pin
    asfur
    7:23 1 Jul '03  
    GeneralRe: Great work - its is free?? Pin
    Jim Connor
    16:43 1 Jul '03  
    GeneralNice work! Pin
    Alvaro Mendez
    4:51 21 Mar '02  
    GeneralLooks great Pin
    Giles
    6:19 2 Mar '02  
    Generalin other window Pin
    andrea
    1:22 2 Oct '00  
    GeneralTranslucent bitmap Pin
    Qing Zhao
    10:11 18 Apr '00  
    GeneralRe: Translucent bitmap Pin
    Portatofe
    7:02 2 Oct '08  
    GeneralPalette Handling Pin
    Llew
    16:22 16 Apr '00  
    GeneralRe: Palette Handling Pin
    Aaron Sulwer
    9:29 11 Jul '00  
    GeneralRe: Palette Handling Pin
    Llew
    12:27 11 Jul '00  
    GeneralRe: Palette Handling Pin
    Aaron Sulwer
    9:09 12 Jul '00  
    GeneralRe: Palette Handling Pin
    Llew
    9:43 12 Jul '00  
    GeneralMake it building under VC50 Pin
    George
    17:58 12 Apr '00  


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