You also need to stop the timer before terminating the application. You can do this in the WM_DESTROY case. Add the following statement:
KillTimer(hWnd, idTimer);