是控件还是父窗口呢?
谢谢

解决方案 »

  1.   

    Message Reflection for Windows Controls:当一个 WM_NOTIFY 消息被发送后,控件就得到了第一次的机会来处理它。如果任何其他的被反射消息被发送,父窗口会有第一个机会来处理之,而控件将能接收被反射的消息。为了达到这样的目的,在控件类消息映射中需要一个处理函数和一个合适的入口。 
    When a WM_NOTIFY message is sent, the control is offered the first chance to handle it. If any other reflected message is sent, the parent window has the first chance to handle it and the control will receive the reflected message. To do so, it will need a handler function and an appropriate entry in the control's class message map. ————————————————————————————
    那这段话是什么意思那,“当一个 WM_NOTIFY 消息被发送后,控件就得到了第一次的机会来处理它”
      

  2.   

    Message Reflection for Windows Controls:在 MFC 4.0 中,旧的消息机制仍然在工作 —— 父窗口可以处理通知消息。另外同时,MFC 4.0 通过提供了一种称为“消息反射”的新机制使的重复使用变的容易多了。消息反射允许这些通知消息既能够被控件自身处理,也能够被其父窗口来处理。在上述控件背景颜色例子中,现在你就既可以通过被发射过来的WM_CTLCOLOR消息自己写一个能够处理背景颜色的控件类,所有的一切就不再依靠其父窗口了。(请注意,既然这个消息反射只能在 MFC 实现,不是 Windows 系统的。所以父窗口必须派生于CWnd,这样消息反射才能正常工作)。 
    In MFC 4.0, the old mechanism still works—parent windows can handle notification messages. In addition, however, MFC 4.0 facilitates reuse by providing a feature called “message reflection” that allows these notification messages to be handled in either the child control window or the parent window, or in both. In the control background color example, you can now write a control class that sets its own background color by handling the reflected WM_CTLCOLOR message—all without relying on the parent. (Note that since message reflection is implemented by MFC, not by Windows, the parent window class must be derived from CWnd for message reflection to work.) MFC 旧版本通过为一些消息提供虚函数的机制部分实现了类似的功能,最典型的就是自绘制的列表框(WM_DRAWITEM等等)。然后新的消息反射机制更通用和持久。 
    Older versions of MFC did something similar to message reflection by providing virtual functions for a few messages, such as messages for owner-drawn list boxes (WM_DRAWITEM, and so on). The new message reflection mechanism is generalized and consistent. 消息消息机制向后与MFC4.0版本前的代码相兼容。 
    Message reflection is backward compatible with code written for versions of MFC previous to 4.0. 
    如果你在控件的父窗口类中为一个或一定范围特定的消息提供了一个处理函数,对于同样的消息,如果在您的处理中您并没有调用其基类的处理函数它就会覆盖掉被反射的消息处理。例如,如果你在一个对话框类中试图处理 WM_CTLCOLOR,您的处理将覆盖掉任何被反射的消息处理函数。 
    If you have supplied a handler for a specific message, or for a range of messages, in your parent window's class, it will override reflected message handlers for the same message provided you don't call the base class handler function in your own handler. For example, if you handle WM_CTLCOLOR in your dialog box class, your handling will override any reflected message handlers. 如果你在父窗口中为一个或一系列一定范围的特定的 WM_NOTIFY 消息提供一个处理函数,您的处理函数只有当这些发送消息的子控件通过ON_NOTIFY_REFLECT() 宏就不会有一个被反射消息处理了。如果该处理返回 FALSE(原文:TRUE),消息就也会给父窗口来处理,而如果它返回的是一个TRUE(原文:FALSE)值,就不会让父窗口来处理该消息。请注意:被反射的消息是在通知消息之前被处理。 If, in your parent window class, you supply a handler for a specific WM_NOTIFY message or a range of WM_NOTIFY messages, your handler will be called only if the child control sending those messages does not have a reflected message handler through ON_NOTIFY_REFLECT(). If you use ON_NOTIFY_REFLECT_EX() in your message map, your message handler may or may not allow the parent window to handle the message. If the handler returns FALSE(TRUE?), the message will be handled by the parent as well, while a call that returns TRUE(FALSE?) does not allow the parent to handle it. Note that the reflected message is handled before the notification message. 当一个 WM_NOTIFY 消息被发送后,控件就得到了第一次的机会来处理它。如果任何其他的被反射消息被发送,父窗口会有第一个机会来处理之,而控件将能接收被反射的消息。为了达到这样的目的,在控件类消息映射中需要一个处理函数和一个合适的入口。 
    When a WM_NOTIFY message is sent, the control is offered the first chance to handle it. If any other reflected message is sent, the parent window has the first chance to handle it and the control will receive the reflected message. To do so, it will need a handler function and an appropriate entry in the control's class message map. 
      

  3.   

    父窗口响应完消息后,再sendmessage给控件,由控件处理函数处理
      

  4.   

    消息路游器:
    CCmdTarget::OnCmdMsg
    This method is called by the framework to route and dispatch command messages and to handle the update of command user-interface objects. virtual BOOL OnCmdMsg(
    UINT nID,
    int nCode,
    void* pExtra,
    AFX_CMDHANDLERINFO* pHandlerInfo ); 
      

  5.   

    反射,反射,故名思义就是
          反射墙
    子 ---> |
            |   父
    子 <--- |就单单你问的问题而言,是没有答案的,因为你只问谁先获得处理权,
    而没有问,谁先获得“什么”的处理权。A. 就一个Button而言,用户在它上面点击一下鼠标,最开始肯定是Button
    自己收到消息,不过Button收到的不是BN_CLICKED这种消息,
    它收到的是形如WM_LBUTTONDOWN,WM_LBUTTONUP这种消息B. Button收到这些消息之后,认为自己被点击了,
    就给父窗口发BN_CLICKED消息,注意BN_CLICKED是Button自己发的,自己定义的。C. 然后父窗口把BN_CLICKED"反射"给Button自己处理所以,如果Subclass一个Button和一个父窗口,你第一次得到BN_CLICKED是在父窗口我说完了,如果有不对的,欢迎指正。
      

  6.   

    其实是控件本身先得到,通过返回值可以决定让不让父窗口得到消息.不过有些消息函数返回void,这种情况下,大部分控件处理后的消息父窗口就收不到了.
    你可以试一下.