How to create timer in WinApi (C++)?
5 Answers
Call the SetTimer function. This allows you to specify a callback function, or to have Windows post you a WM_TIMER message.
2 Comments
Chris Becke
as per nobugz - this will not work in console applications or non gui threads. threads must be pumping messages to generate SetTimer callbacks.
You cannot not know this if you write GUI code. Which makes it likely you want to use CreateTimerQueueTimer().
2 Comments
Hans Passant
Yes, CreateTimerQueueTimer is your friend. Beware that the callback is executed on a threadpool thread so use proper locking.
Li-chih Wu
CreateWaitableTimer can also be used in console application. msdn.microsoft.com/en-us/library/windows/desktop/…
SetTimer. A window handle is needed, and the timer will not be delivered if you aren't pumping messages.