在對話框中顯示時間

首先寫一個

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函數中被初始化。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章