Add a WindowProc() window procedure function using the ClassWizard then Post a user message to this dialog from the new thread, the main thread will receive the post in WindowProc() to perform the updates to the window.
Code:
//CTest2Dlg.h
#define WM_USER_MYUPDATE WM_USER +1
class CTest2Dlg : public CDialog
{
public:
...
...
// Overrides
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CTest2Dlg)
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
virtual LRESULT WindowProc(UINT message, WPARAM wParam, LPARAM lParam);
//}}AFX_VIRTUAL
...
...
};
//CTest2Dlg.cpp
LRESULT CTest2Dlg::WindowProc(UINT message, WPARAM wParam, LPARAM lParam)
{
//lParam = "nice thread"
switch( message )
{
case WM_USER_MYUPDATE:
m_SerialText->Insert(m_SerialText->GetLength(), (char *)lParam);
m_SerialText->Insert(m_SerialText->GetLength(), "\r\n");
m_SerialTextControl->UpdateWindow();
break;
}
return CDialog::WindowProc(message, wParam, lParam);
}
BOOL CTest2Dlg::OnInitDialog()
{
CDialog::OnInitDialog();
m_WorkThread = AfxBeginThread( ThreadProc , this);
return TRUE;
}
UINT CTest2Dlg::ThreadProc( LPVOID pParam )
{
char strMsg[] = "nice thread"
while( doing_something )
{
PostMessage(WM_USER_MYUPDATE, 0, (LPARAM )strMsg);
}
AfxEndThread(0);
return 0;
}