今天犯了一个粗心的错误,在无窗口线程中,SetTimer中设置计时器ID,而WM_TIMER消息响应函数中得到的计时器ID却不是之前设置的计时器ID.
对应计时器ID的输出的是一个随机数字.
原来在msdn中
- nIDEvent
- [in] Specifies a nonzero timer identifier. If the hWnd parameter is NULL, and the nIDEvent does not match an existing timer then it is ignored and a new timer ID is generated. If the hWnd parameter is not NULL and the window specified by hWnd already has a timer with the value nIDEvent , then the existing timer is replaced by the new timer. When SetTimer replaces a timer, the timer is reset. Therefore, a message will be sent after the current time-out value elapses, but the previously set time-out value is ignored. If the call is not intended to replace an existing timer, nIDEvent should be 0 if the hWnd is NULL.
- 注:只有当hWnd参数为非空时,计时器的ID为设置的 nIDEvent, 系统为你自动生成一个计时器ID,可由返回时值获取.
本文探讨了在无窗口线程中使用SetTimer函数时遇到的问题:设置的计时器ID与接收到的消息中的ID不符。通过MSDN文档解释了这一现象的原因,并提供了代码示例。
263

被折叠的 条评论
为什么被折叠?



