我有一个复合控件,声明如下:
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()
到消息映射的结尾并没有区别。我发现当我删除Reflection_handler()时,我不会在KeyDown上崩溃,但我怀疑这些是来自我的Python程序,它正在推动控制。
我唯一可以假设的是链接的msg地图正在吃这些事件,但是没有父控制应该对它们感兴趣。
任何人都有任何想法,为什么我得到一些消息而不是其他消息?重新获得这些消息的任何想法?
答案 0 :(得分:1)
我相信你的代码使用的是ATL而不是MFC。
复合控件上的键盘处理通过IOleInPlaceActiveObject发生。 ATL中的基本实现将在您的类上调用您的PreTranslateMessage(如果已实现),您可以在它进入TranslateMessage之前获取对该消息的破解。
ATL复合控件是一个控件容器(它是一个可以托管其他activex控件的子对话框)。有关详细信息,请参阅http://www.microsoft.com/msj/1299/containment/containment.aspx
中的“键盘处理”部分