Wherever you declare your globals:
Code:
#define IDC_TIMER 600 /* Your choice for ID */
UINT g_unTimerRet;
In your message callback:
Code:
LRESULT CALLBACK WindowProcedure(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) {
switch (message) {
case WM_CREATE: {
g_unTimerRet = SetTimer(hWnd, IDC_TIMER, 1000, &TimerProc);
break;
}
case WM_DESTROY: {
KillTimer(hWnd, g_unTimerRet); /* Don't forget to cleanup your mess! */
break;
}
Declare your callback for the timer (prototype) wherever you plan on putting the whole function. For example in main.c:
Code:
/* Prototype */
void CALLBACK TimerProc(HWND, UINT, UINT, DWORD);
/* The timer function that is executed every second according to when it was created */
void CALLBACK TimerProc(HWND hWnd, UINT uMsg, UINT idEvent, DWORD dwTime) {
/* Whatever code you want executed here */
}
I know this works because I use it in my apps and I acquired it from MSDN.