在MFC中增加一个时间计时器消息事件
利用this->SetTimer(1,1000,NULL);开启计时器
添加响应事件
void Csqllink1Dlg::OnTimer(UINT_PTR nIDEvent)
{
CTime tm;
tm=CTime::GetCurrentTime();
CWnd* pWnd = (CWnd*)GetDlgItem(IDC_STATIC);
switch(nIDEvent)
{
case 1:
//MessageBox(_T("test"));
//MessageBox(NULL,_T("test"),_T("test"),MB_OK);
// CString str1=_T(" ");
str001=tm.Format(_T("现在时间是%Y年%m月%d日 %X"));
//MessageBox(str001,NULL,MB_OK);
pWnd->SetWindowTextW(str001);
break;
default:
break;
}
}
添加消息映射:
BEGIN_MESSAGE_MAP(Csqllink1Dlg, CDialog)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_STN_CLICKED(IDC_STATIC_1, &Csqllink1Dlg::OnStnClickedStatic1)
ON_BN_CLICKED(IDOK, &Csqllink1Dlg::OnBnClickedOk)
ON_WM_TIMER()
ON_BN_CLICKED(IDCANCEL, &Csqllink1Dlg::OnBnClickedCancel)
END_MESSAGE_MAP()
完成消息的映射