我正在尝试为我的计时器编写回调。我这样定义 TimerProc:
void CALLBACK TimerProc(HWND hwnd, UINT uMsg, UINT idEvent, DWORD dwTime)
{
//body of callback
}
然后 SetTimer 定义如下:
myTimer = SetTimer(NULL,Timer_ID,30000,TimerProc);
我的问题是一旦时间过去(30 秒),回调就不会被调用。
谢谢你的帮助。
最佳答案
SetTimer
通过发送 WM_TIMER
来工作向默认窗口过程发送消息。因此,正如 MSDN 所述:
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.
所以请确保您有一个 Message Loop运行。
关于c - c 中的 TimerProc 不工作?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7074517/