Click here to Skip to main content
Click here to Skip to main content

Adding a status bar to an MFC dialog

, 16 May 2002 CPOL
Rate this:
Please Sign up or sign in to vote.
Shows how you can have status bars in your dialog based apps


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.

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.

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 is a real nice guy who has been writing code since 1990 when he first got his hands on an 8088 with 640 KB RAM. Originally from sunny Trivandrum in India, he has been living in various places over the past few years and often thinks it’s time he settled down somewhere.
Nish has been a Microsoft Visual C++ MVP since October, 2002 - awfully nice of Microsoft, he thinks. He maintains an MVP tips and tricks web site - where you can find a consolidated list of his articles, writings and ideas on VC++, MFC, .NET and C++/CLI. Oh, and you might want to check out his blog on C++/CLI, MFC, .NET and a lot of other stuff -
Nish loves reading Science Fiction, P G Wodehouse and Agatha Christie, and also fancies himself to be a decent writer of sorts. He has authored a romantic comedy Summer Love and Some more Cricket as well as a programming book – Extending MFC applications with the .NET Framework.
Nish's latest book C++/CLI in Action published by Manning Publications is now available for purchase. You can read more about the book on his blog.
Despite his wife's attempts to get him into cooking, his best effort so far has been a badly done omelette. Some day, he hopes to be a good cook, and to cook a tasty dinner for his wife.

Comments and Discussions

QuestionButtons OverLapping with status bar Pinprofessionalp.uday kishore18-Nov-13 19:38 
Questionhow to change font color? Pinmemberluiggivillar9-Jan-12 5:27 
QuestionProblem with SetCapture() PinmemberPlamen Petrov29-Dec-11 22:27 
GeneralMy vote of 5 PinmemberA.Health6-Oct-11 4:06 
GeneralMy vote of 3 PinmemberSharanyaMahi4-Oct-11 21:27 
Thank u Very much..
Questionhow to revert the Background color? Pinmembersally89983-Aug-11 22:54 
GeneralMy vote of 5 PinmemberBhupendra S. Brahme30-Nov-10 2:44 
GeneralMy vote of 5 Pinmemberwbanko21-Oct-10 11:45 
GeneralMy vote of 5 PinmemberJongchanAhn7-Jul-10 17:49 
GeneralThat's great and easy to do it PinmemberJongchanAhn7-Jul-10 17:49 
GeneralThanks Pinmemberfuturejo19-Jan-10 7:38 
GeneralMy vote of 2 Pinmemberj1s2chen116-Dec-09 21:16 
GeneralThanks a lot Pinmemberhnkulkarni31-May-09 23:58 
GeneralThanks Pinmembernobihai26-Oct-08 6:21 
GeneralColoring only one pane PinmemberCerpinTaxt20-Oct-08 0:46 
GeneralNice Article!! Pinmemberloverjersey28-Aug-08 3:24 
QuestionMFC help needed Pinmemberabc_nus_student23-Nov-07 0:22 
QuestionAdjusting size of client area of dialog box. PinmemberTushar Jadhav13-Jun-07 0:31 
AnswerRe: Adjusting size of client area of dialog box. Pinmemberjeromelan10-Jun-08 4:48 
Generali m the trainee,thanks for such a grt info PinmemberMember #38960347-Mar-07 19:38 
GeneralThanks for very clear explanations PinmemberRaymond_Gimilio20-Feb-07 4:36 
GeneralSizing Grip PinmemberBlueKat15-Dec-05 13:07 
GeneralRe: Sizing Grip PinmemberSeanNick17-Aug-06 19:20 
QuestionRe: Sizing Grip Pinmemberxu_qing11-Mar-07 5:22 
AnswerRe: Sizing Grip PinmemberSeanNick12-Mar-07 21:26 
GeneralRe: Sizing Grip Pinmemberxu_qing13-Mar-07 2:22 
Generalthank you for easy solution Pinmemberl00p1n612-Jul-05 7:58 
GeneralWorks also great for CPropertySheet ! PinsussAxel Magard29-Apr-05 1:58 
GeneralXP problem PinmemberYavathol1-Apr-05 0:38 
QuestionHow can i set the button position using Cordinates Pinmemberkumararaja19-Jul-04 23:00 
GeneralDialog Design Pinmembersrinivasa murthy19-May-04 3:27 
Generalvc++ how can i insert pic in dialog box Pinmemberneo_matrix10021-Feb-04 21:10 
GeneralRe: vc++ how can i insert pic in dialog box Pinmembervikas amin26-Aug-05 0:54 
Generaldisplaying menu item prompts Pinmembertoxcct3-Dec-03 2:22 
GeneralGreat Article! PinsussVetro XL15-Oct-03 17:23 
GeneralRe: Great Article! Pinmemberkapildevg9-May-06 4:20 
QuestionUrgent Help: How do i add a colour (Back Ground) to a status bar? Pinsusskishore Gaddam11-Jul-03 5:04 
AnswerRe: Urgent Help: How do i add a colour (Back Ground) to a status bar? Pinmemberkishore Babu25-Mar-04 20:49 
General Pinsuss. (DBCS) Read Key20-Jul-05 2:11 
GeneralChange color of individual Panes Pinmembermistroseth7-Apr-03 2:54 
GeneralRe: Change color of individual Panes PinmemberSledgeHammer7-Apr-03 3:16 
GeneralRe: Change color of individual Panes Pinmembermistroseth7-Apr-03 3:41 
GeneralRe: Change color of individual Panes PinmemberSledgeHammer7-Apr-03 8:44 
GeneralRe: Change color of individual Panes Pinmembermistroseth8-Apr-03 2:48 
GeneralRe: Change color of individual Panes PinmemberSledgeHammer8-Apr-03 9:02 
GeneralRe: Change color of individual Panes Pinmembermistroseth8-Apr-03 9:24 
GeneralRe: Change color of individual Panes PinmemberNYTSX2-May-06 11:23 
GeneralRe: Change color of individual Panes Pinmembernorm.net2-May-06 21:38 
Questionhow to change text when mouse move over diffrent controls? Pinsussvibhavari26-Nov-02 2:17 
QuestionHow to refresh the status bar on the dialog when it is expanded or contracted? Pinmembertony.wu10-Sep-02 18:33 

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

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

| Advertise | Privacy | Terms of Use | Mobile
Web04 | 2.8.150327.1 | Last Updated 17 May 2002
Article Copyright 2002 by Nish Nishant
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid