Starting from the article “C++ timer”, we created a simply class that act as a wrapper to the Windows API and that easily allows to start a timer, stop it. and assign the function to call when the timer is elapsed.

Timer

The following is a little example that explains how to use the class:

// this is the method invoked when the timer is elapsed
void CALLBACK OnTimer(HWND hwnd, UINT uMsg, UINT_PTR idEvent, DWORD dwTime)
{
	// write here the code to execute at onTimer event
}

int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE, LPSTR, int nCmdShow)
{
	// ...
	Timer * timer = new Timer(NULL, (TIMERPROC)OnTimer, 1, 1000);
	timer->StartTimer();
	// ..
}

The class is very simple and is based on the post “C++ timer”, so I avoid explanations about the code and I leave you with the download. :)

Download C++ Timer Class. Downloads: 1109


Se sei interessato a questo post, potresti anche provare a leggere:

  • No related posts