MFC PostMessage

#define WM_UPDATE_STATIC (WM_USER + 100)  

afx_msg LRESULT OnUpdateStatic(WPARAM wParam, LPARAM lParam);


BEGIN_MESSAGE_MAP(CUserDlg, CBCGPDialog)
ON_MESSAGE(WM_UPDATE_STATIC, &CUserDlg::OnUpdateStatic)

END_MESSAGE_MAP()


LRESULT CUserDlg::OnUpdateStatic(WPARAM wParam, LPARAM lParam)
{
if (wParam == 0) {
GetDlgItem(IDC_STATIC_MESSAGE)->SetWindowText(_T("Hello Linux"));
}
else {
GetDlgItem(IDC_STATIC_MESSAGE)->SetWindowText(_T("Hello Windows"));

}

}


UINT CUserDlg::ThreadFunction(LPVOID pParam)
{
CUserDlg *pDlg = (CUserDlg *)pParam;


while (TRUE) {
::PostMessage(pDlg->m_hWnd, WM_UPDATE_STATIC, 0, 0);
Sleep(1000);
::PostMessage(pDlg->m_hWnd, WM_UPDATE_STATIC, 1, 0);
Sleep(1000);
}


return 0;
}

     m_pThread = AfxBeginThread((AFX_THREADPROC)ThreadFunction, this);




你可能感兴趣的:(MFC PostMessage)