I'm trying to create a simple non-blocking timer in C++ that can be reset. I've google searched for a while to find some code examples but everything I find is either too complicated to understand or does not compile without extra non example code.
I have a program that logs a key press to a file, but I want this file to be written over one seconds after the key has been pressed unless another key has been pressed before the second is up.
I believe I should use Win32 timers, (I am using windows) however I can't find a simple compilable example of their use.
for example this method taken from the info page:
SetTimer(hwnd, // handle to main window
IDT_TIMER1, // timer identifier
1000, // 1-second interval
(TIMERPROC) MyTimerProc); // no timer callback
VOID CALLBACK MyTimerProc(
HWND hwnd, // handle to window for timer messages
UINT message, // WM_TIMER message
UINT idTimer, // timer identifier
DWORD dwTime) // current system time
{
// my proceedure code
FILE *OUTPUT_FILE;
OUTPUT_FILE = fopen("LOG.TXT", "w");
fprintf(OUTPUT_FILE, "%s", "");
fclose(OUTPUT_FILE);
// writes a blank text file.
KillTimer(hwnd, IDT_TIMER1); // stop timer after one call
}
doesn't compile because the IDT_TIMER1 hasnt' been defined I think.
Also, I'm not sure if this would be reset by calling it twice or would just start two separate calls 1 second apart.
Any help greatly appreciated.