消息与消息队列

原创 2012年03月22日 13:02:46

Messages and Message Queues
消息与消息队列
--------------------------------------------------------------------------------
This section describes messages and message queues and how to use them in your applications.
这一节讲的是怎样在你的应用程序中使用消息和消息队列

Overviews
概述

About Messages and Message Queues
关于消息与消息队列

This section discusses Windows messages and message queues.
这一节讨论的是windows消息与消息队列

Using Messages and Message Queues
使用消息与消息队列

The following code examples demonstrate how to perform the following tasks associated with Microsoft Windows messages and message queues.
接下来的代码例句阐述了在windows中消息和消息队列怎样执行接下来的任务


Functions
函数

BroadcastSystemMessage
The BroadcastSystemMessage function sends a message to the specified recipients. The recipients can be applications, installable drivers, network drivers, system-level device drivers, or any combination of these system components.
BroadcastSystemMessage 函数向指定的收件人发送一条消息。收件人可以为应用程序、可安装驱动、网络驱动器、系统级装备驱动或者是这些系统组件的任意组合。

To receive additional information if the request is defined, use the BroadcastSystemMessage Ex function.
使用BroadcastSystemMessageEx 函数,可以接受到附加信息。

BroadcastSystemMessageEx
The BroadcastSystemMessageEx function sends a message to the specified recipients. The recipients can be applications, installable drivers, network drivers, system-level device drivers, or any combination of these system components.
BroadcastSystemMessageEx函数向指定的收件人发送一条信息。收件人可以是应用程序、可安装驱动、网络驱动器、系统级装备驱动或者是这些系统组件的任意组合。

This function is similar to BroadcastSystemMessage except that this function can return more information from the recipients.
这个函数与BroadcastSystemMessage相似,但是可以从收件人处返回更多的信息。

DispatchMessage
The DispatchMessage function dispatches a message to a window procedure. It is typically used to dispatch a message retrieved by the GetMessage function.
DispatchMessage函数调度一个消息给窗口程序。通常调度从GetMessage函数得到的消息。

GetInputState
The GetInputState function determines whether there are mouse-button or keyboard messages in the calling thread's message queue.
GetInputState函数判定是否有鼠标或者键盘信息在线程消息队列。

GetMessage
The GetMessage function retrieves a message from the calling thread's message queue. The function dispatches incoming sent messages until a posted message is available for retrieval.
GetMessage函数从线程消息队列获得一条信息。这个函数不断调度进来的信息直到发布的信息可用为止

Unlike GetMessage, the PeekMessage function does not wait for a message to be posted before returning.
和 GetMessage不同的是PeekMessage函数不用等到一条信息发布就可以返回

GetMessageExtraInfo
The GetMessageExtraInfo function retrieves the extra message information for the current thread. Extra message information is an application- or driver-defined value associated with the current thread's message queue.
GetMessageExtraInfo函数从当前线程中获得额外信息。额外信息是当前消息线程队列中一个应用程序或者驱动程序的值

GetMessagePos
The GetMessagePos function retrieves the cursor position for the last message retrieved by the GetMessage function.
GetMessagePos函数可以获得GetMessage函数最后一个信息的光标位子

To determine the current position of the cursor, use the GetCursorPos function.
使用GetCursorPos函数可以确定当前光标的位子

GetMessageTime
The GetMessageTime function retrieves the message time for the last message retrieved by the GetMessage function. The time is a long integer that specifies the elapsed time, in milliseconds, from the time the system was started to the time the message was created (that is, placed in the thread's message queue).
GetMessageTime函数可以获得GetMessage函数最后信息的时间。这个时间是从系统启动时间到信息创造出的时间的长整数,单位为毫秒(即安放在线程消息列队里)

GetQueueStatus
The GetQueueStatus function indicates the type of messages found in the calling thread's message queue.
GetQueueStatus函数显示在线程消息队列里的消息类型

InSendMessage
The InSendMessage function determines whether the current window procedure is processing a message that was sent from another thread (in the same process or a different process) by a call to the SendMessage function.
InSendMessage函数决定当前窗口程序是否处理另一线程调用SendMessage(在相同进程或不同进程中)发送的消息

To obtain additional information about how the message was sent, use the InSendMessageEx function.
使用InSendMessageEx函数可以获得消息是如何发送的额外信息

InSendMessageEx
The InSendMessageEx function determines whether the current window procedure is processing a message that was sent from another thread (in the same process or a different process).
InSendMessageEx函数决定当前窗口程序是否处理另一线程(在相同进程或不同进程中)发送的消息

PeekMessage
The PeekMessage function dispatches incoming sent messages, checks the thread message queue for a posted message, and retrieves the message (if any exist).
PeekMessage函数调度进来的消息,检查已发布的消息的线程消息队列,获得消息(如果有的话)

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.
PostMessage函数放置一条消息在消息队列中,在这个线程中创建指定的窗口且可以不用等待线程处理消息就返回

To post a message in the message queue associate with a thread, use the PostThreadMessage function.
使用PostThreadMessage函数可以在一个线程中发布一条消息在消息队列

PostQuitMessage
The PostQuitMessage function indicates to the system that a thread has made a request to terminate (quit). It is typically used in response to a WM_DESTROY message.
PostQuitMessage函数向系统表明一个线程请求终止。通常用在响应WM_DESTROY消息

PostThreadMessage
The PostThreadMessage function posts a message to the message queue of the specified thread. It returns without waiting for the thread to process the message.
PostThreadMessage函数向线程中的消息队列发布一条消息。不需要等待线程处理消息就返回

RegisterWindowMessage
The RegisterWindowMessage function defines a new window message that is guaranteed to be unique throughout the system. The message value can be used when sending or posting messages.
RegisterWindowMessage函数定义一个新窗口信息,这个新窗口信息在系统中的独一无二的。这个消息指可以在发送或发布消息是使用。

ReplyMessage
The ReplyMessage function is used to reply to a message sent through the SendMessage function without returning control to the function that called SendMessage.
ReplyMessage函数是用来应答SendMessage函数发送的消息,而不返回控制调用SendMessage的函数

SendAsyncProc
The SendAsyncProc function is an application-defined callback function used with the SendMessageCallback function. The system passes the message to the callback function after passing the message to the destination window procedure. The SENDASYNCPROC type defines a pointer to this callback function. SendAsyncProc is a placeholder for the application-defined function name.
SendAsyncProc函数是和SendMessageCallback函数一起使用的一个应用程序定义的回调函数。系统将消息传给目标窗口程序后,再传给回调函数。SendAsyncProc是应用程序定义的函数名的一个占位符。

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.
SendMessage函数将指定的消息发送给一个或多个窗口。这个函数为指定的窗口调用窗口程序,当窗口程序处理完消息后返回

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.
使用SendMessageCallback或SendNotifyMessage函数,立即发送和返回一条消息。使用PostMessage or PostThreadMessage函数,发布一条消息给线程消息队列,然后立即返回


SendMessageCallback
The SendMessageCallback function sends the specified message to a window or windows. It calls the window procedure for the specified window and returns immediately. After the window procedure processes the message, the system calls the specified callback function, passing the result of the message processing and an application-defined value to the callback function.
SendMessageCallback函数给一个或多个窗口发送指定的消息。这个函数为指定的窗口调用窗口程序,然后立即返回。在窗口程序处理消息后,系统调用指定的回调函数,将消息处理结果和应用程序定义值发给回调函数。

SendMessageTimeout
Sends the specified message to one of more windows.
发送指定的消息给更多窗口中的一个

SendNotifyMessage
The SendNotifyMessage function sends the specified message to a window or windows. If the window was created by the calling thread, SendNotifyMessage calls the window procedure for the window and does not return until the window procedure has processed the message. If the window was created by a different thread, SendNotifyMessage passes the message to the window procedure and returns immediately; it does not wait for the window procedure to finish processing the message.
SendNotifyMessage函数发送指定的消息给一个或多个窗口。如果窗口是由调用的线程创建,SendNotifyMessage就为窗口调用窗口程序,直至窗口程序完成处理消息后返回。如果窗口是由一个不同线创建,SendNotifyMessage将消息传给窗口程序,然后立即返回;这个函数不需要等待窗口程序处理完消息。

SetMessageExtraInfo
The SetMessageExtraInfo function sets the extra message information for the current thread. Extra message information is an application- or driver-defined value associated with the current thread's message queue. An application can use the GetMessageExtraInfo function to retrieve a thread's extra message information.
SetMessageExtraInfo函数为当前线程设置额外消息信息。额外消息信息是当前线程消息队列中的一个应用程序或者驱动定义值。应用程序能够使用GetMessageExtraInfo函数来获得一个线程额外的消息信息。

TranslateMessage
The TranslateMessage function translates virtual-key messages into character messages. The character messages are posted to the calling thread's message queue, to be read the next time the thread calls the GetMessage or PeekMessage function.
TranslateMessage函数是将虚拟键消息转换为字符消息。字符消息被指派去调用线程消息列队,从而在下一次线程调用GetMessage or PeekMessage函数时被读取

WaitMessage
The WaitMessage function yields control to other threads when a thread has no other messages in its message queue. The WaitMessage function suspends the thread and does not return until a new message is placed in the thread's message queue.
当一个线程在它的消息队列里没有其他消息时,WaitMessage函数产生对其他线程的控制。WaitMessage函数终止线程,直到有一个新消息出现在线程消息队列时,再返回。

Notifications
OCM__BASE
The OCM__BASE constant is used by applications to help define private messages for use by private window classes, usually of the form OCM__BASE+X, where X is an integer value.
OCM__BASE常数通常被应用程序用来帮助为私有的窗口类别定义私有消息,通常用OCM__BASE+X的格式,X是一个整数值

Note  Unlike WM_APP and WM_USER, OCM__BASE is defined in Olectl.h.
和M_APP and WM_USER不同的是:OCM__BASE是在Olectl.h.定义

WM_APP
The WM_APP constant is used by applications to help define private messages, usually of the form WM_APP+X, where X is an integer value.
WM_APP常数通常被应用程序用来帮助定义私有消息,通常用WM_APP+X的格式,X是一个整数值

WM_QUIT
The WM_QUIT message indicates a request to terminate an application and is generated when the application calls the PostQuitMessage function. It causes the GetMessage function to return zero.
WM_QUIT消息指示了终止应用程序的请求,并且当应用程序调用PostQuitMessage函数时产生。WM_QUIT造成GetMessage函数返回到0

WM_USER
The WM_USER constant is used by applications to help define private messages for use by private window classes, usually of the form WM_USER+X, where X is an integer value.
WM_USER常数通常被应用程序用来帮助为私有的窗口类别定义私有消息,通常用WM_USER+X的格式,X是一个整数值


Structures
BSMINFO
The BSMINFO structure contains information about a window that denied a request from BroadcastSystemMessageEx.
BSMINFO结构包含拒绝BroadcastSystemMessageEx函数请求的窗口信息。

MSG
The MSG structure contains message information from a thread's message queue.
MSG结构包含线程消息队列的消息信息

 

uC/OS-II 学习笔记之:信号量、消息邮箱、消息队列之间的使用区别

////////////////////////////////////////////////////////////////////////////////////////////////////...
  • dcx1205
  • dcx1205
  • 2013年05月27日 22:19
  • 3388

远程调用服务(RPC)和消息队列(Message Queue)对比及其适用/不适用场合分析

最近考虑把公司系统重构升级,将原有的垂直MVC架构迁移为分布式系统,因此着重了解了下远程调用服务(RPC)和消息队列(MQ)。一开始对这两个概念比较模糊,RPC和MQ都是用于分布式系统的两个关键技术,...
  • cfydaniel
  • cfydaniel
  • 2015年03月25日 14:19
  • 5598

消息队列的发送与接收

//消息队列的发送与接收 #include #include #include #include #include //不包含此头文件,会出现“警告:隐式声明与内建函数strcpy不...
  • jiamantuo
  • jiamantuo
  • 2016年11月03日 21:25
  • 795

进程间通信(IPC)之消息队列

漫谈进程间通信之消息队列,进程通信家族中不可或缺的一员。交流学习,共同进步。...
  • Xiao__Tian__
  • Xiao__Tian__
  • 2016年07月07日 01:24
  • 3521

基于Dubbo的分布式系统架构(二)-消息中间件在分布式系统中的作用及介绍

一、消息中间件的定义        Message-orientedmiddleware (MOM) is software infrastructure focused on sending and...
  • qq_26504875
  • qq_26504875
  • 2016年07月07日 12:53
  • 2229

Linux下多任务间通信和同步-消息队列

Linux下进程间通信和同步-消息队列 消息队列就是一些消息的列表.用户可以在消息队列中添加消息和读取消息等.从这点上看,消息队列具有一定的FIFO特性,但是它可以实现消息的随机查询,比FIFO具有更...
  • ce123
  • ce123
  • 2013年10月10日 07:12
  • 6001

消息队列的读写

#include #include #include #include #include #include #include struct message { ...
  • mianhuantang848989
  • mianhuantang848989
  • 2015年06月29日 11:17
  • 590

System V和Posix消息队列的差别

一、posix消息队列与system v消息队列的差别: 1、对posix消息队列的读总是返回最高优先级的最早消息,对system v消息队列的读则可以返回任意指定优先级的消息。 2、当往一个空队...
  • LookAtTheStars
  • LookAtTheStars
  • 2016年07月17日 22:04
  • 848

消息队列MQ实践----实现Queue(队列消息)和Topic(主题消息)两种模式

之前有篇文件介绍了生产消费者模式(http://blog.csdn.net/canot/article/details/51541920),当时是通过BlockingQueue阻塞队列来实现,以及在R...
  • canot
  • canot
  • 2016年12月11日 12:04
  • 9180

UCOSII 消息邮箱 消息队列

代码来自于书本光盘 《嵌入式操作系统UCOSII原理及应用》 消息邮箱实例 /************************Test*****************************...
  • liang890319
  • liang890319
  • 2012年12月30日 16:03
  • 3508
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:消息与消息队列
举报原因:
原因补充:

(最多只允许输入30个字)