Write to status bar using sprintf syntax


#include < stdarg.h >

// StatusBarMessage() - Writes to status bar using sprintf syntax.
//
// Author: Keith Rule -- keithr@europa.com
//
// Copyright (c) 1995-1996, Keith Rule
// May be freely used provided this comment
// is included with the source and all derived
// versions of this source.
void StatusBarMessage(char* fmt, ...)
{
	if (AfxGetApp() != NULL && AfxGetApp()->m_pMainWnd != NULL) {
		char buffer[256];
		CStatusBar* pStatus = (CStatusBar*) 
			AfxGetApp()->m_pMainWnd->GetDescendantWindow(AFX_IDW_STATUS_BAR);
		va_list argptr;
		va_start(argptr, fmt);
		vsprintf(buffer, fmt, argptr);
		va_end(argptr);
		if (pStatus != NULL) {
			pStatus->SetPaneText(0, buffer);
			pStatus->UpdateWindow();
		}
	}
}



Comments

  • HomePage

    Posted by Legacy on 03/02/2002 12:00am

    Originally posted by: amit

    See My Statusbar

    Reply
  • Im New How Do I Use that code?

    Posted by Legacy on 08/31/2001 12:00am

    Originally posted by: RYan Zimmerman

    How Would I call that code up? Im very new. I have programmed in C++ long long time ago though.

    Reply
  • Update Version II

    Posted by Legacy on 06/26/2001 12:00am

    Originally posted by: V�ctor Carre�o

    Use this code
    
    

    void StatusBarMessage ( int nPanel, LPCTSTR pszFmt, ... )
    {
    TCHAR pszBuffer[1001];
    va_list argptr;

    va_start( argptr, pszFmt );

    int cch = _vsntprintf( pszBuffer,
    sizeof( pszBuffer )/sizeof( TCHAR ),
    pszFmt,
    argptr );
    va_end(argptr);

    if ( cch == -1 )
    {
    return;
    }

    if (AfxGetApp() != NULL && AfxGetApp()->m_pMainWnd != NULL)
    {
    CStatusBar* pStatus = (CStatusBar*)AfxGetApp()->m_pMainWnd->GetDescendantWindow(AFX_IDW_STATUS_BAR);

    if (pStatus != NULL)
    {
    pStatus->SetPaneText ( nPanel, pszBuffer );
    pStatus->UpdateWindow();
    }
    }
    }

    Reply
  • updated version

    Posted by Legacy on 04/15/2000 12:00am

    Originally posted by: Jeff Miller


    Here's what worked for me.

    void CMainFrame::StatusBarMessage(
    LPCTSTR pszFmt,
    ...
    )
    {
    TCHAR pszBuffer[256];

    va_list argptr;
    va_start( argptr, pszFmt );

    int cch = _vsntprintf( pszBuffer,
    sizeof( pszBuffer )/sizeof( TCHAR ),
    pszFmt,
    argptr );

    va_end(argptr);

    if ( cch == -1 )
    {
    return;
    }

    m_wndStatusBar.SetPaneText( 0, pszBuffer );
    m_wndStatusBar.UpdateWindow();
    }

    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.

Top White Papers and Webcasts

  • Protecting business operations means shifting the priorities around availability from disaster recovery to business continuity. Enterprises are shifting their focus from recovery from a disaster to preventing the disaster in the first place. With this change in mindset, disaster recovery is no longer the first line of defense; the organizations with a smarter business continuity practice are less impacted when disasters strike. This SmartSelect will provide insight to help guide your enterprise toward better …

  • QA teams don't have time to test everything yet they can't afford to ship buggy code. Learn how Coverity can help organizations shrink their testing cycles and reduce regression risk by focusing their manual and automated testing based on the impact of change.

Most Popular Programming Stories

More for Developers

Latest Developer Headlines

RSS Feeds