天天看點

MFC時鐘跟定時器

SetTimer(,,NULL);//OnInitDlg()函數裡設定定時器

//重寫該類的WM_TIMER信号函數
void CPictureDlg::OnTimer(UINT_PTR nIDEvent)
{
    // TODO: Add your message handler code here and/or call default
    switch(nIDEvent){
    case :
        {
            //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);
}
           

附上效果圖:每秒更新一次

MFC時鐘跟定時器