首先寫一個
void OnStartTimer()
{
m_nTimer = SetTime(1, 500, 0);//500 is the time of callback
}
declare UINT_PTR m_nTimer;
use it in initial function, then you will get new time in half of a second.
在對話框的命令欄裏添加WM_OnTimer,
void OnTimer(UINT_PTR nIDEvent)
{
time_t osBinaryTime;
time(&osBinaryTime);
CTime t(osBinaryTime);
CString c=t.Format("%H:%M:%S");
SetDlgTextItem(IDC_SHOWTIMER, c);
}
參數nIDEvent是在SetTime函數中被初始化。