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

  • Live Event Date: December 11, 2014 @ 1:00 p.m. ET / 10:00 a.m. PT Market pressures to move more quickly and develop innovative applications are forcing organizations to rethink how they develop and release applications. The combination of public clouds and physical back-end infrastructures are a means to get applications out faster. However, these hybrid solutions complicate DevOps adoption, with application delivery pipelines that span across complex hybrid cloud and non-cloud environments. Check out this …

  • CentreCorp is a fully integrated and diversified property management and real estate service company, specializing in the "shopping center" segment, and is one of the premier retail service providers in North America. Company executives travel a great deal, carrying a number of traveling laptops with critical current business data, and no easy way to back up to the network outside the office. Read this case study to learn how CentreCorp implemented a suite of business continuity services that included …

Most Popular Programming Stories

More for Developers

RSS Feeds