title: Scrollbar messages block interthread messages in MFC
body: <p>I have an MFC application which is composed of multiple threads, but the problem is with a specific two. </p>
  
  <ol>
  <li>The first thread (CGuiThread) is responsible for GUI (it's not the main thread) and contains a window object (CMainWindow), which contains an inner window object (CInnerWindow), which displays multiple progress displays and has a scroll bar.</li>
  <li>The second thread (CStatusDispatcherThread) is responsible for sending to the gui thread messages, which contain progress status information related to some calculation processes.</li>
  </ol>
  
  <p>Once the calculations begin, the status dispatcher sends messages with the status to the GUI thread. The gui thread updates progress bars in the inner window accordingly.</p>
  
  <p>The problem starts when I move or hold the thumb of the inner window's scroll bar - it seems that GUI thread stops processing the status messages from the status dispatcher thread, since the progress bars are no longer updated. Not only that, I'd expect the status messages to be stopped somewhere and processed once I release the tumb, but it is not happening. New messages arrive but the messages that while clicking are lost.</p>
  
  <p>If anyone has an idea what could be the cause, I would be very grateful.</p>
  
  <p>I tried "catching" the status messages in the CGuiThread::PreaTranslateMessage function, but it seems that after holding the scroll thumb, they no longer get there, even though PostThreadMessage of CStatusDispatcherThread indicates they were sent successfully.</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false">
  <div class="snippet-code">
  <pre class="snippet-code-css lang-css prettyprint-override"><code>#define MY_MESSAGE 1
  
  class CStatusDispatcherThread : public CWinThread
  {
    //... 
    
    // This class sends progress status percentaget to gui thread via PostThreadMessage
    OnTimer(UINT nIDEvent)
    {
        PostThreadMessage(iThreadID,MY_MESSAGE,100,0);
    }
  };
  
  class CGuiThread : public CWinThread
  {
    //...
    
  BEGIN_MESSAGE_MAP(CGuiThread, CWinThread)
    ON_THREAD_MESSAGE(MY_MESSAGE,OnStatusMessage)
  END_MESSAGE_MAP()
    
  private:
    CMyMainWindow m_mainWindow;
    
    void OnStatusMessage(WPARAM iStatus, LPARAM dummy);
    {
        m_mainWindow.updateStatus((int)iStatus)
    }
  };
  
  class CMyMainWindow : public CWnd
  {
    //...
    void updateStatus(int iStatus)
    {
        m_sbarWindow.updateStatusBar(iStatus);
    }
    
  private:
    CInnerWindow m_sbarWindow;
  }; 
   
  class CInnerWindow : public CWnd
  {
    //...
    
    void updateStatusBar(int iStatus)
    {
        //...
    }
  
  private:
    BOOL Create(...)
    {
        CWnd::Create(strClassName, strWindowTitle, WS_DLGFRAME | WS_CHILD| WS_VISIBLE | WS_VSCROLL,
          rectRectOfWnd, pParentWnd, iID, NULL);
    }
    
    void OnVScroll(nSBCode, nPos, pScrollBar)
    {
        //...
    }
  };</code></pre>
  </div>
  </div>
  </p>
  
  <p>Thank in advance,
  Gal</p>