Is it possible to have more than one timer in one window/application? Want to animate different objects on different times, or timings!
Is it possible to have more than one timer in one window/application? Want to animate different objects on different times, or timings!
I believe that's possible, as long as they are not the same ID. But you could of course also just do something like this:
That will perform the "doSomething" every 5th (count 0..4) tick - and it's most likely more lightweight than having two timers running simultaneously.Code:void handleTimer() { static int tCount = 0; tCount++; if (tCount > 3) { doSomething; tCount = 0; } doEveryTick(); }
--
Mats
Compilers can produce warnings - make the compiler programmers happy: Use them!
Please don't PM me for help - and no, I don't do help over instant messengers.
I wrote a better one long ago.
If it's any use, for C, here it is:
http://cboard.cprogramming.com/showp...6&postcount=10
Although it doesn't use the use the timer mechanism.
--
Mats
Compilers can produce warnings - make the compiler programmers happy: Use them!
Please don't PM me for help - and no, I don't do help over instant messengers.
Are these timers handled as threads, i mean which gets called first? Also, my idea is to simultaneously run them on different speeds (i.e. move two objects on screen on different speeds)Code:// Set two timers. SetTimer(hwnd, // handle to main window IDT_TIMER1, // timer identifier 10000, // 10-second interval (TIMERPROC) NULL); // no timer callback SetTimer(hwnd, // handle to main window IDT_TIMER2, // timer identifier 300000, // five-minute interval (TIMERPROC) NULL); // no timer callback /* To process the WM_TIMER messages generated by these timers, add a WM_TIMER case statement to the window procedure for the hwnd parameter. */ case WM_TIMER: switch (wParam) { case IDT_TIMER1: // process the 10-second timer return 0; case IDT_TIMER2: // process the five-minute timer return 0; }
The way a timer works is that it posts a message to your message queue with the WM_TIMER message-type, and with the relevant ID. The messages for multiple timers may be posted at once by the OS. It is then up to your message-handler (aka event-loop) to handle the WM_TIMER message - this normally means that one happens after the other, but theoretically you could come up with (complicated) code that attempts to run multiple timer event's functions at once.
I hope this clarifies things - if not, please ask whatever it is you don't understand.
--
Mats
Compilers can produce warnings - make the compiler programmers happy: Use them!
Please don't PM me for help - and no, I don't do help over instant messengers.
If either of the timers has to perform a lenghty task (ie process large data files into a DB), remember to KillTimer(), perform the task and start the timer again.
"Man alone suffers so excruciatingly in the world that he was compelled to invent laughter."
Friedrich Nietzsche
"I spent a lot of my money on booze, birds and fast cars......the rest I squandered."
George Best
"If you are going through hell....keep going."
Winston Churchill