如何在 WinApi (C++) 中创建计时器?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2128620/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-27 22:11:46  来源:igfitidea点击:

How to create timer in WinApi (C++)?

c++winapitimer

提问by SomeUser

How to create timer in WinApi (C++)?

如何在 WinApi (C++) 中创建计时器?

回答by itowlson

Call the SetTimerfunction. This allows you to specify a callback function, or to have Windows post you a WM_TIMER message.

调用SetTimer函数。这允许您指定回调函数,或让 Windows 向您发送 WM_TIMER 消息。

回答by Hans Passant

You cannot not know this if you write GUI code. Which makes it likely you want to use CreateTimerQueueTimer().

如果您编写 GUI 代码,您不可能不知道这一点。这使得您很可能想要使用 CreateTimerQueueTimer()。

回答by Swanand

A Good Example for CreateTimerQueueTimer : Here

CreateTimerQueueTimer 的一个很好的例子:这里

Another is HERE

另一个在这里

回答by John Knoeller

SetTimer. A window handle is needed, and the timer will not be delivered if you aren't pumping messages.

设置定时器。需要一个窗口句柄,如果您不发送消息,则不会传递计时器。

回答by sankar

call the setTimer()Function. Suppose I called

调用setTimer()函数。假设我打电话

SetTimer(hWnd,POST_CBIT_TIMER,500,NULL);

Call back function is

回调函数是

UINT nIdEvent ;//global member variable

case WM_TIMER:

if(nIDEvent == POST_CBIT_TIMER)
{

KillTimer(hParent,POST_CBIT_TIMER);


}
break;