Browse - Programming Tips - How can I have timer without a thread?

Date: 2016apr23
OS: Windows
Platform: win32
Keywords: InitTimer, StartTimer

Q.  How can I have timer without a thread?

A.  Use Windows' timers.

Initialize it:
#define IDT_TIMER1 (1000) // Any number will do SetTimer(hwnd, // handle to main window IDT_TIMER1, // timer identifier 10000, // 10-second interval NULL); // Send a windows message, don't call a function
Then you'll get a WM_TIMER message:
switch(message) { case WM_TIMER: switch (wParam) { case IDT_TIMER1: // Do something with the timer return 0; }
Stop it:
KillTimer(hwnd, IDT_TIMER1);