Your application must also stop the timer before terminating. You can do this by adding a WM_DESTROY case to the application, as follows:
KillTimer(hWnd, idTimer);
KillTimer
(hWnd, idTimer);