tags:

views:

705

answers:

3

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

+3  A: 

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

John Knoeller
+5  A: 

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

itowlson
as per nobugz - this will not work in console applications or non gui threads. threads must be pumping messages to generate SetTimer callbacks.
Chris Becke
+1  A: 

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

Hans Passant
this is console application
SomeUser
Yes, CreateTimerQueueTimer is your friend. Beware that the callback is executed on a threadpool thread so use proper locking.
Hans Passant