新建一个单文档工程
在resource.h当中添加两个宏
#define TIMER1 1
#define TIMER2 2
在CMainFrame的OnCreate()方法当中定义两个定时器的属性
SetTimer(TIMER1,3000,0);
SetTimer(TIMER2,5000,0);
新建一个消息处理函数,用来处理消息 WM_TIMER
void CMainFrame::OnTimer(UINT nIDEvent)
{
// TODO: Add your message handler code here and/or call default
switch(nIDEvent)
{
case TIMER1:
{
AfxMessageBox("定时器1!");
break;
}
case TIMER2:
{
AfxMessageBox("定时器2!");
break;
}
default:
break;
}
CFrameWnd::OnTimer(nIDEvent);
}