CSDN首页 空间 新闻 论坛 Blog 下载 读书 网摘 搜索 .NET Java 视频 接项目 求职 在线学习 买书 程序员 通知
不看会后悔的Windows XP之经验谈 简单快捷DIY实用家庭影院
CSDN社区
搜索 收藏 打印 关闭
CSDN社区 >  VC/MFC >  基础类

关于消息发送

楼主nieguodong()2002-04-02 21:46:00 在 VC/MFC / 基础类 提问

请问sendmessage与postmessage在效果上有什么不同.他们分别应在什么  
  地方使用 问题点数:50、回复次数:8Top

1 楼feelinn(feelinn)回复于 2002-04-02 22:06:19 得分 5

send是要返回,post就不。Top

2 楼LXJ2001(lxj)回复于 2002-04-02 22:06:43 得分 5

sendmessage消息处理才返回,postmessage发送完消息就返回Top

3 楼jacky_mo(把你藏起来)回复于 2002-04-02 22:06:47 得分 5

SendMessage一定要等到你送的消息被处理之后才返回,所以要等待的  
  而PostMessage则不需要等待,只要把消息发到消息队列里他就返回了Top

4 楼yongdu()回复于 2002-04-02 22:07:06 得分 10

send等待消息处理完才返回  
  post则只将消息发送到窗口就返回,不会等待它的处理。  
   
  结果上基本没什么不同,线程上有登记消息队列和发送消息队列,Send的消息发到发送消息队列,post的消息只会在登记消息队列中。  
   
  Send由于要等待消息处理完成才返回,所以如果发送消息和处理消息在两个不同线程内的话,发送线程将会阻塞挂起,等待处理消息线程的处理和唤醒,所以可能会使你的线程永远挂起,而postTop

5 楼eastrock(东方之石)回复于 2002-04-02 22:07:19 得分 10

查msdn:  
  PostMessage  
  Remarks  
  Applications   that   need   to   communicate   using   HWND_BROADCAST   should   use   the   RegisterWindowMessage   function   to   obtain   a   unique   message   for   inter-application   communication.  
   
  If   you   send   a   message   in   the   range   below   WM_USER   to   the   asynchronous   message   functions   (PostMessage   and   SendNotifyMessage),   its   message   parameters   cannot   include   pointers.   Otherwise,   the   operation   will   fail.   The   functions   will   return   before   the   receiving   thread   has   had   a   chance   to   process   the   message   and   the   sender   will   free   the   memory   before   it   is   used.    
   
  SendMessage  
  Remarks  
  Applications   that   need   to   communicate   using   HWND_BROADCAST   should   use   the   RegisterWindowMessage   function   to   obtain   a   unique   message   for   inter-application   communication.  
   
  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.    
   
  Windows   CE   does   not   support   all   the   messages   the   Windows-based   desktop   platforms   support  
  Top

6 楼yongdu()回复于 2002-04-02 22:08:00 得分 5

而用post则不会  
   
  少了几个字Top

7 楼eastrock(东方之石)回复于 2002-04-02 22:08:59 得分 5

SendMessage是不返回,而PostMessage要返回  
  SendMessage   calls   the   window   procedure   for   the   specified   window   and   does   not   return   until   the   window   procedure   has   processed   the   message.   The   PostMessage   function,   in   contrast,   posts   a   message   to   a   thread's   message   queue   and   returns   immediately.Top

8 楼twtpdc(呢呢)回复于 2002-04-02 22:13:50 得分 5

SendMessage是发送消息,需要立即处理,而PostMessage则是寄送,User   模块组  
  会将它放在消息队列中。如楼上所说,前者不返回,后者是要返回的。Top

相关问题

  • 发送消息
  • 发送消息。
  • 发送消息
  • 发送消息,接受消息??
  • 用VB发送消息
  • 发送消息问题
  • 消息发送问题
  • 发送消息给客户
  • 消息发送问题
  • 消息发送问题

关键词

  • 消息
  • 线程
  • 队列
  • 返回
  • 处理
  • 发送
  • postmessage
  • 等待
  • sendmessage
  • communicate

得分解答快速导航

  • 帖主:nieguodong
  • feelinn
  • LXJ2001
  • jacky_mo
  • yongdu
  • eastrock
  • yongdu
  • eastrock
  • twtpdc

相关链接

  • Visual C++类图书
  • Visual C++类源码下载

广告也精彩

反馈

请通过下述方式给我们反馈
反馈
提问
网站简介|广告服务|VIP资费标准|银行汇款帐号|网站地图|帮助|联系方式|诚聘英才|English|问题报告
北京创新乐知广告有限公司 版权所有, 京 ICP 证 070598 号
世纪乐知(北京)网络技术有限公司 提供技术支持
Copyright © 2000-2008, CSDN.NET, All Rights Reserved
GongshangLogo