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: April 22, 2014 @ 1:00 p.m. ET / 10:00 a.m. PT Database professionals — whether developers or DBAs — can often save valuable time by learning to get the most from their new or existing productivity tools. Whether you're responsible for managing database projects, performing database health checks and reporting, analyzing code, or measuring software engineering metrics, it's likely you're not taking advantage of some of the lesser-known features of Toad from Dell. Attend this live …

  • The impact of a data loss event can be significant. Real-time data is essential to remaining competitive. Many companies can no longer afford to rely on a truck arriving each day to take backup tapes offsite. For most companies, a cloud backup and recovery solution will eliminate, or significantly reduce, IT resources related to the mundane task of backup and allow your resources to be redeployed to more strategic projects. The cloud - can now be comfortable for you – with 100% recovery from anywhere all …

Most Popular Programming Stories

More for Developers

Latest Developer Headlines

RSS Feeds