Show scrolling text in a status bar pane | CodeGuru

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 […]

Written By
CodeGuru Staff
CodeGuru Staff
Aug 6, 1998
1 minute read
CodeGuru content and product recommendations are editorially independent. We may make money when you click on links to our partners. Learn More

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[] =
	{
		ID_SEPARATOR,
		IDS_SCROLL_PANE,				//scrolling text
		ID_INDICATOR_CAPS,
		ID_INDICATOR_NUM,
		ID_INDICATOR_SCRL,
	};

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())
	{
		KillTimer(1);
		SetPaneText(CommandToIndex(IDS_SCROLL_PANE), "");
		return;
	}
	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)
		m_strScrollText)+str_idx);

	//scroll one character
	str_idx = str_idx + 1;

	CStatusBar::OnTimer(nIDEvent);
}

7. Destroy timer:

void CMyStatusBar::OnDestroy()
{
	CStatusBar::OnDestroy();

	// TODO: Add your message handler code here

	KillTimer(1);
}

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;

	KillTimer(1);
	VERIFY(SetTimer(1, 200, NULL) != 0);    //timer
}
CodeGuru Logo

CodeGuru covers topics related to Microsoft-related software development, mobile development, database management, and web application programming. In addition to tutorials and how-tos that teach programmers how to code in Microsoft-related languages and frameworks like C# and .Net, we also publish articles on software development tools, the latest in developer news, and advice for project managers. Cloud services such as Microsoft Azure and database options including SQL Server and MSSQL are also frequently covered.

Property of TechnologyAdvice. © 2026 TechnologyAdvice. All Rights Reserved

Advertiser Disclosure: Some of the products that appear on this site are from companies from which TechnologyAdvice receives compensation. This compensation may impact how and where products appear on this site including, for example, the order in which they appear. TechnologyAdvice does not include all companies or all types of products available in the marketplace.