views:

930

answers:

1

Hi,

I have a composite control with a declaration like this:

         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);

I get events like OnMouseMove, OnLButtonDown/Up/DblClk, but I don't get events like KeyUp, KeyDown or MouseWheel.

Everything seems to be defined correctly. I've moved

      CHAIN_MSG_MAP(CComCompositeControl< CFooCtrl >)
      DEFAULT_REFLECTION_HANDLER()

To the end of the Message Map and no difference. I find that when I remove the Reflection_handler() I don't get crashes on KeyDown, but I suspect those are from my Python program that's driving the control.

The only thing I can assume is that the chained msg map is eating these events, but there is no parent control that should be interested in them.

Anyone have any ideas why I get some messages but not others? Any ideas for regaining those messages?

A: 

I believe your code is using ATL and not MFC.

Keyboard handling on composite controls happens through IOleInPlaceActiveObject. The base implementation in ATL will call your PreTranslateMessage on your class (if implemented) where you can get a crack at the message before it goes into TranslateMessage.

The ATL composite control is a control container (it's a child dialog that can host other activex controls). For more information, see the "Keyboard Handling" section in http://www.microsoft.com/msj/1299/containment/containment.aspx

m-sharp