小盒子的小盒

【原创】VC2005手动添加定时器函数

0
阅读(2221)

如何手工在VC2005中添加定时器的功能?

文件:SmallBoxSystemDlg.cpp 中添加以下程序:

#define TIMEID1  1
#define TIMEID2  2

BEGIN_MESSAGE_MAP(CheSystemDlg, CDialog)
 ON_WM_SYSCOMMAND()
 ON_WM_PAINT()
 ON_WM_TIMER()
 ON_WM_QUERYDRAGICON()
 //}}AFX_MSG_MAP
END_MESSAGE_MAP()

2.启动定时器

 SetTimer(TIMEID1,5000,0);
 SetTimer(TIMEID2,7000,0);

3.定时器函数

void CSmallBoxSystemDlg::OnTimer(UINT nIDEvent)
{
    // TODO: Add your message handler code here and/or call default
    switch(nIDEvent) {
    case TIMEID1:
        {   
            AfxMessageBox("定时器1!");
            break;
        }
 case TIMEID2:
        {   
            AfxMessageBox("定时器2!");
            break;
        }
    default:
        ;
    }
   
    CheSystemDlg::OnTimer(nIDEvent);
}

在SmallBoxSystemDlg.h文件中声明该函数

public:
          afx_msg void OnTimer(UINT nIDEvent);