PostMessage和SendMessage的区别

本文详细解释了PostMessage与SendMessage两种消息传递方式的区别。PostMessage将消息放置在消息队列中并立即返回,而SendMessage则等待消息被处理后才返回。通过一个具体的例子展示了两种方法在实际应用中的不同表现。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

1.PostMessage  
  The   PostMessage   function   places   (posts)   a   message   in   the   message   queue   associated   with   the   thread   that   created   the   specified   window   and   returns   without   waiting   for   the   thread   to   process   the   message.    
   
2.SendMessage  
  The   SendMessage   function   sends   the   specified   message   to   a   window   or   windows.   It   calls   the   window   procedure   for   the   specified   window   and   does   not   return   until   the   window   procedure   has   processed   the   message.    
  To   send   a   message   and   return   immediately,   use   the   SendMessageCallback   or   SendNotifyMessage   function.   To   post   a   message   to   a   thread's   message   queue   and   return   immediately,   use   the   PostMessage   or   PostThreadMessage   function. 

 

PostMessage消息发出后不等消息函数处理完就执行它的下一语句  
SendMessage消息发出后阻塞等消息函数处理完执行它的下一语句

 

例如:

一个按钮向发一个消息,然后弹出一个模态对话框。

当你高速点击该按钮时,采用postmessage可能会产生多次点击事件,导致弹出多个模态对话框

而使用sendmessage,一次点击后必须响应后才能出来下一次点击,就可以避免以上问题 

 

闻香止步 淘宝店 摆件 饰品 *木雕系列*:海南黄花梨、越南黄花梨、草花梨、小叶紫檀、黑檀、绿檀木、黄杨木、桃木发簪  木梳 樟木壁挂 佛珠 车饰 摆件
收藏送礼佳品
http://shop36570193.taobao.com

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值