Click here to Skip to main content
14,544,540 members

Adding a status bar to an MFC dialog

Rate this:
4.96 (87 votes)
Please Sign up or sign in to vote.
4.96 (87 votes)
16 May 2002CPOL
Shows how you can have status bars in your dialog based apps
Image 1


Someone asked in the VC++ forum how they can add a status bar to a dialog and I foolishly replied saying that all they had to do was to have a CStatusBar member in their dialog class and that they should call Create() from the OnInitDialog() handler. Then someone else replied saying that it didn't work and then I tried it out myself and to my horror found that nothing happened. Anyhow I just realized, it's not too complicated a task. I thought I'd write a small article on adding a status bar to a dialog. There is an MSDN sample that does this too, but they derive a class from CStatusBar and do some complicated stuff which is not required for the usual simple things we do with status bars.

Eight simple steps

Step 1

I assume that you have a dialog based MFC application ready for use. Take Resource Symbols from the View menu and add two new symbols, ID_INDICATOR_NISH and ID_INDICATOR_TIME. You can use the default values that VS 6 suggests, but sometimes it might suggest an already used value, in which case you might have to manually change it. I had to anyway. I wonder if this is a known bug.

Image 2

Step 2

Open your String Table and add the two entries there as well - ID_INDICATOR_NISH and ID_INDICATOR_TIME. And set some default values, whatever you want to use. It doesn't really matter.

Image 3

Step 3

Add a CStatusBar member to your main dialog class.

CStatusBar m_bar;

Step 4

Open the corresponding cpp file and add the following on top of the file :-

static UINT BASED_CODE indicators[] =

Step 5

Now we have to create our status bar. A nice place to do this would be in the OnInitDialog function of our CDialog derived class.

m_bar.Create(this); //We create the status bar

m_bar.SetIndicators(indicators,2); //Set the number of panes 

CRect rect;
//Size the two panes

//This is where we actually draw it on the screen

Step 6 - background color

By the end of Step 5, we actually have a status bar on screen. The two panes show the default values we set in our string table. But now say, you want to change the background color. This is wholly optional of course. You can add this line to the OnInitDialog(...)


Note that we had to get the underlying status bar control to call the SetBkColor function.

Step 7 - adding the clock

Say, you want the right pane to show the current time. First set a timer. Just add this line to the OnInitDialog(...)


Now add the following code to the WM_TIMER handler

void CDlgStatusBarDlg::OnTimer(UINT nIDEvent) 
        CTime t1;

Step 8 - showing X and Y co-ordinates

Say, you want to show the X,Y co-ordinates of the mouse as it moves along your dialog. What you need to do is to override OnMouseMove.

void CDlgStatusBarDlg::OnMouseMove(UINT nFlags, CPoint point) 
    CString s;
    s.Format("X=%d Y=%d",point.x,point.y);
    CDialog::OnMouseMove(nFlags, point);


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Nish Nishant
United States United States
Nish Nishant is a Principal Software Architect based out of Columbus, Ohio. He has over 17 years of software industry experience in various roles including Lead Software Architect, Principal Software Engineer, and Product Manager. Nish was a Microsoft Visual C++ MVP between 2002 and 2015.

Nish is an industry acknowledged expert in the Microsoft technology stack. He authored C++/CLI in Action for Manning Publications in 2005, and had previously co-authored Extending MFC Applications with the .NET Framework for Addison Wesley in 2003. In addition, he has over 140 published technology articles on and another 250+ blog articles on his WordPress blog. Nish is vastly experienced in team management, mentoring teams, and directing all stages of software development.

Contact Nish : If you are interested in hiring Nish as a consultant, you can reach him via his google email id voidnish.

Company Website :

Comments and Discussions

GeneralThank You! It worked! Pin
Hai Thai22-Sep-18 4:33
MemberHai Thai22-Sep-18 4:33 
QuestionSome fix in Visual Studio 2015 Pin
Member 1295110515-Jan-17 23:31
MemberMember 1295110515-Jan-17 23:31 
QuestionButtons OverLapping with status bar Pin
P Uday kishore18-Nov-13 18:38
professionalP Uday kishore18-Nov-13 18:38 
Questionhow to change font color? Pin
luiggivillar9-Jan-12 4:27
Memberluiggivillar9-Jan-12 4:27 
QuestionProblem with SetCapture() Pin
Plamen Petrov29-Dec-11 21:27
professionalPlamen Petrov29-Dec-11 21:27 
GeneralMy vote of 5 Pin
A.Health6-Oct-11 3:06
MemberA.Health6-Oct-11 3:06 
GeneralMy vote of 3 Pin
SharanyaMahi4-Oct-11 20:27
MemberSharanyaMahi4-Oct-11 20:27 
Questionhow to revert the Background color? Pin
sally89983-Aug-11 21:54
Membersally89983-Aug-11 21:54 
GeneralMy vote of 5 Pin
Bhupendra S. Brahme30-Nov-10 1:44
MemberBhupendra S. Brahme30-Nov-10 1:44 
GeneralMy vote of 5 Pin
wbankovitch21-Oct-10 10:45
Memberwbankovitch21-Oct-10 10:45 
GeneralMy vote of 5 Pin
JongchanAhn7-Jul-10 16:49
MemberJongchanAhn7-Jul-10 16:49 
GeneralThat's great and easy to do it Pin
JongchanAhn7-Jul-10 16:49
MemberJongchanAhn7-Jul-10 16:49 
GeneralThanks Pin
futurejo19-Jan-10 6:38
Memberfuturejo19-Jan-10 6:38 
GeneralMy vote of 2 Pin
j1s2chen116-Dec-09 20:16
Memberj1s2chen116-Dec-09 20:16 
GeneralThanks a lot Pin
hnkulkarni31-May-09 22:58
Memberhnkulkarni31-May-09 22:58 
GeneralThanks Pin
nobihai26-Oct-08 5:21
Membernobihai26-Oct-08 5:21 
GeneralColoring only one pane Pin
CerpinTaxt19-Oct-08 23:46
MemberCerpinTaxt19-Oct-08 23:46 
GeneralNice Article!! Pin
loverjersey28-Aug-08 2:24
Memberloverjersey28-Aug-08 2:24 
QuestionMFC help needed Pin
abc_nus_student22-Nov-07 23:22
Memberabc_nus_student22-Nov-07 23:22 
QuestionAdjusting size of client area of dialog box. Pin
Tushar Jadhav12-Jun-07 23:31
MemberTushar Jadhav12-Jun-07 23:31 
AnswerRe: Adjusting size of client area of dialog box. Pin
jeromelan10-Jun-08 3:48
Memberjeromelan10-Jun-08 3:48 
Generali m the trainee,thanks for such a grt info Pin
Priti Jain7-Mar-07 18:38
MemberPriti Jain7-Mar-07 18:38 
GeneralThanks for very clear explanations Pin
Raymond_Gimilio20-Feb-07 3:36
MemberRaymond_Gimilio20-Feb-07 3:36 
GeneralSizing Grip Pin
BlueKat15-Dec-05 12:07
MemberBlueKat15-Dec-05 12:07 
GeneralRe: Sizing Grip Pin
SeanNick17-Aug-06 18:20
MemberSeanNick17-Aug-06 18:20 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Posted 16 May 2002


126 bookmarked