MFC中的OnTime
2012-09-04 12:49
120 查看
你需要在需要计时器的类的生成onTime函数:
在ClassWizard里,选择需要计时器的类,添加WM_TIMER消息映射,就自动生成OnTime函数了
先请看SetTimer这个API函数的原型
UINT_PTR SetTimer(
HWND hWnd, // 窗口句柄
UINT_PTR nIDEvent, // 定时器ID,多个定时器时,可以通过该ID判断是哪个定时器
UINT uElapse, // 时间间隔,单位为毫秒
TIMERPROC lpTimerFunc // 回调函数
);
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))
第三个参数是一个回调函数,在这个函数里,放入你想要做的事情的代码,你可以将它设定为NULL,
也就是使用系统默认的回调函数,系统默认认的是onTime函数。
SetTimer(1,1000,NULL);
1:计时器的名称;
1000:时间间隔,单位是毫秒;
NULL:使用onTime函数。
不需要计时器的时候调用KillTimer(1);
在ClassWizard里,选择需要计时器的类,添加WM_TIMER消息映射,就自动生成OnTime函数了
先请看SetTimer这个API函数的原型
UINT_PTR SetTimer(
HWND hWnd, // 窗口句柄
UINT_PTR nIDEvent, // 定时器ID,多个定时器时,可以通过该ID判断是哪个定时器
UINT uElapse, // 时间间隔,单位为毫秒
TIMERPROC lpTimerFunc // 回调函数
);
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))
第三个参数是一个回调函数,在这个函数里,放入你想要做的事情的代码,你可以将它设定为NULL,
也就是使用系统默认的回调函数,系统默认认的是onTime函数。
SetTimer(1,1000,NULL);
1:计时器的名称;
1000:时间间隔,单位是毫秒;
NULL:使用onTime函数。
不需要计时器的时候调用KillTimer(1);
相关文章推荐
- 解决 mfc OninitDialog里面隐藏对话框的方法
- MFC 自定义非窗口类控件中实现 ON_COMMAND 和 ON_UPDATE_COMMAND_UI
- 解决php It is not safe to rely on the system's timezone settings. You are *required* to use the date.
- LOCK ON SYS.SMON_SCN_TIME [ID 747745.1]
- MFC中ON_UPDATE_COMMAND_UI和ON_COMMAND消息区别
- Do not spend all your time on training or studying
- [MFC]两个GetCurrentTime()的区别
- Coping with the TCP TIME-WAIT state on busy Linux servers
- Show IplImage on MFC Window
- 解决php的It is not safe to rely on the system’s timezone settings的问题
- MFC里ON_COMMAND_RANGE消息映射的ID问题
- About Setting the Time on All Nodes
- 关于 MFC 的 OnInitialUpDate
- Synchronization and Time(Chapter 2 of Concurrent Programming on Windows)
- Installed Pop Corn time on Xiaomi
- List the UTC Time on a Computer
- MFC消息映射之ON_COMMAND_RANGE()
- Real-time model scoring for streaming data – a prototype based on Oracle Stream Explorer and Oracle
- MFC中ON_COMMAND_RANGE()消息映射
- PHP Warning: date() [function.date]: It is not safe to rely on the system's timezone