MFC中使用多个定时器

来源:互联网 发布:手机练钢琴软件 编辑:程序博客网 时间:2024/06/05 11:38

1,在MFC中添加WM_TIMER消息处理函数会生成

[cpp] view plain copy
 
  1. void CFaceDetectDlg::OnTimer(UINT_PTR nIDEvent)  
  2. {  
  3.        CDialogEx::OnTimer(nIDEvent);  
  4. }  
在需要定时的地方使用
[cpp] view plain copy
 
  1. SetTimer(1,10,NULL);  
  2. SetTimer(2,100,NULL);  
  3. SetTimer(3,200,NULL);  

设置定时其开始定时,设定自己需要的时间间隔

其中第一个参数1,2,3,为定时其的ID

然后再OnTimer()函数中处理每个定时器事件

[cpp] view plain copy
 
  1. void CFaceDetectDlg::OnTimer(UINT_PTR nIDEvent)  
  2. {  
  3.     // TODO: Add your message handler code here and/or call default  
  4.     switch(nIDEvent)//nIDEvent 为定时器事件ID,1,2,3  
  5.     {     
  6.     case 1:  
  7.         {}  
  8.                  break;  
  9.         case 2:  
  10.                 {}  
  11.                  break;  
  12.         }  
  13. }  
0 0
原创粉丝点击