描述:
开发平台:Visual Studio 6.0/Visual Studio 2008
项目类型:MFC ActiveX
部分说明:已添加代码将ActiveX标记为安全脚本
参考文章:
COM组件开发实践(八)---多线程ActiveX控件和自动调整ActiveX控件大小(下)
http://www.cnblogs.com/phinecos/archive/2008/12/29/1364791.html
问题描述:
在重载的WindowProc里面拦截不到自定义的消息
在函数里面直接操作可以成功
代码如下:
#define WM_ONMSG WM_APP + 101
LRESULT MyActiveXCtrl::WindowProc(UINT message, WPARAM wParam, LPARAM lParam)
{
switch(message)
{
case WM_ONMSG:
{
AfxMessageBox("拦截到了消息");//此处没有执行
return 0;
}
}
return COleControl::WindowProc(message, wParam, lParam);
}
猜想:
我在公司的电脑中使用同样的方法却能成功拦截,由于我调整了IE的安全设置,会不会对此
造成影响?
解决方案1:
MFC做的ActiveX应该是有窗口的,直接往这个窗口发送消息即可,不要向容器窗口发消息,容器窗口只把鼠标和键盘消息交给无窗口控件处理。
解决方案2:ActiveX自己没有消息循坏,只能看容器什么时候把消息转给ActiveX。一般容器只把鼠标键盘消息转给当前激活的ActiveX。
解决方案3: The Message Map
To enable us to process window messages in a CWindowImpl-derived class, ATL inherits from the abstract base class CMessageMap. CMessageMap declares one pure virtual function, ProcessWindowMessage. The entire class is shown here:
class ATL_NO_VTABLE CMessageMap
{
public:
virtual BOOL ProcessWindowMessage(HWND hWnd, UINT uMsg,
WPARAM wParam, LPARAM lParam,
LRESULT& lResult, DWORD dwMsgMapID) = 0;
};
Your CWindowImpl-derived class must implement the ProcessWindowMessage function, which is called from the WindowProc function in the CWindowImpl base class CWindowImplBaseT. If ProcessWindowMessage returns TRUE, the message has been handled by your derived class and WindowProc shouldn't continue with default message processing. A FALSE return value allows default processing.
BEGIN_MSG_MAP(CMainFrame)
MESSAGE_HANDLER(WM_DESTROY, OnDestroy)
END_MSG_MAP()
Message handlers are processed in order from top to bottom until something handles the message or processing falls through, which results in default processing. The bHandled parameter is set to TRUE by default before the handler function is called. You can manually set it to FALSE (as OnDestroy does) to allow default processing after the handler function returns and ProcessWindowMessage exits.
ATL has a large selection of message-handler macros to choose from. The basic types are MESSAGE_HANDLER, NOTIFY_HANDLER, and COMMAND_HANDLER for normal window messages, WM_NOTIFY messages, and WM_COMMAND messages. Ranges of messages are handled using the corresponding macros MESSAGE_RANGE_HANDLER, NOTIFY_RANGE_HANDLER, and COMMAND_RANGE_HANDLER. The easiest way to add handlers to a message map is to right-click on the class in ClassView and choose Add Windows Message Handler &nb