Windows API一日一练(67)SetTimer和KillTimer函数
来源:互联网 发布:直通车地域优化 编辑:程序博客网 时间:2024/05/21 18:32
在前面介绍了一对定时器的API函数使用,现在又介绍另外一对API函数的使用。它使用起来比前的函数要简单一些,但它一般是使用到有窗口的程序里,并且它的精度也没有前面的API函数高,对于一些要求不高的场合还是非常合适的。它是采用消息通知的方式,每当定时到了就会收到一条消息。
函数SetTimer和KillTimer声明如下:
WINAPI
SetTimer(
__in_opt HWND hWnd,
__in UINT_PTR nIDEvent,
__in UINT uElapse,
__in_opt TIMERPROC lpTimerFunc);
WINUSERAPI
BOOL
WINAPI
KillTimer(
__in_opt HWND hWnd,
__in UINT_PTR uIDEvent);
hWnd是窗口接收定时器的句柄。
nIDEvent是定时器事件标识号。
uElapse是定时器的毫秒值。
lpTimerFunc是定时到达回调函数。
调用函数的例子如下:
#001 //设置定时器。
#002 ::SetTimer(m_hWnd, //指向窗口的句柄。
#003 IDT_TIMER1, // 定时器标识。
#004 1000, // 1秒
#005 (TIMERPROC) NULL); // 不使用回调函数。
接收WM_TIMER消息并关闭定时器:
#001 case WM_TIMER:
#002 {
#003 if (IDT_TIMER1 == wParam)
#004 {
#005 OutputDebugString(_T("定时器测试消息关闭/r/n"));
#006 ::KillTimer(m_hWnd,IDT_TIMER1);
#007 }
#008
#009 }
#010 break;
- Windows API一日一练(67)SetTimer和KillTimer函数
- Windows API一日一练(67)SetTimer和KillTimer函数
- Windows API一日一练(67)SetTimer和KillTimer函数
- Windows API一日一练(67)SetTimer和KillTimer函数
- Windows API一日一练(67)SetTimer和KillTimer函数
- Windows API一日一练(67)SetTimer和KillTimer函数
- Windows API一日一练(67)SetTimer和KillTimer函数
- Windows API一日一练(67)SetTimer和KillTimer函数
- Windows API一日一练(67)SetTimer和KillTimer函数
- Windows API一日一练(67)SetTimer和KillTimer函数
- Windows API一日一练(67)SetTimer和KillTimer函数
- Windows API - Timer Function , SetTimer和KillTimer函数
- SetTimer和KillTimer函数
- SetTimer和KillTimer函数
- SetTimer和KillTimer函数
- SetTimer和KillTimer函数
- Windows API一日一练(5)RegisterClass和RegisterClassEx函数
- Windows API一日一练(9)WindowProc和DefWindowProc函数
- .Net Remoting配置文件的用法
- 书评 -- Microsoft SQL Server 2005 Integration Services
- 多核编程的几个难题及其应对策略(难题一)
- Windows API一日一练(71)GetComputerName函数
- Java游戏程序部署在不同平台的手机模拟器上
- Windows API一日一练(67)SetTimer和KillTimer函数
- 用JSP实现基于Web的RSS阅读器
- 书评 -- Professional SQL Server 2005 Reporting Services
- 使用 PreparedStatement 进行模糊查询
- Windows API一日一练(66)CreateWaitableTimer和SetWaitableTimer函数
- Guru of the Week 条款20:代码的复杂性(第一部分)
- Webwork2开发文档
- Windows API一日一练(65)RegQueryValueEx函数
- 用AS3调用摄像头(附源代码下载)