3.SetTimer

来源:互联网 发布:js二维数组列数不同 编辑:程序博客网 时间:2024/04/28 00:00

原文:

The SetTimer function creates a timer with the specified time-out value.
UINT SetTimer(
  HWND hWnd,              // handle of window for timer messages
  UINT nIDEvent,          // timer identifier
  UINT uElapse,           // time-out value
  TIMERPROC lpTimerFunc   // address of timer procedure
);
 
Parameters
hWnd
Handle to the window to be associated with the timer. This window must be owned by the calling thread. If this parameter is NULL, no window is associated with the timer and the nIDEvent parameter is ignored.
nIDEvent
Specifies a nonzero timer identifier. If the hWnd parameter is NULL, this parameter is ignored.
uElapse
Specifies the time-out value, in milliseconds.
lpTimerFunc
Pointer to the function to be notified when the time-out value elapses. For more information about the function, see TimerProc.
If lpTimerFunc is NULL, the system posts a WM_TIMER message to the application queue. The hwnd member of the message's MSG structure contains the value of the hWnd parameter.
Return Values
If the function succeeds, the return value is an integer identifying the new timer. An application can pass this value, or the string identifier, if it exists, to the KillTimer function to destroy the timer.
If the function fails to create a timer, the return value is zero. To get extended error information, call GetLastError.
Remarks
An application can process WM_TIMER messages by including a WM_TIMER case statement in the window procedure or by specifying a TimerProc callback function when creating the timer. When you specify a TimerProc callback function, the default window procedure calls the callback function when it processes WM_TIMER. Therefore, you need to dispatch messages in the calling thread, even when you use TimerProc instead of processing WM_TIMER.
The wParam parameter of the WM_TIMER message contains the value of the nIDEvent parameter.
QuickInfo
  Windows NT: Requires version 3.1 or later.
  Windows: Requires Windows 95 or later.
  Windows CE: Requires version 1.0 or later.
  Header: Declared in winuser.h.
  Import Library: Use user32.lib.
See Also
Timers Overview, Timer Functions, KillTimer, MSG, TimerProc, WM_TIMER

翻译:

SetTimer函数一个指定终止时间的定时器
UINT SetTimer(
  HWND hWnd,              // 相关联窗口
  UINT nIDEvent,          //时间标识符
  UINT uElapse,           //设定的时间值
  TIMERPROC lpTimerFunc   // 计时器程序地址
);
参数:
hWnd:与计时器相关联的窗口的句柄。必须被调用的线程所有,如果参数为空,没有窗口与计时器相连,nIDEvent参数被忽略。
nIDEvent:指定一个非零的计时器标识,如果hWnd为空该参数被忽略。
uElapse:指定截止时间,以毫秒计。
lpTimerFunc:指向当时间到时,要通报的函数,要获得更多信息参见TimerProc函数。
如果lpTimerFunc为空,系统发出WM_TIMER消息给应用程序队列。消息的MSG结构体包含hWnd参数的值。
返回值:如果调用成功,是一个识别新的计时器的整数,如果存在应用程序可发送这个值或字符串标识给KillTimer函数来销毁计时器。如果创建计时器失败,返回值为零要得到更多的错误消息,请调用GetLastError函数。
备注:应用程序可以在包含WM_TIMER case声明的窗口处理函数中处理WM_TIMER消息,也可以指定TimerProc回调函数处理。当指定里TimerProc调回函数,默认窗口程序调用调回函数,在处理WM_TIMER消息时。因此需要在调用的线程里分派消息,即使使用TimerProc代替WM_TIMER的处理。
WM_TIMER消息的wParam参数包含着nIDEvent参数。
原创粉丝点击