One way to do this is to call SetTimer and then handle the WM_TIMER event in WndProc. For example, this sets a timer that is called every 45 seconds and displays a message box when it is called:
LRESULT CALLBACK WndProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
switch (message)
{
case WM_CREATE:
SetTimer (hwnd, 1, 45000, NULL);
break;
case WM_TIMER:
MessageBox (hwnd, L "Timer", L "Timer fired!", MB_OK);
break;
}
return DefWindowProc (hwnd, message, wParam, lParam);
}
The first parameter to SetTimer is the window into which you want to receive the WM_TIMER message. You probably want this to be your window, so you can just walk into the hwnd that passed you by.
The second parameter is a number that you can use to uniquely identify the timer. You may have more than one timer running at the same time, and it will need a way to tell which one has been started.
The third parameter is how long you want the timer to wait before it starts. This is in milliseconds, so you need a few thousand if you want seconds.
The fourth parameter is NULL if you want to handle timers by looking at WM_TIMER. Otherwise, you can pass a pointer to a callback function that will be called instead.
Remember that the timer will continue to fire every X milliseconds until you kill it. You can kill it by calling KillTimer and passing the same number that you passed to the second parameter when calling SetTimer.
In addition, when Windows sends you the WM_TIMER message, wParam will contain the timer identifier that you passed in the second parameter when you called SetTimer.
Slapout
source share