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,
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
- Change the scrolling text colors, fonts, scroll speed, rate, etc.
- Change the font attributes such as bold hyperlinks, underline them when
- Add hyperlink name and its url for scrolling.
- Remove all the hyperlinks that were added.
- 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) #define CLR_BLACK RGB(0, 0, 0) // Black color
define CLR_GRAY RGB(178, 178, 178) #define CLR_WHITE RGB(255, 255, 255) // White color
#define SCROLLRATE 1 // Frequency of timer
define SCROLLSPEED 1 #define SCROLLALLOWANCE 50 // Amount of pixels between 2 scroll text
m_uiScrollRate = SCROLLRATE;
m_uiScrollSpeed = SCROLLSPEED;
m_uiScrollAllowance = SCROLLALLOWANCE;
m_clrText = CLR_BLACK;
m_clrHover = CLR_RED;
m_clrBackground = GetSysColor(COLOR_BTNFACE);
m_bOnHover = FALSE;
2) Change the font attributes such as bold hyperlinks, underline them when
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.
CFont* pFont = GetFont();
lfLogFont.lfWeight = FW_BOLD;
lfLogFont.lfUnderline = TRUE;
3) Add hyperlink name and its url for scrolling.
Now to add your hyperlink to the scroller, you should use
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 ,
CString strURL )
CTextFrame* pTextFrame = new CTextFrame(strText, strURL);
if (pTextFrame != NULL)
pTextFrame = NULL;
4) Remove all the hyperlinks that were added.
And to clear all the hyperlinks that you have added, call
5) Begin scrolling all the added hyperlinks.
After you have added your hyperlinks details, call
StartScrolling to begin
BOOL CScrollLink::StartScrolling(BOOL bRestart)
if (m_oTextFrames.GetSize() > 0)
if (bRestart == TRUE)
SetTimer(ID_SCROLLTIMER, SCROLLRATE, NULL);
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.