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: November 20, 2014 @ 2:00 p.m. ET / 11:00 a.m. PT Are you wanting to target two or more platforms such as iOS, Android, and/or Windows? You are not alone. 90% of enterprises today are targeting two or more platforms. Attend this eSeminar to discover how mobile app developers can rely on one IDE to create applications across platforms and approaches (web, native, and/or hybrid), saving time, money, and effort and introducing apps to market faster. You'll learn the trade-offs for gaining long …

  • Live Event Date: October 29, 2014 @ 11:00 a.m. ET / 8:00 a.m. PT Are you interested in building a cognitive application using the power of IBM Watson? Need a platform that provides speed and ease for rapidly deploying this application? Join Chris Madison, Watson Solution Architect, as he walks through the process of building a Watson powered application on IBM Bluemix. Chris will talk about the new Watson Services just released on IBM bluemix, but more importantly he will do a step by step cognitive …

Most Popular Programming Stories

More for Developers

Latest Developer Headlines

RSS Feeds