MFC单文档应用程序子线程向主线程发送消息调用函数
程序员文章站
2024-03-23 11:48:58
...
- 在Resource.h文件中添加代码:
#define WM_USER_MSG (WM_USER+2)
- 在View类中添加函数:
LRESULT CMCU_systemView::OnMsg(WPARAM wp, LPARAM lp)
{
CMainFrame* pFrame = (CMainFrame *)AfxGetMainWnd();
pFrame->m_wndStatusBar.SetPaneText(1, "完成!!!", TRUE);
return 1L;
}
- 加入自定义消息映射:
ON_MESSAGE(WM_USER_MSG, &CMCU_systemView::OnMsg)
- 子线程中发送消息到主线程:
CMCU_systemView *para = (CMCU_systemView *)p;//p是线程参数this
::PostMessage(para->GetSafeHwnd(), WM_USER_MSG, WPARAM(0), LPARAM(0));