在对话框中显示时间

来源:互联网 发布:啊哈c编程思维 编辑:程序博客网 时间:2024/04/19 16:39

首先写一个

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