?
Solved

Clock in the statusbar??

Posted on 1998-01-26
6
Medium Priority
?
240 Views
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.)

thanks
0
Comment
Question by:stevenc317
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
6 Comments
 
LVL 10

Expert Comment

by:RONSLOW
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:

//MyStatusBar.h:
//==============
class CMyStatusBar : public CStatusBar {
     DECLARE_DYNCREATE(CMyStatusBar)
public:
     CMyStatusBar();
     ~CMyStatusBar();
private:
     CString m_strClockFormat;
public:
     void SetClockFormat(LPCTSTR strClockFormat);
     // Overrides
     // ClassWizard generated virtual function overrides
     //{{AFX_VIRTUAL(CMyStatusBar)
     //}}AFX_VIRTUAL
     // Generated message map functions
     //{{AFX_MSG(CMyStatusBar)
     afx_msg void OnDestroy();
     afx_msg void OnUpdateIndicatorTime(CCmdUI* pCmdUI);
     afx_msg int OnCreate( LPCREATESTRUCT lpCreateStruct );
     //}}AFX_MSG
     DECLARE_MESSAGE_MAP()
};


/////////////////////////////////////////////////////////////////
//MyStatusBar.cpp:
//==============
#include "stdafx.h"
#include "MyStatusBar.h"
#include "Resource.h"

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

IMPLEMENT_DYNCREATE(CMyStatusBar, CStatusBar)

BEGIN_MESSAGE_MAP(CMyStatusBar, CStatusBar)
ON_WM_CREATE()
ON_WM_DESTROY()
ON_UPDATE_COMMAND_UI(ID_INDICATOR_TIME, OnUpdateIndicatorTime)
END_MESSAGE_MAP()

CMyStatusBar::CMyStatusBar()
: 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
     CStatusBar::OnCreate(lpCreateStruct);
     SetTimer(ID_INDICATOR_TIME,1000,NULL);
     return 0;
}

void CMyStatusBar::OnUpdateIndicatorTime(CCmdUI* pCmdUI) {
     pCmdUI->Enable(true);
     pCmdUI->SetText(CTime::GetCurrentTime().Format(m_strClockFormat));
}

void CMyStatusBar::OnDestroy() {
     KillTimer(ID_INDICATOR_TIME);
     ProgressDestroy();
     CStatusBar::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_CAPS,
     ID_INDICATOR_NUM,
     ID_INDICATOR_SCRL,
     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;

0
 
LVL 1

Author Comment

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

Accepted Solution

by:
jhance earned 40 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.
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 1

Author Comment

by:stevenc317
ID: 1179094
thanks, i got it!
0
 

Expert Comment

by:kraphics
ID: 1179095
Thanks, I needed that.......................
0
 
LVL 10

Expert Comment

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

Guess I'm just a sadist :-)

0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Errors will happen. It is a fact of life for the programmer. How and when errors are detected have a great impact on quality and cost of a product. It is better to detect errors at compile time, when possible and practical. Errors that make their wa…
C++ Properties One feature missing from standard C++ that you will find in many other Object Oriented Programming languages is something called a Property (http://www.experts-exchange.com/Programming/Languages/CPP/A_3912-Object-Properties-in-C.ht…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.
Suggested Courses

770 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