SendMessage消息传递信息和调用函数有什么不同呢

cktaa 2018-03-09 10:58:15
在一个MFC中多个线程运行
一个线程中运算完后通过
::SendMessage(pInfo->hWnd,WM_INFO,bResult,i);

传递至下面的函数运行
LRESULT OnMyInfo(WPARAM wParam,LPARAM lParam);

这样调用和直接 调用OnMyInfo() 有什么区别呢
...全文
488 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
mstlq 2018-03-09
  • 打赏
  • 举报
回复
二楼说得很对 如果还想知道细节,官方文档是这么说的 If the specified window was created by the calling thread, the window procedure is called immediately as a subroutine. If the specified window was created by a different thread, the system switches to that thread and calls the appropriate window procedure. Messages sent between threads are processed only when the receiving thread executes message retrieval code. The sending thread is blocked until the receiving thread processes the message. However, the sending thread will process incoming nonqueued messages while waiting for its message to be processed. 参考链接https://msdn.microsoft.com/en-us/library/windows/desktop/ms644950(v=vs.85).aspx
狐狸小十 2018-03-09
  • 打赏
  • 举报
回复
在同一线程里,和直接调用响应函数一样 其他线程会进入消息队列
真相重于对错 2018-03-09
  • 打赏
  • 举报
回复
看<深入浅出MFC>
ooolinux 2018-03-09
  • 打赏
  • 举报
回复
SendMessage发送消息是要等待返回的,PostMessage发送消息直接就返回了,等到消息队列处理到那条消息时,才会调用消息映射的那个函数。有时候直接调用函数可能会引起界面死锁,死锁就是我手握A还等待B,你手握B还等待A,都不放手,就一直等待了。

24,854

社区成员

发帖
与我相关
我的任务
社区描述
C/C++ 工具平台和程序库
社区管理员
  • 工具平台和程序库社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧