Don't receive all Windows messages in MFC ActiveX Composite Control
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 correctly defined. I moved
CHAIN_MSG_MAP(CComCompositeControl< CFooCtrl >)
DEFAULT_REFLECTION_HANDLER()
By the end of the Message Map and no difference. I found that when I remove Reflection_handler (), I don't get any crashes in KeyDown, but I suspect it is from my Python program that is manipulating the control.
The only thing I can guess is that the beveled msg card is eating these events, but there is no parent control that should be interested in them.
Anyone have any ideas why I am getting messages but not others? Any ideas for recovering these messages?
source to share
I believe your code is using ATL and not MFC.
Keyboard handling on a composite control occurs through the IOleInPlaceActiveObject. The base implementation in ATL will call your PreTranslateMessage on your class (if implemented) where you can get a crack in the message before it goes to TranslateMessage.
An ATL composite element is a control container (it is a child dialog that can contain other activex controls). For more information see the Keyboard Handling section at http://www.microsoft.com/msj/1299/containment/containment.aspx
source to share