user4653519
user4653519

Reputation:

How to make SetTimer() only send one WM_TIMER message?

Is it possible to make SetTimer() only send one WM_TIMER message and not send a new message every time the specified time elapses? I am currently using KillTimer() when I receive a WM_TIMER message to stop the timer. Should I continue doing this or there is another way to specify this automatically?

Upvotes: 4

Views: 1722

Answers (2)

Remy Lebeau
Remy Lebeau

Reputation: 595702

SetTimer() creates a periodic timer only. The only way to make it a one-shot timer is to kill the timer on the first WM_TIMER message, as you are already doing.

Otherwise, change your timer logic so you can use CreateWaitableTimer() or timeSetEvent() instead, both of which can create a true one-shot timer.

Upvotes: 6

Jonathan Potter
Jonathan Potter

Reputation: 37122

No, SetTimer always repeats. Just kill it in your WM_TIMER handler to stop it sending another one.

Upvotes: 3

Related Questions