SetTimer(1,1000,NULL);//OnInitDlg()函数里设置定时器
//重写该类的WM_TIMER信号函数
void CPictureDlg::OnTimer(UINT_PTR nIDEvent)
{
// TODO: Add your message handler code here and/or call default
switch(nIDEvent){
case 1:
{
//KillTimer(1);
CTime m_time;
m_time = CTime::GetCurrentTime();
//CString m_strdate = m_time.Format(_T("%X"));
CString m_s=m_time.Format(_T("%Y-%m-%d %H:%M:%S"));//%A
//AfxMessageBox(m_s);
SetDlgItemText(IDC_STATIC,m_s);
break;
}
}
CDialogEx::OnTimer(nIDEvent);
}
附上效果图:每秒更新一次