About Messages and Message Queues

和DOS系统不同的是,Windows系统的程序是基于事件驱动。它们没有显式函数调用(比如C运行时库调用)来获取输入。相反,它们等待系统将输入传递给它们。

系统将所有的输入传给应用程序的每个窗口。每一个窗口都有一个过程函数,当系统接收到输入时,就会调用它。窗口过程函数处理完后,再返回给系统。更多有关过程函数的,请见 Window Procedures .

如果一个顶级窗口没有处理消息超过几秒钟,系统就认为窗口近期不会有消息。这种情况下,系统就隐藏这个窗口,并用一个相同大小,位置等视觉效果的窗口来代替。用户可以移动和改变它的大小。甚至关闭它。但是,这都是一些无效的行为,因为窗口已经没有响应。在调试模式下,系统不会生成幽灵窗口。

本节将讨论以下主题:

Windows Messages

系统用消息的形式将用户输入发送给窗口过程函数,消息由系统和应用程序中生成。系统生成将每一个输入事件转换成消息--举个例子,当用户打字,移动鼠标或点击滚动条时。系统也会根据应用程序的变化来生成消息,例如,当应用程序的字体或大小发生改变时。一个程序可以生成消息指挥自己的窗口执行或与其它的窗口通信。

系统用消息的形式将用户输入发送给窗口过程函数,消息由系统和应用程序中生成。系统生成将每一个输入事件转换成消息--举个例子,当用户打字,移动鼠标或点击滚动条时,系统也会根据应用程序的变化来生成消息,例如,当应用程序的字体或大小发生改变时。一个程序可以生成消息指挥自己的窗口执行或与其它的窗口通信。系统发送给过程函数的消息带有四个参数;窗口句柄,消息标识符,和两个消息参数。窗口句柄为要接受消息的窗口,系统使用它来确定应该接收消息的窗口过程。
消息标识符是标识消息目的的命名常量。当窗口过程接收消息时,它使用消息标识符来决定如何处理消息。例如,消息标识符WM_PAINT告诉窗口过程,窗口的客户区域已经更改,必须重新绘制。

消息参数指定在处理消息时使用的数据或数据的位置。消息参数的含义和值取决于消息。消息参数可以包含一个整数、填充的位标志、指向包含附加数据的结构的指针等等。当消息不使用消息参数时,它们通常被设置为NULL。窗口过程必须检查消息标识符,以确定如何解释消息参数。

Message Types

这一节描述两个消息(Message)类型:

System-Defined Messages

系统在与应用程序通信时发送一个系统定义的消息。它使用这些消息来控制应用程序的操作,并为应用程序提供输入和其他信息。应用程序也可以自己发送system-defined消息。程序通常使用这些消息控制使用预先窗口类创建的窗口控件。

每一个system-defined消息都有一个唯一的消息标识符和符号常量(在软件开发包(SDK)的头文件中有定义)。举个例子,WM_PAINT常量请求窗口重新绘制自己。

符号常量指定每一个system-define消息所属的类别。每个消息前缀表示了消息的目的,下面为消息前缀和相关消息类别。

Prefix Message category Documentation
ABM and ABN Application desktop toolbar Shell Messages and Notifications
ACM and ACN Animation control Animation Control Messages and Animation Control Notifications
BCMBCNBM, and BN Button control Button Control Messages and Button Control Notifications
CB and CBN ComboBox control ComboBox Control Messages and ComboBox Control Notifications
CBEM and CBEN ComboBoxEx control ComboBoxEx Messages and ComboBoxEx Notifications
CCM General control Control Messages
CDM Common dialog box Common Dialog Box Messages
DFM Default context menu Shell Messages and Notifications
DL Drag list box Drag List Box Notifications
DM Default push button control Dialog Box Messages
DTM and DTN Date and time picker control Date and Time Picker Messages and Date and Time Picker Notifications
EM and EN Edit control Edit Control MessagesEdit Control NotificationsRich Edit Messages, and Rich Edit Notifications
HDM and HDN Header control Header Control Messages and Header Control Notifications
HKM Hot key control Hot Key Control Messages
IPM and IPN IP address control IP Address Messages and IP Address Notifications
LB and LBN List box control List Box Messages and List Box Notifications
LM SysLink control SysLink Control Messages
LVM and LVN List view control List View Messages and List View Notifications
MCM and MCN Month calendar control Month Calendar Messages and Month Calendar Notifications
PBM Progress bar Progress Bar Messages
PGM and PGN Pager control Pager Control Messages and Pager Control Notifications
PSM and PSN Property sheet Property Sheet Messages and Property Sheet Notifications
RB and RBN Rebar control Rebar Control Messages and Rebar Control Notifications
SB and SBN Status bar window Status Bar Messages and Status Bar Notifications
SBM Scroll bar control Scroll Bar Messages
SMC Shell menu Shell Messages and Notifications
STM and STN Static control Static Control Messages and Static Control Notifications
TB and TBN Toolbar Toolbar Control Messages and Toolbar Control Notifications
TBM and TRBN Trackbar control Trackbar Control Messages and Trackbar Control Notifications
TCM and TCN Tab control Tab Control Messages and Tab Control Notifications
TDM and TDN Task dialog Task Dialog Messages and Task Dialog Notifications
TTM and TTN Tooltip control Tooltip Control Messages and Tooltip Control Notifications
TVM and TVN Tree-view control Tree View Messages and Tree View Notifications
UDM and UDN Up-down control Up-Down Messages and Up-Down Notifications
WM General
Clipboard Messages Clipboard Notifications Common Dialog Box Notifications Cursor Notifications Data Copy Message Desktop Window Manager Messages Device Management Messages Dialog Box Notifications Dynamic Data Exchange Messages Dynamic Data Exchange Notifications Hook Notifications Keyboard Accelerator Messages Keyboard Accelerator Notifications Keyboard Input Messages Keyboard Input Notifications Menu Notifications Mouse Input Notifications Multiple Document Interface Messages Raw Input Notifications Scroll Bar Notifications Timer Notifications Window Messages Window Notifications




  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值