1.首先在string table 里添加兩個(gè)字串,ID分別為IDS_INDICATOR_MESSAGE and IDS_INDICATOR_TIME
2.在你的 dlg.h 類(lèi)里面加個(gè) CStatusBar m_bar;
3.在dlg.cpp 開(kāi)頭加上
static UINT indicators[] =
{
IDS_INDICATOR_MESSAGE,
IDS_INDICATOR_TIME
};
4.OnInitDialog 里面加上
m_bar.Create(this); //We create the status bar
m_bar.SetIndicators(indicators,2); //Set the number of panes
CRect rect;
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);
5.時(shí)間顯示
OnInitDialog 里面加 SetTimer(1,1000,NULL);
為你的dlg類(lèi)添加WM_TIMER的響應函數,在其中添加代碼:
CTime t1;
t1=CTime::GetCurrentTime();
m_bar.SetPaneText(1,t1.Format("%H:%M:%S"));
CDialog::OnTimer(nIDEvent);
這樣添加的程序剛開(kāi)始運行時(shí)在時(shí)間一欄中顯示的是初始設置的字符,為了使程序在剛開(kāi)始運行時(shí)就顯示系統時(shí)間,可在m_bar.SetPaneInfo(1,IDS_INDICATOR_TIME,SBPS_STRETCH ,0);后添加如下代碼:
CTime t1;
t1=CTime::GetCurrentTime();
m_bar.SetPaneText(1,t1.Format("%H:%M:%S"));
這樣在程序剛啟動(dòng)時(shí)就會(huì )顯示系統時(shí)間,然后實(shí)時(shí)更新。
聯(lián)系客服