天天看点

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时钟跟定时器