启用一个定时器直接调用函数: SetTimer(1,500,NULL);//定义时钟 1,时间间隔为 500ms SetTimer(2,1000,NULL);//定义时钟 2,时间间隔为 1000ms 可以在按钮按下时启用定时器: void CTimeDlg::OnButton1() { // TODO: Add your control notification handler code here SetTimer(1,500,NULL);//定义时钟 1,时间间隔为 500ms SetTimer(2,1000,NULL);//定义时钟 2,时间间隔为 1000ms } 2
关闭定时器:可以在按钮中调用如下函数关闭某定时器: void CTimeDlg::OnButton2() { // TODO: Add your control notification handler code here KillTimer(1); //关闭 1 号定时器 KillTimer(2); //关闭 2 号定时器 } 3
添加定时器时间到的处理代码: 1) 在开发界面中 Ctrl+W 进入 MFCclass wizard 页面 2) 选择 Message Maps 选项卡 3) 在 Project 中选择你的工程 4) 在 object Ids:中选择 C…
Dlg 5) 在Messages:中选择 WM_TIMER,此时,Member functions 中自动定位到: W OnTimer ON_WM_TIMER, 6) 单击 EDIT code(或双击W OnTimer ON_WM_TIMER)自动进入如下函数: void CTimeDlg::OnTimer(UINT nIDEvent) { // TODO: Add your message handler code he