About Messages and Message Queues

来源:互联网 发布:raphael min.js 下载 编辑:程序博客网 时间:2024/05/12 03:13

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

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

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

本节将讨论以下主题:

  • Windows Messages
  • Message Types
    • System-Defined Messages
    • Application-Defined Messages
  • Message Routing
    • Queued Messages
    • Nonqueued Messages
  • Message Handling
    • Message Loop
    • Window Procedure
  • Message Filtering
  • Posting and Sending Messages
    • Posting Messages
    • Sending Messages
  • Message Deadlocks
  • Broadcasting Messages
  • Query Messages

Windows Messages

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

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

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

Message Types

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

  • System-Defined Messages
  • Application-Defined Messages

System-Defined Messages

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

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

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

PrefixMessage categoryDocumentationABM and ABNApplication desktop toolbarShell Messages and NotificationsACM and ACNAnimation controlAnimation Control Messages and Animation Control NotificationsBCMBCNBM, and BNButton controlButton Control Messages and Button Control NotificationsCB and CBNComboBox controlComboBox Control Messages and ComboBox Control NotificationsCBEM and CBENComboBoxEx controlComboBoxEx Messages and ComboBoxEx NotificationsCCMGeneral controlControl MessagesCDMCommon dialog boxCommon Dialog Box MessagesDFMDefault context menuShell Messages and NotificationsDLDrag list boxDrag List Box NotificationsDMDefault push button controlDialog Box MessagesDTM and DTNDate and time picker controlDate and Time Picker Messages and Date and Time Picker NotificationsEM and ENEdit controlEdit Control Messages, Edit Control Notifications, Rich Edit Messages, and Rich Edit NotificationsHDM and HDNHeader controlHeader Control Messages and Header Control NotificationsHKMHot key controlHot Key Control MessagesIPM and IPNIP address controlIP Address Messages and IP Address NotificationsLB and LBNList box controlList Box Messages and List Box NotificationsLMSysLink controlSysLink Control MessagesLVM and LVNList view controlList View Messages and List View NotificationsMCM and MCNMonth calendar controlMonth Calendar Messages and Month Calendar NotificationsPBMProgress barProgress Bar MessagesPGM and PGNPager controlPager Control Messages and Pager Control NotificationsPSM and PSNProperty sheetProperty Sheet Messages and Property Sheet NotificationsRB and RBNRebar controlRebar Control Messages and Rebar Control NotificationsSB and SBNStatus bar windowStatus Bar Messages and Status Bar NotificationsSBMScroll bar controlScroll Bar MessagesSMCShell menuShell Messages and NotificationsSTM and STNStatic controlStatic Control Messages and Static Control NotificationsTB and TBNToolbarToolbar Control Messages and Toolbar Control NotificationsTBM and TRBNTrackbar controlTrackbar Control Messages and Trackbar Control NotificationsTCM and TCNTab controlTab Control Messages and Tab Control NotificationsTDM and TDNTask dialogTask Dialog Messages and Task Dialog NotificationsTTM and TTNTooltip controlTooltip Control Messages and Tooltip Control NotificationsTVM and TVNTree-view controlTree View Messages and Tree View NotificationsUDM and UDNUp-down controlUp-Down Messages and Up-Down NotificationsWMGeneral

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




原创粉丝点击