单文档:
在导向程序的第四步中选中 Initial status bar
ResourceView StringTable 中添加一个新的字符串IDS_CLOCK
Caption: 0000-00-00 00:00:00
static UINT indicators []=
{
IDS_CLOCK,
};
在CMainFrame 类 WM_CREATE 添加:SetTimer(1,1000,NULL);
在CMainFrame 类 WM_TIMER添加:
Void CMainFrame::OnTimer (UINT nIDEvent)
{
If (nIDEvent ==1)
{
CTime t;
T=CTime::GetCurrentTime();
CString str=t.Format(“%Y-%m-%d %H:%M:%S”);
m_wndStatusBar.SetPaneText(m_wndStatusBar.CommandToIndex(IDS_CLOCK),str);
}
CFrameWnd ::OnTimer(nIDEvent);
}
在CMainFrame 类 WM_CLOSE添加:
Void CMainFrame::OnClose ()
{
KillTimer(1);
CFrameWnd::OnClose();
}
对话框:
先按上一个技巧在对话框中添加状态栏
ResourceView StringTable 中添加一个新的字符串IDS_CLOCK
Caption: 0000-00-00 00:00:00
static UINT indicators []=
{
IDS_CLOCK,
};
BOOL CClient_Puzzle_V1Dlg::OnInitDialog()
{ …
SetTimer(1,1000,NULL); //用于显示当前时间的定时器
CTime m_SysTime = CTime::GetCurrentTime();
CString str=m_SysTime.Format("%Y-%m-%d %H:%M:%S");
m_wndStatusBar.SetPaneText (m_wndStatusBar.CommandToIndex(IDS_CLOCK), str);
…
}
void CClient_Puzzle_V1Dlg::OnTimer(UINT nIDEvent) //显示系统时间
{
// TODO: Add your message handler code here and/or call default
switch(nIDEvent)
{
case 1:
CTime m_SysTime = CTime::GetCurrentTime();
CString str=m_SysTime.Format("%Y-%m-%d %H:%M:%S");
m_wndStatusBar.SetPaneText (m_wndStatusBar.CommandToIndex(IDS_CLOCK), str);
break;
}
CDialog::OnTimer(nIDEvent);
}
void CClient_Puzzle_V1Dlg::OnOK()
{
// TODO: Add extra validation here
KillTimer (1);
CDialog::OnOK();
}

被折叠的 条评论
为什么被折叠?



