title: PostMessage from WorkerThread to Main Window in MFC
body: <p>I have a MFC application, which has a worker thread, what I want to do is to post message from worker  thread to the Main GUI thread to update some status messages on GUI. What I have done so far is <code>Registered a new window message</code></p>
  
  <pre><code>//custom messages
  static UINT FTP_APP_STATUS_UPDATE = ::RegisterWindowMessageA("FTP_APP_STATUS_UPDATE");
  </code></pre>
  
  <p>Added this message to the message map of dialog class</p>
  
  <pre><code>ON_MESSAGE(FTP_APP_STATUS_UPDATE, &amp;CMFC_TestApplicationDlg::OnStatusUpdate)
  </code></pre>
  
  <p>The prototype of <code>OnStatusUpdate</code> is</p>
  
  <pre><code>afx_msg LRESULT OnStatusUpdate(WPARAM, LPARAM);
  </code></pre>
  
  <p>and definition is </p>
  
  <pre><code>LRESULT CMFC_TestApplicationDlg::OnStatusUpdate(WPARAM wParam, LPARAM lParam)
  {
  
       //This function is not called at all.
       return 0;
  }
  </code></pre>
  
  <p>and the worker thread calling code is</p>
  
  <pre><code>void CMFC_TestApplicationDlg::OnBnClickedMfcbutton1()
  {
      ThreadParams params;
      params.m_hWnd = m_hWnd;
      params.FTPHost = "test_host";
      params.FTPUsername = "test";
      params.FTPPassword = "test";
  
      AfxBeginThread(FTPConnectThread,&amp;params);
  }
  </code></pre>
  
  <p>and Worker thread code is</p>
  
  <pre><code>//child thread function
  UINT FTPConnectThread( LPVOID pParam )
  {
      if(pParam == NULL)
      {
          return 0;
      }
      ThreadParams *params = (ThreadParams*)pParam;
      OutputDebugString(params-&gt;FTPHost);
      Sleep(4000); //simulating a network call
      CString * message = new CString("Conencted");
      PostMessage(params-&gt;m_hWnd,FTP_APP_STATUS_UPDATE,0,(LPARAM)message);
      //PostMessage do nothing? what I am doing wrong?
      return 1;
  }
  </code></pre>
  
  <p>the problem is when the PostMessage function is called the <code>OnStatusUpdate</code> should be called, but it is not being called, no exception or assertion is thrown, What I am doing wrong? I have tried <code>ON_REGISTERED_MESSAGE</code> and <code>ON_MESSAGE</code> but no success, any help?</p>