在ActiveX项目中的重载WindowPro函数里面居然截取不到自定义的消息

songsu 2009-03-14 11:44:19
开发平台: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的安全设置,会不会对此

造成影响?
...全文
183 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
蒋晟 2009-03-14
  • 打赏
  • 举报
回复
ActiveX自己没有消息循坏,只能看容器什么时候把消息转给ActiveX。一般容器只把鼠标键盘消息转给当前激活的ActiveX。
oyljerry 2009-03-14
  • 打赏
  • 举报
回复
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 from the context menu. Microsoft Visual C++ then inserts the correct macro based on the message you choose to handle. You can't use ClassWizard to add handlers to ATL message maps. Here's a summary of the available message-handler macros:


MESSAGE_HANDLER Maps a window message to a handler function


MESSAGE_RANGE_HANDLER Maps a contiguous range of window messages to a handler function


COMMAND_HANDLER Maps a WM_COMMAND message to a handler function based on the notification code and the identifier of the menu item, control, or accelerator


COMMAND_ID_HANDLER Maps a WM_COMMAND message to a handler function based on the identifier of the menu item, control, or accelerator


COMMAND_CODE_HANDLER Maps a WM_COMMAND message to a handler function based on the notification code


COMMAND_RANGE_HANDLER Maps a contiguous range of WM_COMMAND messages to a handler function based on the identifier of the menu item, control, or accelerator


NOTIFY_HANDLER Maps a WM_NOTIFY message to a handler function based on the notification code and the control identifier


NOTIFY_ID_HANDLER Maps a WM_NOTIFY message to a handler function based on the control identifier


NOTIFY_CODE_HANDLER Maps a WM_NOTIFY message to a handler function based on the notification code


NOTIFY_RANGE_HANDLER Maps a contiguous range of WM_NOTIFY messages to a handler function based on the control identifier
songsu 2009-03-14
  • 打赏
  • 举报
回复
谢谢两位高手,问题解决了,不过不是使用的 SendMessage 方式,下午试了一下还是没成功。
这次使用的是列集和散集。
wwwxxb40000 2009-03-14
  • 打赏
  • 举报
回复

头一次见2楼的高手会贴

后悔我来这里太晚了,早两年就好了
jameshooo 2009-03-14
  • 打赏
  • 举报
回复
MFC做的ActiveX应该是有窗口的,直接往这个窗口发送消息即可,不要向容器窗口发消息,容器窗口只把鼠标和键盘消息交给无窗口控件处理。
蒋晟 2009-03-14
  • 打赏
  • 举报
回复
直接往窗口句柄SendMessage
songsu 2009-03-14
  • 打赏
  • 举报
回复
感谢两位高手的回复,控件运行环境是这样的,ActiveX控件在网页中运行,
(1)通过 JavaScript 调用ActiveX的ShowMsg方法
(2)ActiveX的ShowMsg方法创建一个线程TA
(3)线程TA再调用OnMsg方法
(4)OnMsg方法PostMessage(自定义消息)
(5)然后在WindowProc中响应这个自定义消息

结果发现没反应。

684

社区成员

发帖
与我相关
我的任务
社区描述
智能路由器通常具有独立的操作系统,包括OpenWRT、eCos、VxWorks等,可以由用户自行安装各种应用,实现网络和设备的智能化管理。
linuxpython 技术论坛(原bbs)
社区管理员
  • 智能路由器社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧