Click here to Skip to main content
11,920,394 members (40,069 online)
Click here to Skip to main content
Add your own
alternative version


41 bookmarked

Hyperlink Scroller

, 21 Nov 2002
Rate this:
Please Sign up or sign in to vote.
An article on scrolling your hyperlinks, something like a news ticker

Sample Image


This article is about a subclassed static control which you can use to scroll hyperlinks from right to left. I once used it to scroll news headlines as hyperlinks in an application.

Using the code

The source for this subclassed control is in ScrollLink.h and ScrollLink.cpp. In it, you will find 2 classes, CScrollLink and CTextFrame. The latter is used by CScrollLink for each hyperlink to scroll, so you don't really need to know much about it to use this hyperlink scroller. To use it, you need to use a Static control and subclassed with CScrollLink. Note that you need to check the 'Notify' property of the static control.

The code listed below will show you how to 

  1. Change the scrolling text colors, fonts, scroll speed, rate, etc.
  2. Change the font attributes such as bold hyperlinks, underline them when hovered.
  3. Add hyperlink name and its url for scrolling.
  4. Remove all the hyperlinks that were added.
  5. Begin scrolling all the added hyperlinks.

1) Change the scrolling text colors, fonts, scroll speed, rate, etc.

#define CLR_RED RGB(255, 0, 0) // Red color
#define CLR_BLUE RGB(0, 0, 255) // Blue color
#define CLR_BLACK RGB(0, 0, 0) // Black color
#define CLR_GRAY RGB(178, 178, 178) // Gray color
#define CLR_WHITE RGB(255, 255, 255) // White color

#define SCROLLRATE 1 // Frequency of timer
#define SCROLLSPEED 1 // Amount of pixels to scroll
#define SCROLLALLOWANCE 50 // Amount of pixels between 2 scroll text
    // Empty array

    // Scroll rate is the value used in SetTimer(), which scrolls your hyperlinks to
    // the left by x pixels, where x is the scroll speed value. Scroll allowance is the
    // gap in pixels between 2 scrolling hyperlinks
    m_uiScrollRate = SCROLLRATE;
    m_uiScrollSpeed = SCROLLSPEED;
    m_uiScrollAllowance = SCROLLALLOWANCE;

    // The text of the hyperlink will be black if there is no url for it. If not, it will
    // be blue. The color of the hyperlink is set to red when mouse it is hovered and the
    // background color of the control is set to the same as the button color.
    m_clrText = CLR_BLACK;
    m_clrHover = CLR_RED;
    m_clrBackground = GetSysColor(COLOR_BTNFACE);

    // Set flag
    m_bOnHover = FALSE;

2) Change the font attributes such as bold hyperlinks, underline them when hovered.

This hyperlink scroller uses the same font as its parent. You can change its font attributes for the scrolling text as well as when it is hovered in CreateTextFonts as show below.

void CScrollLink::CreateTextFonts(void)
    // Get window font
    CFont* pFont = GetFont();
    // Create LOGFONT structure
    LOGFONT lfLogFont;

    // Get LOGFONT structure of current font

    // Set font to be bold
    lfLogFont.lfWeight = FW_BOLD;

    // Create normal font that is bold (when not hovered)
    // Set underline attribute
    lfLogFont.lfUnderline = TRUE;

    // Create current font with underline attribute (when hovered)

3) Add hyperlink name and its url for scrolling.

Now to add your hyperlink to the scroller, you should use AddScrollText as shown below. Note that you can pass an empty url string and the scrolled text will appear as a normal text instead of a hyperlink.

BOOL CScrollLink::AddScrollText(CString strText /* Text to scroll */, 
                                CString strURL /* URL behind scrolled text */)
    // Allocate memory for CTextFrame object
    CTextFrame* pTextFrame = new CTextFrame(strText, strURL);

    // Check if memory allocation successful
    if (pTextFrame != NULL)
        // Store object into array

        // Assign null pointer value
        pTextFrame = NULL;

        // Indicate success
        return TRUE;

    // Indicate failure
    return FALSE;

4) Remove all the hyperlinks that were added.

And to clear all the hyperlinks that you have added, call RemoveAllScrollText.

BOOL CScrollLink::RemoveAllScrollText(void)
    // Remove all scroll text

    // Repaint

    // Indicate success
    return TRUE;

5) Begin scrolling all the added hyperlinks.

After you have added your hyperlinks details, call StartScrolling to begin scrolling them.

/* bRestart = Flag to indicate whether to restart scrolling */
BOOL CScrollLink::StartScrolling(BOOL bRestart)
    // Make sure there are text to scroll
    if (m_oTextFrames.GetSize() > 0)
        // Stop timer if any

        // Check if scrolling is to be restarted
        if (bRestart == TRUE)
            // Empty array of indexes of current scrolling text frames

            // Store index of the first text frame to be scrolling

            // Initialize size of text and its starting position

            // Clear any previous scroll text

        // Scrolling is to be continued

        // Start timer

        // Indicate success
        return TRUE;

    // Indicate failure
    return FALSE;

Points of Interest

Well, I need to apologize if my code comments appear vague. I am still improving on that. Also, I know that some of my code could be further improved, so I will be open to your comments, suggestions and criticisms.


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


About the Author

Weiye Chen
Singapore Singapore
No Biography provided

You may also be interested in...

Comments and Discussions

GeneralMutiThread problems Pin
shirley_cl15-Jul-09 18:00
membershirley_cl15-Jul-09 18:00 
GeneralLittle question about using this control in ATL project Pin
mfranco_neto5-Oct-06 6:46
membermfranco_neto5-Oct-06 6:46 
Questiona little suggestion or improvement? Pin
ice_lei18-Sep-06 23:55
memberice_lei18-Sep-06 23:55 
QuestionHow to display not fliking Pin
pyoon17-Apr-06 4:31
memberpyoon17-Apr-06 4:31 
QuestionHow to change the SCROLLRATE and SCROLLSPEED Pin
chinakknd26-Mar-06 22:15
memberchinakknd26-Mar-06 22:15 
I change the SETTIMER(,x,)but when x=20 ,the speed is slow,x=15 or 10 ,the rate dosn't change.why?
how to change the scrollrate
AnswerRe: How to change the SCROLLRATE and SCROLLSPEED Pin
Weiye Chen27-Mar-06 2:57
memberWeiye Chen27-Mar-06 2:57 
QuestionCan I creat the control with 'creat' method Pin
chgrbr31-Oct-05 21:37
memberchgrbr31-Oct-05 21:37 
AnswerRe: Can I creat the control with 'creat' method Pin
Weiye Chen8-Nov-05 22:18
memberWeiye Chen8-Nov-05 22:18 
Generaltransparent text and halts Pin
sir kaber28-Jul-05 14:25
susssir kaber28-Jul-05 14:25 
Questionright to left scroll ? Pin
waelahmed5-Sep-04 17:44
memberwaelahmed5-Sep-04 17:44 
AnswerRe: right to left scroll ? Pin
Weiye Chen6-Sep-04 1:59
memberWeiye Chen6-Sep-04 1:59 
GeneralRe: right to left scroll ? Pin
waelahmed11-Sep-04 18:07
memberwaelahmed11-Sep-04 18:07 
GeneralRe: right to left scroll ? Pin
Weiye Chen11-Sep-04 18:55
memberWeiye Chen11-Sep-04 18:55 
GeneralRe: right to left scroll ? Pin
waelahmed11-Sep-04 18:57
memberwaelahmed11-Sep-04 18:57 
GeneralRe: Hi, I have two question! Pin
Weiye Chen23-Jun-04 22:05
memberWeiye Chen23-Jun-04 22:05 
GeneralRe: Image Background Pin
Weiye Chen15-Jun-04 21:03
memberWeiye Chen15-Jun-04 21:03 
GeneralTransparent background Pin
WolfSupernova8-Nov-03 5:55
memberWolfSupernova8-Nov-03 5:55 
GeneralRe: Transparent background Pin
WolfSupernova8-Nov-03 6:29
memberWolfSupernova8-Nov-03 6:29 
GeneralRe: Transparent background Pin
WeiyeChen9-Nov-03 5:22
memberWeiyeChen9-Nov-03 5:22 
GeneralBigger Font Pin
Rizi29-Sep-03 20:57
memberRizi29-Sep-03 20:57 
GeneralRe: Bigger Font Pin
WeiyeChen30-Sep-03 3:14
memberWeiyeChen30-Sep-03 3:14 
GeneralObject ID problem Pin
gigi boieru28-Jul-03 23:30
membergigi boieru28-Jul-03 23:30 
GeneralRe: Object ID problem Pin
Weiye Chen29-Jul-03 19:02
memberWeiye Chen29-Jul-03 19:02 
GeneralRe: Object ID problem Pin
gigi boieru31-Jul-03 5:38
membergigi boieru31-Jul-03 5:38 
GeneralUhm Pin
Tak23-Nov-02 11:25
memberTak23-Nov-02 11:25 

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.

| Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.151120.1 | Last Updated 22 Nov 2002
Article Copyright 2002 by Weiye Chen
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid