Message maps

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 CFrameWnd , CMDIFrameWnd , CMDIChildWnd , CView , CDialog , 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 .

 

 

所以在CWinApp里面也可以处理第3种方式包括菜单响应。这些都是在CMainFrame里面用OnCmdMsg()这个函数,把所有菜单响应都转发给CWinApp和CView。

如果自己建了个CWnd的子类,想要处理父窗口的消息,就必须在父窗口重载OnCmdMsg()这个函数,并把消息转发给自定义子类,交由子类先处理,如果返回true说明子类已经处理了,一般可以直接return不再由父窗口处理了。

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值