如果接收线程开始发送消息,SendMessage 可以提前返回吗? [英] Can SendMessage return early if the receiving thread starts pumping messages?

查看:23
本文介绍了如果接收线程开始发送消息,SendMessage 可以提前返回吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

windows 如何精确地决定 SendMessage 应该返回——也就是说,它如何决定接收线程已经完成处理发送的消息?

How precisely does windows decide that SendMessage should return- that is, how does it decide the receiving thread has finished processing the sent message?

详细场景:我有线程 A 使用 SendMessage 向线程 B 发送一个线程.显然,在线程 B 处理完消息之前,SendMessage 不会返回.线程 B 弹出一个对话框并开始发送消息.在我的场景中,队列上有一条 WM_KILLFOCUS 消息,它由线程 B 泵送.结果是线程 B 上的 WM_COMMAND 消息.线程 B 将此 WM_COMMAND 消息传递给默认窗口进程.当它这样做时,SendMessage 返回到线程 A,即使原始消息还没有完成处理!到底是怎么回事?看起来默认窗口进程不知何故混淆了窗口,使其认为原始发送的消息已完成.

Detailed scenario: I've got thread A using SendMessage to send a thread to thread B. Obviously SendMessage doesn't return until thread B finishes processing the message. Thread B pops up a dialog box and starts pumping messages. In my scenario, there is a WM_KILLFOCUS message on the queue which gets pumped by thread B. This results is a WM_COMMAND message on thread B. Thread B passes this WM_COMMAND message to the default window proc. When it does this, SendMessage returns back to thread A, even though the original message hasn't finished processing yet! What is going on? It looks like somehow the default window proc is confusing windows into thinking the original sent message is finished.

那么,是否存在泵送消息和调用默认窗口过程可以诱使 SendMessage 返回的已知场景?

So are there known scenarios where pumping messages and calling the default window proc can trick SendMessage into returning?

谢谢!菲尔

推荐答案

只要消息的处理已经开始,处理线程间消息的WindowProc就可以调用ReplyMessage 允许调用线程在处理继续时继续.

As long as processing of the message has started, the WindowProc processing the interthread message can call ReplyMessage to allow the calling thread to continue while processing continues.

这篇关于如果接收线程开始发送消息,SendMessage 可以提前返回吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆