Clock in the statusbar??

Posted on 1998-01-26
Last Modified: 2010-05-18
I have used the following codes to make a clock in my status bar...

StatusBar1->Panels->Items[2]->Text = Time().FormatStriing("h.nn ampm    ");

But it stays the same time and never updates (as the time passes).  How do I get it to update the clock every minute or every 60 seconds (I know that you guys/gals know 1 minute is 60 seconds, but I said it anyway.)

Question by:stevenc317
LVL 10

Expert Comment

ID: 1179091
Here is how to add the current time to your status bar... [ Alternatively, look for article Q99198 "HOWTO: Display the Current Time in a CStatusBar Pane" on MS KB

Step 1:
Derive a CMyStatusBar class from CStatusBar as follows:

class CMyStatusBar : public CStatusBar {
     CString m_strClockFormat;
     void SetClockFormat(LPCTSTR strClockFormat);
     // Overrides
     // ClassWizard generated virtual function overrides
     // Generated message map functions
     afx_msg void OnDestroy();
     afx_msg void OnUpdateIndicatorTime(CCmdUI* pCmdUI);
     afx_msg int OnCreate( LPCREATESTRUCT lpCreateStruct );

#include "stdafx.h"
#include "MyStatusBar.h"
#include "Resource.h"

#ifdef _DEBUG
#undef THIS_FILE
static char BASED_CODE THIS_FILE[] = __FILE__;



: CStatusBar()
, m_strClockFormat("%H:%M:%S")

CMyStatusBar::~CMyStatusBar() {

void CMyStatusBar::SetClockFormat(LPCTSTR strClockFormat) {
     m_strClockFormat = strClockFormat;

int CMyStatusBar::OnCreate(LPCREATESTRUCT lpCreateStruct) {
     // make sure time gets updated every second, even when idle
     return 0;

void CMyStatusBar::OnUpdateIndicatorTime(CCmdUI* pCmdUI) {

void CMyStatusBar::OnDestroy() {

Step 2:
Create a new indicator pane by first adding a new menu called "ID_INDICATOR", add a single dropdown called "Indicator", add a single item to the menu called "Time" - This should create a menu item with id ID_INDICATOR_TIME. Give it a prompt string of, say, "HH:MM:SS" which reserves an approriate amount of space for the pane. NOTE: If you change time format by calling SetClockFormat you will need to ensure that your ID_INDICATOR_TIME pane is big enough.
Step 3:
Add a new indicator pane called ID_INDICATOR_TIME to your list of indicator in your mainframe eg. this is my indicator list...

static const UINT indicators[] = {
     ID_SEPARATOR,           // status line indicator
     ID_INDICATOR_TIME,  // <-- new indicator pane

Step 4:
Replace all existing uses of CStatusBar in your app with CMyStatusBar - in particular, the member variable in your mainframe m_wndStatusBar;


Author Comment

ID: 1179092
can i please get something more simple??
LVL 32

Accepted Solution

jhance earned 10 total points
ID: 1179093
Set a time to go off every second (or however long you want the update interval to be) and then run your:

StatusBar1->Panels->Items[2]->Text = Time().FormatStriing("h.nn ampm ");

command.  I think you should take some time to study RONSLOW's answer above as it is simple and does what you are asking for.
Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!


Author Comment

ID: 1179094
thanks, i got it!

Expert Comment

ID: 1179095
Thanks, I needed that.......................
LVL 10

Expert Comment

ID: 1179096
Thanks for no points on the answer there .. sometimes I wonder why I bother...

Guess I'm just a sadist :-)


Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Introduction This article is a continuation of the C/C++ Visual Studio Express debugger series. Part 1 provided a quick start guide in using the debugger. Part 2 focused on additional topics in breakpoints. As your assignments become a little more …
Container Orchestration platforms empower organizations to scale their apps at an exceptional rate. This is the reason numerous innovation-driven companies are moving apps to an appropriated datacenter wide platform that empowers them to scale at a …
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

706 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now