I'm not really sure what you are doing, but DestroyWindow is usually problematic. Have you tried just posting a WM_QUIT to the window instead? That should cleanly end the window and it will let its parent know that it is exiting cleanly too, so you may not even have to detach.