mfc控件在ie里面显示不正确的解决方法

FIX: MFC ActiveX controls paint incorrectly when scrolling the HTML page

<script type="text/javascript">function loadTOCNode(){}</script>
Article ID:233391
Last Review:February 1, 2005
Revision:4.0
This article was previously published under Q233391

SYMPTOMS

<script type="text/javascript">loadTOCNode(1, 'symptoms');</script>
An MFC-based windowed ActiveX control on an HTML page paints incorrectly when you scroll the HTML page in the browser. The control appears distorted, showing successively larger bands at the bottom or top as it moves off the visible portion of the HTML page.

In versions of Microsoft Internet Explorer later than version 5, the control may paint correctly. However, child windows on the control still experience the banding effects while scrolling.

CAUSE

<script type="text/javascript">loadTOCNode(1, 'cause');</script>
A performance enhancement was added to Internet Explorer 5 to improve the rendering of windowed ActiveX controls by manipulating the available window and clip regions for the control's window. When this code operates on MFC controls, portions of the control's window outside the clip region are invalidated. Because the control's OnDraw cannot draw outside the clip region, these areas show stripes of the background color.

RESOLUTION

<script type="text/javascript">loadTOCNode(1, 'resolution');</script>
To resolve this problem, upgrade clients to version 5.01 or later of Internet Explorer.

Note A change was made in Internet Explorer to fix the problem that is described in the following Microsoft Knowledge Base (KB) article:
307978 (http://support.microsoft.com/kb/307978/) FIX: MFC controls in overlapped IFRAMEs receive unnecessary WM_PAINT messages
However, this change reintroduced the problem in Internet Explorer 6 Service Pack 1.

WORKAROUND

<script type="text/javascript">loadTOCNode(1, 'workaround');</script>
To work around this problem, use one of the following methods:
Repaint the control when the cnscroll event fires, as in the following sample code.
<SCRIPT>
function workaround()
{
// "a" is the name of the control.
window.document.all.item("a").style.display = "none"
window.document.all.item("a").style.display = ""
}
</SCRIPT>
<BODY onscroll="workaround();">
If the control class is derived from the COleControl class, it implements a virtual method that is named OnSetObjectRects. You can override this method, as in the following sample code.
BOOL CmfcaxCtrl::OnSetObjectRects(LPCRECT lpRectPos, LPCRECT lpRectClip) 
{ return TRUE; 
}
Use ATL instead of MFC to develop the ActiveX control.
Unfortunately, MFC controls that contain child windows will still have painting problems in Internet Explorer. You can resolve these problems by forcing a redraw on all the child windows during handling of the OnPaint message. To do this, you must add a message map entry for WM_PAINT to the COleControl-derived class. In the OnPaint handler, use code that is similar to the following.
// NUMBER_OF_CHILDREN is predefined as the number of child windows
// that are hosted on this control

// m_Children is a member variable of the CWindowedCtrl class that
// stores an array of CWnd references to the child windows on the control.

void CWindowedCtrl::OnPaint()
{
   CPaintDC dc(this); // device context for painting<BR/>

   for(int i = 0 ; i < NUMBER_OF_CHILDREN ; i++)
   {
      m_Children[i].RedrawWindow(NULL,NULL,RDW_INVALIDATE | RDW_FRAME);   
   }

   COleControl::OnPaint(&dc);
}

STATUS

<script type="text/javascript">loadTOCNode(1, 'status');</script>
Microsoft has confirmed that this is a bug in the Microsoft products that are listed in the "Applies to" section. This problem was corrected in Internet Explorer 5.01. This problem was reintroduced in Internet Explorer 6 Service Pack 1.

MORE INFORMATION

<script type="text/javascript">loadTOCNode(1, 'moreinformation');</script>
This bug does not cause any painting problems for windowless controls.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值