MFC時鐘跟定時器
阿新 • • 發佈:2019-01-23
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);
}
附上效果圖:每秒更新一次