Message Categories MFC消息类别

转载自:https://docs.microsoft.com/zh-cn/cpp/mfc/message-categories?view=vs-2017

What kinds of messages do you write handlers for There are three main categories:

  1. Windows messages

    This includes primarily those messages beginning with the WM_ prefix, except for WM_COMMAND. Windows messages are handled by windows and views. These messages often have parameters that are used in determining how to handle the message.

  2. Control notifications

    This includes WM_COMMAND notification messages from controls and other child windows to their parent windows. For example, an edit control sends its parent a WM_COMMAND message containing the EN_CHANGE control-notification code when the user has taken an action that may have altered text in the edit control. The window's handler for the message responds to the notification message in some appropriate way, such as retrieving the text in the control.

    The framework routes control-notification messages like other WM_ messages. One exception, however, is the BN_CLICKED control-notification message sent by buttons when the user clicks them. This message is treated specially as a command message and routed like other commands.

  3. Command messages

    This includes WM_COMMAND notification messages from user-interface objects: menus, toolbar buttons, and accelerator keys. The framework processes commands differently from other messages, and they can be handled by more kinds of objects, as explained in Command Targets.

Windows Messages and Control-Notification Messages

Messages in categories 1 and 2 — Windows messages and control notifications — are handled by windows: objects of classes derived from class CWnd. This includes CFrameWndCMDIFrameWndCMDIChildWndCViewCDialog, and your own classes derived from these base classes. Such objects encapsulate an HWND, a handle to a Windows window.

Command Messages

Messages in category 3 — commands — can be handled by a wider variety of objects: documents, document templates, and the application object itself in addition to windows and views. When a command directly affects some particular object, it makes sense to have that object handle the command. For example, the Open command on the File menu is logically associated with the application: the application opens a specified document upon receiving the command. So the handler for the Open command is a member function of the application class. For more about commands and how they are routed to objects, see How the Framework Calls a Handler.

See Also

Messages and Commands in the Framework

哪些类型的消息编写处理程序的有三个主要类别:

  1. Windows 消息

    这包括主要使用开头的消息WM_ 前缀,但 WM_COMMAND 除外。 Windows 消息由窗口和视图处理。 这些消息通常具有用于确定如何处理消息的参数。

  2. 控件通知

    这包括来自控件和其他子窗口到其父窗口的 WM_COMMAND 通知消息。 例如,一个编辑控件向其父级发送 WM_COMMAND 消息来包含 EN_CHANGE 控件通知代码,当用户已经采取可能已更改文本编辑控件中的操作。 窗口的消息处理程序将以某种合适的方式响应通知消息,如检索控件中的文本。

    框架将传送控件通知消息与其他值一样WM_ 消息。 一个例外,但是,是当用户单击这些按钮发送的 BN_CLICKED 控件通知消息。 此消息将专门作为命令消息处理,并像传送其他命令一样传送。

  3. 命令消息

    这包括来自用户界面对象的 WM_COMMAND 通知消息: 菜单、 工具栏按钮和快捷键。 框架处理命令以不同的方式从其他消息,并且它们可以处理更多类型的对象,如中所述命令目标

Windows 消息和控件通知消息

类别 1 和 2 的消息(Windows 消息和控件通知)由窗口处理:派生自 CWnd 对象。 这包括 CFrameWndCMDIFrameWndCMDIChildWndCViewCDialog,并且您拥有派生自这些基类的类。 此类对象将封装 HWND(Windows 窗口的句柄)。

命令消息

类别 3 的消息(命令)可由更多类型的对象处理:文档、文档模板和应用程序对象本身以及窗口和视图。 当命令直接影响了某个特定对象时,让该对象处理命令很有意义。 例如,“文件”菜单上的“打开”命令与应用程序逻辑关联:应用程序在收到命令时打开指定的文档。 因此,“打开”命令的处理程序是应用程序类的成员函数。 有关命令和如何传送到对象的详细信息,请参阅框架如何调用处理程序

请参阅

框架中的消息和命令

猜你喜欢

转载自blog.csdn.net/daizhiyan1/article/details/85119496
今日推荐