dcsimg

Show scrolling text in a status bar pane

WEBINAR:
On-Demand

Building the Right Environment to Support AI, Machine Learning and Deep Learning


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
}



Comments

  • desktop

    Posted by Legacy on 08/05/1999 12:00am

    Originally posted by: atif

    do u know how to display on desktop client area not in application client area

    • Take a look!

      Posted by owuag on 12/03/2008 09:03pm

      Check

      Reply
    Reply
  • You must have javascript enabled in order to post comments.

Leave a Comment
  • Your email address will not be published. All fields are required.

Most Popular Programming Stories

More for Developers

RSS Feeds

Thanks for your registration, follow us on our social networks to keep up-to-date