Can you supply me with boilerplate code for a simple console tsr program? I’m using VC++ 4.0, and I want to create a console program to check a directory every five minutes and delete zf*.* files. I don’t know if Windows NT has an event activator to fire this program every five minutes, so I had to resort to tsr programming.
First of all, all Windows applications are terminate and stay resident (TSR) applications in that they initialize themselves and then return control to the system. So I’m not sure what you mean by TSR in this case.
Beyond that, Windows has always supported timers, which direct Windows to call your application after a given time elapses. To begin the timer, just call SetTimer.
SetTimer (hWnd, 1, 5000, NULL);The third argument specifies how much time to wait before notifying your application. The time is specified in milliseconds (1000 = 1 second). Note that the time is not precise. You should probably track the system time at each notification and determine if you want to perform your task.
Once you start the timer this way, Windows will send a WM_TIMER message to your window repeatedly as the time elapses.
case WM_TIMER: MessageBeep(MB_OK); break;Use KillTimer to stop the timer messages.