title: MFC - Posting data via PostMessage to the GUI
body: <p>I Read a few threads on how passing data from Workerthread to Main window(Dialog), but I still don't understand and still need help.
  My workerthread should process some calculations and display the result during each loop to an edit on the GUI. I know, I should use PostMessage but since the calculation I'm doing implies a control element, I don't know how to solve this problem ...</p>
  
  <pre><code> //CWorkerThreadMgr.h manages the second thread
  HRESULT Start (HWND hWnd);// from where the workerthread will be started 
  
   HWND  m_hWnd ;    //Window handle to the UI ;
  
   HANDLE m_hTread;  //handle of the worker thread
  
   static UINT WINAPI ThreadProc( LPVOID lptest ); 
  
  static UINT WINAPI ThreadProc( LPVOID lptest ) 
  
  {    
    CWorkerThreadMgr* pCalculateMgr = reinterpret_cast&lt; CWorkerThreadMgr*(lptest);
  
  //The following operation:rand() *m_Slider.GetPos() should
  
  //should be calculated and the result displayed each time in the edit box in the gui
  
  for( UINT uCount = 0; uCount &lt; 40; uCount++ ){ 
  
  pCalculateMgr-&gt;rand() *m_Slider.GetPos();//?don't allowed to touch the gui!! 
  
  PostMessage(pCalculateMgr-&gt; m_hWnd, WM_SENDCALCULATED_VALUE,wparam(rand() *m_Slider.GetPos(),0); 
  } 
  } 
  
  LRESULT CStartCalculationDlg::OnSendCalculatedValue( WPARAM Result, LPARAM )
  
  { 
      // The resut should be displayed in the edit box
  
        m_Calculation.Format(_T("%d"),???); 
        SetDlgItemText(IDC_CALCULATION, m_Calculation); 
  
       return 1; 
  } 
  
  void CStartCalculationDlg::OnHScroll(UINT nSBCode, UINT nPos,CScrollBar* pScrollBar) 
  { 
    m_SliderValue.Format(_T("%d"),m_Slider.GetPos()); 
    SetDlgItemText(IDC_SLIDER_VALUE,m_SliderValue); 
  } 
  
  // Implementation in the CStartCalculationDlg.h 
  
  CWorkerThreadMgr   m_WorkerThreadMgr  //instance of the WorkerThreadMgr 
  CSliderCtrl  m_Slider  //member variable of the slider control 
  CString m_SliderValue  // member variable of the edit box, where the current value of the 
                         //slider will be displayed 
  CString  m_Calculation // member variable of the edit box where the calculated 
                         //result from  the workerthread will be displayed via PostMessage 
  afx_msg LRESULT OnSendCalculatedValue( WPARAM, LPARAM ); 
  afx_msg void OnHScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar); 
  </code></pre>
  
  <p>The next probem is that, when my slider control is moved and gets a new value, the thread procedure should know it and update the value of the slider. How can I manage to do it?</p>