title: Open a MFC dialog in a std::thread
body: <p>I would like to show a dialog to inform the user that the application is busy. To avoid blocking of the main thread, I was thinking to use a std::thread to show the dialog. Consider the following code:</p>
  
  <pre><code>InProcDlg inProcess;
  std::thread t([ &amp;inProcess ] {      
      inProcess.DoModal();
      delete inProcess;
  });
  // wait till process has finished 
  ::PostMessage(inProcess.m_hWnd, WM_USER + 1, 0, 0);
  if (t.joinable()){
      t.join();
  }
  </code></pre>
  
  <p>InProcDlg.cpp</p>
  
  <pre><code>BEGIN_MESSAGE_MAP(InProcDlg, CDialogEx)
    ...
    ON_MESSAGE(WM_USER + 1, &amp;InProcDlg::close)
  END_MESSAGE_MAP()
  
  LRESULT InProcDlg::close(WPARAM wParam, LPARAM lParam)
  {
    UNREFERENCED_PARAMETER(wParam, lParam);
    EndDialog(1);
    return 0;
  }
  </code></pre>
  
  <p>Running this code the dialog is shown properly. The dialog is also closed, but the main dialog is not shown, the application hangs in <code>CreateRunDlgIndirect()</code>. Trying to step in, while setting some breakpoints the main dialog is shown properly back again. Very strange. I would be very happy for any advices where I have to dive deeper in. </p>
  
  <p>In the next step I would also like to show the process to the user, by sending an integer indicating the current state of process.</p>
  
  <pre><code>int *percent;
  ::PostMessage(inProcess.m_hWnd, WM_USER + 2, 0, reinterpret_cast&lt;LPARAM&gt;(percent));
  </code></pre>
  
  <p>How I can gain evidence that the dialog is already existing, before sending or posting a message?
  I'm using Visual Studio 2013.</p>