I want to do some function every second say, but it could be at some other interval like every 0.1 seconds, I want to register for system clock events, then I can sit back and watch code being triggered by these events.
there are two basic ways to get the events. the first (and usual) way is to create a window procedure to receive the timer events. (you'll have to create a window for this too, but it can be hidden if you like.) Read some Win32 tutorials for more. The second is to use one of the 'wait' functions -- either waiting on a timer control or as the timer itself. For an example of using a wait function as a timer, see here: http://www.cplusplus.com/forum/beginner/5619/#msg25047
// EXAMPLE
#include <iostream>
#include <ctime>
void pause(int dur);
usingnamespace std;
int main (void){
cout << "I will pause my program for eight seconds.. ;D" << endl;
pause(8);
cout << "The program paused for 8 seconds..." << endl;
return 0;
}
void pause(int dur)
{
int temp = time(NULL) + dur;
while(temp > time(NULL));
}
Let me know if this was what you were looking for.
@Code Assassin:
Your pause function would spike the CPU, which isn't gonna fly if other processes are running. If you want to pause for X milliseconds or whatever units, without CPU spikes, you will have to look into platform-specific functions (i.e. Sleep() in Windows).