什么是PostMessage? [英] what is PostMessage?

查看:340
本文介绍了什么是PostMessage?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

什么是PostMessage?我们如何从线程中使用?我浏览了一些文档,但尚不清楚,我无法理解,因此请大家对此提供意见.... Thanx in Advance

解决方案

Windows Naming的怪异之处在于,"SendMessage()"与TCP/IP"send()"不同,它不是即发即弃"消息传递机制.

SendMessage()是立即分派到目标窗口(HWND)的消息处理,并且直到消息处理完成后才返回,并且可能返回该消息处理的结果(如获取控件值).消息的所有处理都在堆栈上和线程的上下文中完成.

由于只有控件拥有"(读取:创建)的线程可以操纵它,所以一个线程(例如工人线程")不可能直接操纵另一个线程(例如线程")拥有的控件. "GUI线程"),因此"SendMessage()"不是适当的机制.

因此,"PostMessage()"是一种将标准窗口控件"消息从非GUI"线程发送到控件的机制.自定义或用户定义的消息也可以创建一种从其他线程触发GUI操作"的方法.

请注意,"SendMessage()"和"PostMessage()"都不是用于通用消息传递的,因为目标(HWND)和数据值(WPARAM,LPARAM)的大小和格式受到严格限制.如果您想要通用的消息/进程间通信功能,请发布一个更具体的问题,因为有多个选项,其中一些选项比其他选项更好. Windows(当然,您不必一定是获取/发送消息的窗口).

两种基本方法SendMessage()PostMessage()相似(在原型中),但是行为却大不相同. SendMessage()是一个同步消息发送方,其中调用方法等待接收方发送和处理该消息,然后接收方返回.相反,PostMessage()是异步的,在这种情况下,发送方发送消息,并且不等待接收方返回.每种方法都有其适当的用途,因此请小心选择正确的方法.

作为补充,还有PostThreadMessage()和使用线程句柄而不是窗口句柄向其发布消息的异步调用.


what is PostMessage ? how can we use from an thread ? i went through some documents but it is not clear enough for me to understand so guys pls give inputs regarding this.....Thanx in Advance

解决方案

It is one of the oddities of Windows Naming that "SendMessage()", unlike TCP/IP "send()", is not a "fire and forget" message passing mechanism.

SendMessage() is an immediate dispatch to the target window''s (HWND) message handling and does not return until the message processing is complete and may return the result of that message processing (like getting a controls value). All of the processing for the message is done on your stack and in your thread''s context.

Since only the thread that "owns" (read : created) the control can manipulate it, it is not possible for one thread (e.g., a "worker thread") to directly manipulate a control "owned" by another thread (e.g., the "GUI thread") so "SendMessage()" is not an appropriate mechanism.

Hence, "PostMessage()" is the mechanism to send standard Window Control messages from a "non-GUI" thread to the controls. Custom or User Defined messages are also possible to create a way to "trigger GUI actions" from other threads.

Note that neither "SendMessage()" nor "PostMessage()" are meant for general purpose message passing as the destination (HWND) and data values (WPARAM, LPARAM) are very restricted in size and format. If you want general message / interprocess commmunication capability, post a more specific question as there are several options, some better than others.


Messaging is the basic way within the MS framework to get information between windows (of course, you don''t have to necessarily be a window to get/send a message).

The two basic methods, SendMessage() and PostMessage() are similar (in prototype) but very different in behavior. SendMessage() is a synchronous message sender, where the calling method waits for the message to be sent and processed by the receiver and the receiver to return. In contrast, PostMessage() is asynchronous, in which case the sender sends the message and DOES NOT wait for a return from the receiver. Each method has it''s appropriate uses, so be careful to choose the correct one.

To add to the mix, there is also PostThreadMessage(), and asynchronous call that uses a thread handle rather than a window handle to post messages to.


这篇关于什么是PostMessage?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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