SetTimer is easy. There are two ways you can use it. You can use it in conjunction with a WindowProc, or you can use it with a standalone callback function.
With a callback:
cpp
void APIENTRY OnTimerElapsed(HWND hWnd, UINT uMsg, UINT_PTR idEvent, DWORD dwTime)
{
// Do something
}
// To set the timed callback:
// 5000 means it is called in 5000ms, or 5 seconds
// 1000 is just some arbitrary identifier that you can assign to identify the timer. It cannot be zero, however.
SetTimer(NULL, 1000, 5000, OnTimerElapsed);
As a window proc event:
cpp
LRESULT APIENTRY WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
switch(uMsg) {
case WM_TIMER:
// wParam is the timer id
// lParam is a function specified as the last param of SetTimer
return 0;
}
return DefWindowProc(hWnd, uMsg, wParam, lParam);
}
// To set this:
// hWnd is the handle of the to-be associated window.
SetTimer(hWnd, 1000, 5000, NULL);
By the way, Posix Threads is available for Windows also.
This post has been edited by perfectly.insane: 8 Aug, 2008 - 01:47 PM