Click here to Skip to main content
13,829,956 members
Click here to Skip to main content
Add your own
alternative version


38 bookmarked
Posted 19 Feb 2002

Statusbar – It’s Just So Easy to Use in MFC

, 19 Feb 2002
Rate this:
Please Sign up or sign in to vote.
How to add your own text to the status bar control using MFC


I just had a look at the MSDN articles on CStatusBar, and to my surprise, I found it so easy to use.

First of all, a status bar contains several 'panes'. Each pane is a rectangular area of the status bar that you can use to display information. As you know, many applications display the status of the CAPS, NUM LOCK, and other keys in the rightmost panes. These panes, by default, have a 3-D border around them. The leftmost pane (pane 0), sometimes called the 'message pane', has the BPS_NOBORDERS style, and therefore doesn’t have any border surrounding it. This pane is usually used to display a string explaining the currently selected menu item or toolbar button. Furthermore, by default, the 'message pane' is 'elastic': it takes up the area of the status-bar not used by the other indicator panes, so that the other panes are always right-aligned.

To add a customized pane to display your own message on the status bar, it only takes the following 6 steps. For this example, we are going to display the current time at the rightmost location of the status bar. It will be updated every 60 seconds.

First of all, add a new entry to your string table with an ID of ID_INDICATOR_TIME and a caption of '%5s “. The extra spaces are to give you a little more room in the pane so the text will not be clipped.

Second, append ID_INDICATOR_TIME to the indicators[] array in the MainFrm.cpp file as the last entry (so that it will appear as the rightmost item on status bar).

Third, in the message map in mainfrm.h, add the following:

afx_msg void OnUpdateTimeIndicator(CcmdUI *pCmdUI);

Fourth, in MainFrm.cpp, add the macro call:


Fifth, in MainFrm.cpp, create the function body:

void CMainFrame::OnUpdateTimeIndicator(CCmdUI *pCmdUI)
    CString strStatus;

    strStatus.Format(ID_INDICATOR_TIME, time);

		strStatus );

Last of all, update the variable time every 60 seconds:


class CMainFrame : public CFrameWnd
	char time[7];

void CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
  SetTimer(TIME_STATUSBAR, 60000, NULL);
  Memset(time, ‘\0’, 7);

void CMainFrame::OnTimer(UINT nIDEvent) 
    // TODO: Add your message handler code here and/or call default
    if ( nIDEvent == TIME_STATUSBAR )
        char tempchar[20];
        _strtime(tempchar); // get current time
        strncpy(time, tempchar, 5); // extract only hour and minute info


The secret here is, whenever variable time changes, the display changes during the next idle loop. This is done automatically by MFC. Isn’t it nice?

If you wish, you can download the sample project, which does the same as described above.


This article has no explicit license attached to it, but may contain usage terms in the article text or the download files themselves. If in doubt, please contact the author via the discussion board below.

A list of licenses authors might use can be found here.


About the Author

Software Developer
Canada Canada
I love this place!

You may also be interested in...


Comments and Discussions

Questionhow to change pane text when mouse move over diffrent controls? Pin
hvibh29-Nov-02 18:32
memberhvibh29-Nov-02 18:32 
GeneralCannot get time working on MDI :( Pin
3-Apr-02 17:23
suss3-Apr-02 17:23 
GeneralRe: Cannot get time working on MDI :( Pin
3-Apr-02 17:46
suss3-Apr-02 17:46 
Generalone pane Pin
23-Feb-02 9:29
suss23-Feb-02 9:29 
GeneralRe: one pane Pin
24-Feb-02 0:40
suss24-Feb-02 0:40 
GeneralRe: one pane Pin
24-Feb-02 1:11
suss24-Feb-02 1:11 
GeneralRe: one pane Pin
lucy25-Feb-02 9:02
memberlucy25-Feb-02 9:02 
Generalno topic Pin
Mazdak20-Feb-02 20:58
memberMazdak20-Feb-02 20:58 
This article should be marked as "pre pre beginner" ,but it's useful because I've seen questions about this topic about HUNDRED times in the discussion board. Smile | :)

Another thing I want to say:
Lucy,why do you set timer for every 60 seconds?Does your watch show time for every one minute?;) I have to wait to see changes in demo project for every one minute Dead | X|


"So,so you think you can tell,
Heaven from Hell,
Blue skies from pain,...
How I wish,how I wish you were here."
Wish You Were Here-Pink Floyd-1975

GeneralRe: no topic Pin
Nish Nishant20-Feb-02 21:27
sitebuilderNish Nishant20-Feb-02 21:27 
GeneralRe: no topic Pin
Kannan Kalyanaraman21-Feb-02 3:27
memberKannan Kalyanaraman21-Feb-02 3:27 
GeneralRe: no topic Pin
lucy21-Feb-02 3:52
memberlucy21-Feb-02 3:52 
GeneralRe: no topic Pin
Mazdak21-Feb-02 4:22
memberMazdak21-Feb-02 4:22 
GeneralRe: no topic Pin
alex.barylski21-Feb-02 11:43
memberalex.barylski21-Feb-02 11:43 
GeneralYay, there is actually a female on this site !! Pin
20-Feb-02 20:01
suss20-Feb-02 20:01 
GeneralRe: Yay, there is actually a female on this site !! Pin
Christian Graus20-Feb-02 20:03
protectorChristian Graus20-Feb-02 20:03 
GeneralRe: Yay, there is actually a female on this site !! Pin
Nish Nishant20-Feb-02 20:14
sitebuilderNish Nishant20-Feb-02 20:14 
GeneralRe: Yay, there is actually a female on this site !! Pin
21-Feb-02 6:59
suss21-Feb-02 6:59 
GeneralRe: try message board Pin
lucy21-Feb-02 9:39
memberlucy21-Feb-02 9:39 
GeneralRe: Yay, there is actually a female on this site !! Pin
Mazdak21-Feb-02 10:00
memberMazdak21-Feb-02 10:00 
GeneralRe: Yay, there is actually a female on this site !! Pin
lucy21-Feb-02 11:40
memberlucy21-Feb-02 11:40 
GeneralRe: Yay, there is actually a female on this site !! Pin
Mazdak21-Feb-02 20:12
memberMazdak21-Feb-02 20:12 
GeneralRe: Yay, there is actually a female on this site !! Pin
Christian Graus25-Feb-02 9:45
protectorChristian Graus25-Feb-02 9:45 
GeneralRe: Yay, there is actually a female on this site !! Pin
Anonymous10-Oct-03 12:24
memberAnonymous10-Oct-03 12:24 
GeneralRe: Yay, there is actually a female on this site !! Pin
alex.barylski21-Feb-02 11:37
memberalex.barylski21-Feb-02 11:37 
GeneralRe: Yay, there is actually a female on this site !! Pin
25-Feb-02 9:31
suss25-Feb-02 9:31 

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.

Permalink | Advertise | Privacy | Cookies | Terms of Use | Mobile
Web05 | 2.8.190114.1 | Last Updated 20 Feb 2002
Article Copyright 2002 by lucy
Everything else Copyright © CodeProject, 1999-2019
Layout: fixed | fluid