Show scrolling text in a status bar pane

This simple trick uses string pointer manipulation to give scrolling
effect in a status bar. The code is not robust. It only demonstrates
how it could be done.

1. Derive your own CMyStatusBar from CstatusBar.

2. In MainFrm.h, change the type of status bar as:

	CMyStatusBar m_wndStatusBar;

3. Also change the indicator array in MainFrm.cpp as:

	static UINT indicators[] =
		IDS_SCROLL_PANE,				//scrolling text

4. Add IDS_SCROLL_PANE in the string table with few blanks. The size
of pane will depend on this blank string. There are other painfull
ways of sizing a pane too.

5. Add following member to CMyStatusBar:

Cstring m_strScrollText;

6. Add OnTimer() to the CMyStatusBar:

void CMyStatusBar::OnTimer(UINT nIDEvent)
	// TODO: Add your message handler code here and/or call default

	if (m_strScrollText.IsEmpty())
		SetPaneText(CommandToIndex(IDS_SCROLL_PANE), "");
	static UINT str_idx = 0;        //offset into string

	//if end of string, return to top
	if (str_idx >= (UINT) (m_strScrollText.GetLength() / 2) - 1)
		str_idx = 0;

	//display string
	SetPaneText(CommandToIndex(IDS_SCROLL_PANE), ((LPCSTR)

	//scroll one character
	str_idx = str_idx + 1;


7. Destroy timer:

void CMyStatusBar::OnDestroy()

	// TODO: Add your message handler code here


8. Add a method to start scrolling text. This method must be called
after the mainframe (and the status bar) has been constructed to
display scrolling text. Perhaps from the CWinApp::InitInstance().

void CMyStatusBar::StartDisplay(void)
	//set text for scrolling
	m_strScrollText = "   Hello! World.   "

		//to make it circular scroll
		m_strScrollText += m_strScrollText;

	VERIFY(SetTimer(1, 200, NULL) != 0);    //timer

More by Author

Must Read