4.2.7 Modifying the WM_DESTROY Case

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);