Praveen Katiyar' Blog

Learning along the way . . . .

Creating a status Bar in a Dialog Box ( VC++, MFC)

Normally in MFC Applications one can not create a status bar by default, this article shows you how status bar can be created in a dialog box.

Create a Dialog based application, using MFC AppWizard,

compile and make sure that every thing is working fine.

Open “resource.h”

define two identifiers in the file ”resource.h”, for two panes, these identifier will be used to identify two panes in the status bar you are going to create.

#define ID_INDICATOR_PANE             106
#define ID_INDICATOR_TIME             107

define an array of indicators in  DialogBox Source file, let say if you need to create two panes, you need  to define two values as shown below.

static UINT BASED_CODE indicators[] =

Now make the necessary modifications in the Dialog Box’s InitDialog function.

BOOL CMyStatusBarDialogDlg::OnInitDialog()
//    rudimentary stuff

// Set the icon for this dialog. 
    SetIcon(m_hIcon, TRUE);        // Set big icon
    SetIcon(m_hIcon, FALSE);       // Set small icon

// Here is what you need, to create a status bar
m_StatusBar.Create(this);     //Create status bar

//    Find the Size of Dialog box

CRect rect;                                       

//    Size the two panes
m_StatusBar.SetPaneInfo(0,ID_INDICATOR_PANE, SBPS_NORMAL, rect.Width()-100);     
m_StatusBar.SetPaneInfo(1,ID_INDICATOR_TIME, SBPS_STRETCH ,0);

//    This is where we actually draw it RepositionBars( AFX_IDW_CONTROLBAR_FIRST, AFX_IDW_CONTROLBAR_LAST, ID_INDICATOR_TIME ) ;

    // Timer is Set to Update the Time on the status Bar.   

    return TRUE;  // return TRUE  unless . . . .

Implement the Message WM_TIMER to update time

Implement the WM_TIMER message handler to update the current time on the pane of the status bar.

void CStatusBarDialogDlg::OnTimer(UINT nIDEvent)
    // TODO: Add your message handler code here 

    if ( nIDEvent==STATUS_TIMEER )
        CTime t1 ;
        t1 = CTime::GetCurrentTime();

build and execute, and voila you are done.

June 29, 2013 Posted by | CodeProject, GUI, MFC | , , | Leave a comment