I was wondering if anyone knew how to make a timer? One where the user put in a certain time, and when the counter reaches zero/reached that time, the program would do something that would cause the bottom of the screen to appear and flash, indicating something has happened. I have no idea how to do this, so I have no base code to edit or add on to.
I know it's not a good one, just throwing out another option that he could possibly use - and haha trust me i've seen myself with the speed of a computer when you use anything with loops on a laptop - if you change the battery setting or the power goes out while your running something. Damn big decrease in speed lol
If your developing a GUI application there should be a timer item that will have a callback parameter. Creating the timer and it'll run in it's own thread not tieing up the CPU until it's time is up then call the callback.
If your going to have a blocking timer (e.g stops everything til it's done). Then it's best to use the Sleep() method or a message loop. A message loop would be more beneficial because it'd allow you to process other events (e.g GUI Updates).
The best method if writing your own. Have a class that creates it's own thread. In this thread use the Sleep() call and return after the amount of time. Threading will give you a non-blocking timer.
However, I am 95% sure that Visual Studio has timer objects you can use.
Umm, okay... I'll settle with a simple console app...
I just want help on a timer that'll play a sound when it's done and won't take up any CPU. I have no idea what half of you said means, Zaita, so i guess I'll just stop asking and settle on not coding...
No, it says a few things along the lines of "so and so doesn't exist" and "so and so wasn't declared in this scope." I tried emailing CrazyFoo, but he's at college, and yeah.
void CALLBACK TimerProc (HWND hwnd, UINT message, UINT iTimerID, DWORD dwTime); // define a function somewhere with this prototype
after every "TimerInterval" miliseconds until you finally call
KillTimer (hwnd, 1);
If you need to perform a certain set of commands only once, call the KillTimer() procedure inside your TimerProc() to disable the timer. Of course, the flashing or whatever action you need is coded in the TimerProc (or called from within).
Note: To have more timers in your app, change the second parameter (I chose 1) which has to be the same in evry pair of SetTimer() and KillTimer().
@Mythios: no worries :) I do a fair amount of multi-threaded development and it's something you actually use quite frequently. Especially with socket development.
@Console: Look at poloniny's answer. That's the windows timer I referred to and the simplest way to achieve your result.