在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的安全设置,会不会对此

造成影响?
...全文
181 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中响应这个自定义消息

结果发现没反应。
【更新至2025年】2001-2025年上市公司数字化转型年报词频统计(吴非、赵宸宇、甄红线)(300+年报词频统计) 1、时间:2001-2025年 2、来源:上市公司年报 3、参考文献:企业数字化转型与资本市场表现——来自股票流动性的经验证据(吴非) 数字化转型如何影响企业全要素生产率(赵宸宇) 知识产权行政保护与企业数字化转型(甄红线) 4、方法说明:(1)参考吴非老师的做法,对人工智能技术、大数据技术、云计算技术、区块链技术、数字技术运用五个维度76个数字化相关词频进行统计 (2)参考赵宸宇老师的做法,对数字技术应用、互联网商业模式、智能制造、现代信息系统四个维度99个数字化相关词频进行统计 (3)参考甄红线老师的做法,对技术分类、组织赋能、数字化应用等类别下139个数字化相关词频进行统计 5、指标:年份、股票代码、公司简称、行业名称、行业代码、全文-文本总长度、仅英文-文本总长度、人工智能技术-吴、大数据技术-吴、云计算技术-吴、区块链技术-吴、数字技术运用-吴、数字技术应用-赵、互联网商业模式-赵、智能制造-赵、现代信息系统-赵、技术分类-人工智能技术-甄、技术分类-区块链技术-甄、技术分类-云计算技术-甄、技术分类-大数据技术-甄、组织赋能-人工智能技术-甄、组织赋能-云计算技术-甄、组织赋能-大数据技术-甄、组织赋能-广义数字技术-甄、数字化应用-技术创新-甄、数字化应用-流程创新-甄、数字化应用-业务创新-甄、人工智能、商业智能、图像理解、投资决策辅助系统、智能数据分析、智能机器人、机器学习、深度学习、语义搜索、生物识别技术、人脸识别、语音识别、身份验证、自动驾驶、自然语言处理、大数据、数据挖掘、文本挖掘、数据可视化、异构数据、征信、增强现实、混合现实、虚拟现实、云计算、流计算、图计算、内存计算、多方安全计算、类脑计算、绿色计算、认知计算等300+词频

684

社区成员

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

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