能力值:
( LV2,RANK:10 )
|
-
-
关于SetTimer函数的问题
MFC SetTimer函数的用法
1) 函数原型及变形
SetTimer这个API函数的原型 :
UINT_PTR SetTimer(
HWND hWnd, // 窗口句柄
UINT_PTR nIDEvent, // 定时器ID,多个定时器时,可以通过该ID判断是哪个定时器
UINT uElapse, // 时间间隔,单位为毫秒
TIMERPROC lpTimerFunc // 回调函数
);
注意:设置第二个参数时要注意,如果设置的等待时间比处理时间短,程序就会出问题了。
回调函数:在这个函数里,放入你想要做的事情的代码,你可以将它设定为NULL,也就是使用系统默认的回调函数,系统默认认的是onTime函数。
例如 :
SetTimer(m_hWnd,1,1000,NULL); //一个1秒触发一次的定时器
在MFC程序中SetTimer被封装在CWnd类中,调用就不用指定窗口句柄了
于是SetTimer函数的原型变为:
UINT SetTimer(UINT nIDEvent,UINT nElapse,void(CALLBACK EXPORT *lpfnTimer)(HWND,UINT ,YINT ,DWORD)) ,用法如:SetTimer(1,1000,NULL);
|
能力值:
( LV2,RANK:10 )
|
-
-
|