Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

c

winapi

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?


2 Answers

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.

like image 90
Remy Lebeau Avatar answered Oct 20 '25 08:10

Remy Lebeau


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

like image 43
Jonathan Potter Avatar answered Oct 20 '25 09:10

Jonathan Potter



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!