开发基于MFC的ActiveX控件的时候的一些消息处理

在开发基于MFC的ActiveX控件时,由于控件自身没有消息循环,导致某些消息无法正常接收。这个问题可以通过在消息回调中调用PreTranslateMessage()函数来处理对话框和加速键消息,以及特殊按键。微软官方提供了KB文章来解决这个问题,如KB168777和KB187988。在ActiveX控件内部,如果包含其他MFC类子控件,需在PreTranslateMessage后调用COleControl::PreTranslateMessage(pMsg),以避免消息被容器忽略。
摘要由CSDN通过智能技术生成

MFC有PreTranslageMessage() 可以处理一些基于MFC的消息处理。

可是有时候如果你开发一个基于MFC的ActiveX作为容器,内部实现是Win32 或者其他框架会发现,好多消息都不能正常收到。

除非把你现有的内部的控件基于各种MFC的基类实现(会重载各种MFC的PreTranslateMessage)才能收到各种消息。

根本原因是基于MFC的ActiveX控件没有自己的消息循环,要基于使用ActiveX的容器来处理消息。这样有时候会忽略掉一些我们需要的消息。

微软官方有出过KB来解决问题,这里贴出了备忘一下。

PRB: MFC ActiveX Control in IE Doesn't Detect Keystrokes

https://support.microsoft.com/en-us/kb/168777


The TAB key, arrow keys, and accelerator keys do not work as expected when an ActiveX control is the parent window of a modeless dialog box or of a propertysheet window

https://support.microsoft.com/en-us/kb/187988


SYMPTOMS
Accelerator keys, such as ARROW keys, are first received by the message pump of the ActiveX control's container. Even if the control has the focus, it does not receive messages for keystrokes that have special meaning to control containers, such as ARROW and TAB keys. MFC ActiveX controls have a chance to intercept these messages by overriding their PreTranslateMessage function. 

However, PreTranslateMessage is not always called for an MFC ActiveX control.
CAUSE
PreTranslateMessage in an MFC ActiveX control is called by the TranslateAccelerator method of the IOleInPlaceActiveObject interface of the control. Internet Explorer only calls this method for the control that is currently UI-Active. Only one control can be UI-Active at a time. 

Internet Explorer does not automatically UI-Activate any controls when a page is first loaded. Internet Explorer waits until the user tabs t
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值