1. First, add two strings in the string table, ID are IDS_INDICATOR_MESSAGE and IDS_INDICATOR_TIME
2. In your class inside dlg.h add CStatusBar m_bar;
3. At the beginning of dlg.cpp plus
static UINT indicators[] =
{
IDS_INDICATOR_MESSAGE,
IDS_INDICATOR_TIME
};
4.OnInitDialog inside with
m_bar.Create(this); //We create the status bar
m_bar.SetIndicators(indicators,2); //Set the number of panes
CRect rectum;
GetClientRect(&rect);
//Size the two panes
m_bar.SetPaneInfo(0,IDS_INDICATOR_MESSAGE, SBPS_NORMAL,rect.Width()-100);
m_bar.SetPaneInfo(1,IDS_INDICATOR_TIME,SBPS_STRETCH ,0);
//This is where we actually draw it on the screen
RepositionBars(AFX_IDW_CONTROLBAR_FIRST,AFX_IDW_CONTROLBAR_LAST, ID_INDICATOR_TIME);
The time display
OnInitDialog which add SetTimer (1,1000, NULL);
Add WM_TIMER response function for your class dlg, add code in which:
CTime t1;
t1=CTime::GetCurrentTime();
m_bar.SetPaneText(1,t1.Format("%H:%M:%S"));
CDialog::OnTimer(nIDEvent);
Such a procedure is added during the beginning of a run in the time bar displays the character is initially set, in order to make the program display system at the beginning of operation, may m_bar.SetPaneInfo (1, IDS_INDICATOR_TIME, SBPS_STRETCH, 0); after add the following code:
CTime t1;
t1=CTime::GetCurrentTime();
m_bar.SetPaneText(1,t1.Format("%H:%M:%S"));
This will display the system time when the program has just started, and real-time updates.
CSDN on 2015-5-15