title: How to close a modeless MFC dialog in C++
body: <p>I have a modeless dialog that is sometimes left up on the screen when I go to close my main app. If I close it manually, all destructors get called properly. But so far, if I try to do it through C++ code, I encounter problems in the Debug build that don't give me confidence in what is happening in the Release build.</p>
  
  <p>What is the correct way to close a modelss dialog? Documentation for <code>PostQuitMessage()</code> indicates it closes entire threads (is a modeless dialog run in a separate thread, or just part of the single MFC App UI thread?). Calling <code>DestroyWindow()</code> gives me issues in practice. Sending a <code>WM_CLOSE</code> doesn't feel like the right thing to do. And <code>CWnd::EndDialog()</code> only applies to Modal dialogs. Does the correct answer lie among these... or somewhere else?</p>