0

我有一个复合控件,其声明如下:

         class ATL_NO_VTABLE CFooCtrl : 

               public CComObjectRootEx<CComSingleThreadModel>,
               public IDispatchImpl<CFooCtrl, &IID_IFooCtrl, &LIBID_FooLib>,
               public CComCompositeControl<CFooCtrl>,
               public IPersistStreamInitImpl<CFooCtrl>,
               public IOleControlImpl<CFooCtrl>,
               public IOleObjectImpl<CFooCtrl>,
               public IOleInPlaceActiveObjectImpl<CFooCtrl>,
               public IViewObjectExImpl<CFooCtrl>,
               public IOleInPlaceObjectWindowlessImpl<CFooCtrl>,
               public IConnectionPointContainerImpl<CFooCtrl>,
               public IPersistStorageImpl<CFooCtrl>,
               public ISpecifyPropertyPagesImpl<CFooCtrl>,
               public IQuickActivateImpl<CFooCtrl>,
               public IDataObjectImpl<CFooCtrl>,
               public IProvideClassInfo2Impl<&CLSID_FooCtrl, &DIID__IFooCtrlEvents, &LIBID_FooCtrlLib>,
               public IPropertyNotifySinkCP<CFooCtrl>,
               public CComCoClass<CFooCtrl, &CLSID_FooCtrl>,
               public CProxy_IFooCtrlEvents<CFooCtrl>,
            {

        ...

       BEGIN_MSG_MAP(CFooCtrl)
          CHAIN_MSG_MAP(CComCompositeControl< CFooCtrl >)
          DEFAULT_REFLECTION_HANDLER()
          MESSAGE_HANDLER(WM_TIMER, OnTimer)
          MESSAGE_HANDLER(WM_ERASEBKGND, OnEraseBkgnd)
          MESSAGE_HANDLER(WM_KEYDOWN, OnKeyDown)
          MESSAGE_HANDLER(WM_KEYUP, OnKeyUp)
          MESSAGE_HANDLER(WM_LBUTTONDBLCLK, OnLButtonDblClk)
          MESSAGE_HANDLER(WM_LBUTTONDOWN, OnLButtonDown)
          MESSAGE_HANDLER(WM_LBUTTONUP, OnLButtonUP)
          MESSAGE_HANDLER(WM_PAINT, OnPaint)
          MESSAGE_HANDLER(WM_RBUTTONDBLCLK, OnRButtonDblClk)
          MESSAGE_HANDLER(WM_RBUTTONDOWN, OnRButtonDown)
          MESSAGE_HANDLER(WM_RBUTTONUP, OnRButtonUp)
          MESSAGE_HANDLER(WM_MOUSEMOVE, OnMouseMove)
          MESSAGE_HANDLER(WM_MOUSEWHEEL, OnMouseWheel)
          MESSAGE_HANDLER(WM_SIZE, OnSize)
          MESSAGE_HANDLER(WM_INITDIALOG, OnInitDialog)
          MESSAGE_HANDLER(WM_DESTROY, OnDestroy)
      END_MSG_MAP()

   LRESULT OnTimer(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
   LRESULT OnEraseBkgnd(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
   LRESULT OnKeyDown(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
   LRESULT OnKeyUp(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
   LRESULT OnLButtonDblClk(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
   LRESULT OnLButtonDown(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
   LRESULT OnLButtonUP(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
   LRESULT OnPaint(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled); 
   LRESULT OnRButtonDblClk(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
   LRESULT OnRButtonDown(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
   LRESULT OnRButtonUp(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
   LRESULT OnMouseMove(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
   LRESULT OnMouseWheel(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
   LRESULT OnSize(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
   LRESULT OnInitDialog(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
   LRESULT OnDestroy(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);

我得到像 OnMouseMove、OnLButtonDown/Up/DblClk 这样的事件,但我没有得到像 KeyUp、KeyDown 或 MouseWheel 这样的事件。

一切似乎都被正确定义了。我已经搬家了

      CHAIN_MSG_MAP(CComCompositeControl< CFooCtrl >)
      DEFAULT_REFLECTION_HANDLER()

到最后的Message Map 并没有什么区别。我发现当我删除 Reflection_handler() 时,我不会在 KeyDown 上发生崩溃,但我怀疑这些来自驱动控件的 Python 程序。

我唯一可以假设的是链接的 msg 映射正在吃这些事件,但是没有应该对它们感兴趣的父控件。

任何人都知道为什么我收到一些消息而不是其他消息?有什么重新获得这些信息的想法吗?

4

1 回答 1

1

我相信您的代码使用的是 ATL 而不是 MFC。

复合控件上的键盘处理通过 IOleInPlaceActiveObject 进行。ATL 中的基本实现将在您的类上调用您的 PreTranslateMessage(如果已实现),您可以在该消息进入 TranslateMessage 之前对其进行破解。

ATL 复合控件是一个控件容器(它是一个可以承载其他 activex 控件的子对话框)。有关详细信息,请参阅http://www.microsoft.com/msj/1299/containment/containment.aspx中的“键盘处理”部分

于 2009-02-21T06:26:15.377 回答