About Messages and Message Queues

 1.将数据类的指针用发消息的办法发给另外一个线程是个非常不正确的做法。

让界面自个儿来取更新的数据同步其自身的数据备份或刷新界面等。不同工作者线程间则可以通过一个信号体等等来通知。

postmessage由于是直接把消息放到接收线程的消息队列,在队列满的时候会发送失败。这时候一般人会在接收线程的处理消息函数里删除指针指向的数据。

应该在发送线程对postmessage做一个是否成功的判断,如果失败重发或者删除指针指向的数据。

 

sendmessage由于是同步执行的,会等接收线程的处理函数执行完才返回,如果接收线程yields control 就会使sendmessage一直卡那里使发送线程继续不下去。一般会发生yields control 的是消息处理函数内调用的跳对话框等图形界面的函数。

不知道yields control 是什么意思。

Before calling any of the functions that will yields control while processing a message, the window procedure should first call InSendMessage or InSendMessageEx. If this function returns TRUE, the window procedure must call the ReplyMessage function before any function that causes the thread to yield control.

 

If the receiving thread is attached to the same queue as the sender, it can cause an application deadlock to occur. (Note that journal hooks attach threads to the same queue.)

 

 

Using SMTO_BLOCK could create a deadlock situation until the timeout expires—for example, if you send a message to another thread and that thread needs to send a message to your thread. In this case, neither thread can continue processing and both threads are forever suspended.

 

 

if an application GetMessage()  filters for a WM_CHAR message in a window that does not receive keyboard input, the GetMessage function does not return. 因为WM_CHAR 是由 TranslateMessage WM_KEYDOWN 得来的,不接收WM_KEYDOWN 就得不到WM_CHAR

 

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值