Microsoft KB Archive/307978

= FIX: MFC Controls in Overlapped IFRAMEs Receive Unnecessary WM_PAINT Messages =

Article ID: 307978

Article Last Modified on 5/11/2006

-

APPLIES TO


 * Microsoft Internet Explorer 5.5
 * Microsoft Internet Explorer (Programming) 6.0

-



This article was previously published under Q307978



SYMPTOMS
When a Microsoft Foundation Classes (MFC) ActiveX control appears in an IFRAME that is partially covered by another IFRAME in the same Hypertext Markup Language (HTML) page, the ActiveX control receives unnecessary WM_PAINT messages. The unnecessary WM_PAINT messages occur when other parts of the HTML page are updated.



CAUSE
MFC ActiveX controls include dual windows: a child window and a parent window. The parent window is used for notification. If the IFRAME that contains an MFC ActiveX control is completely covered in one dimension, the parent window is resized to the size of the control (including the clipped portion that is outside the boundaries of the IFRAME). The parent window returns to the clip area size whenever the page is updated. The resizing generates the extra WM_PAINT messages.



RESOLUTION
To resolve this problem, obtain the latest service pack for Internet Explorer 6. For additional information, click the following article number to view the article in the Microsoft Knowledge Base:

328548 How to Obtain the Latest Internet Explorer 6 Service Pack

To work around this problem, modify the OnSetObjectRects function to ignore the resizing. For example: // Code in the header file: virtual BOOL OnSetObjectRects(LPCRECT lpRectPos, LPCRECT lpRectClip);

// Code in the implementation file:
 * 1) include 
 * 2) include <..\src\afximpl.h>
 * 3) include <..\src\ctlimpl.h>

void MyGetClippingCoordinates(LPCRECT pPosRect, LPCRECT pClipRect,   LPRECT pIntersectRect, LPPOINT pOffsetPoint) {   int clipLeft = 0; int clipTop = 0;

if ((pClipRect == NULL) || IsRectEmpty(pClipRect)) {       CopyRect(pIntersectRect, pPosRect); }   else {       IntersectRect(pIntersectRect, pPosRect, pClipRect); clipLeft = pClipRect->left; clipTop = pClipRect->top; }

pOffsetPoint->x = min(0, pPosRect->left - clipLeft); pOffsetPoint->y = min(0, pPosRect->top - clipTop); }

BOOL CTmpCtrl::OnSetObjectRects(LPCRECT lprcPosRect, LPCRECT lprcClipRect) { // return COleControl::OnSetObjectRects(lprcPosRect, lprcClipRect); ASSERT(lprcPosRect != NULL);

// Remember the position rectangle. m_rcPos = *lprcPosRect;

// Calculate complete rectangle, include the tracker if it is present. CRect rectPos = m_rcPos; if (m_bUIActive && m_pRectTracker != NULL) {       // Save new clipping rectangle (for DestroyTracker). if (lprcClipRect != NULL) m_pRectTracker->m_rectClip = *lprcClipRect;

// Adjust tracker rectangle to new dimensions. CRect rectTmp = rectPos; rectTmp.OffsetRect(-rectTmp.left, -rectTmp.top); m_pRectTracker->m_rect = rectTmp;

// Adjust the &quot;true&quot; rectangle to include handles/hatching. UINT nHandleSize = m_pRectTracker->m_nHandleSize - 1; rectPos.InflateRect(nHandleSize, nHandleSize); }

// Now clip the rectangle as appropriate. CRect rectClip; MyGetClippingCoordinates(rectPos, lprcClipRect, rectClip, &m_ptOffset);

// Move the outer window first, and then move the inner window.

if (!m_bInPlaceSiteWndless) {       CWnd* pWndOuter = GetOuterWindow; //BEGIN CHANGE. if (pWndOuter != NULL) {           static CRect oldClipRect(0, 0, 0, 0); if (oldClipRect != rectClip) ::MoveWindow(pWndOuter->m_hWnd,                   rectClip.left, rectClip.top,                    rectClip.Width, rectClip.Height,                    TRUE); oldClipRect = rectClip; }       //END CHANGE. if (pWndOuter != this) MoveWindow(m_ptOffset.x, m_ptOffset.y,               rectPos.Width, rectPos.Height); }

return TRUE; }



STATUS
Microsoft has confirmed that this is a bug in the Microsoft products that are listed at the beginning of this article. This problem was first corrected in Internet Explorer 6 Service Pack 1.



Steps to Reproduce Behavior
 Create a default MFC ActiveX control.  To modify the OnDraw function, use the following code to display the paint count: void CTmpCtrl::OnDraw(           CDC* pdc, const CRect& rcBounds, const CRect& rcInvalid) {   static int count = 0; // TODO: Replace the following code with your own drawing code. pdc->FillRect(rcBounds, CBrush::FromHandle((HBRUSH)GetStockObject(WHITE_BRUSH))); pdc->Ellipse(rcBounds); CString number; number.Format(&quot;%d&quot;, count++); pdc->TextOut(10, (rcBounds.bottom - rcBounds.top)/2, number); }                    Build the MFC ActiveX control. The control automatically registers.  Create a new HTML file named Simple.htm that contains the following code: You can type text in this text area <iframe src=&quot;mfctest.htm&quot; style=&quot;top: 300; left: 0; position:absolute&quot;> <iframe src=&quot;about:blank&quot; style=&quot;top: 300; left: 200; position: absolute&quot;> </li>  Create another new HTML file named Mfctest.htm that contains the following code: <body style=&quot;margin:0px;&quot;> <object classid=&quot;clsid:xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxx&quot; height = &quot;100%&quot; width = &quot;100%&quot;> NOTE: Use the class ID (CLSID) from the .odl file of the ActiveX control. One of the IFRAMEs for Simple.htm is Mfctest.htm. </li> Double-click Simple.htm, and then type text in the text area. Every time you type, the ActiveX control flickers. Additionally, every time the top frame window is resized, the ActiveX control flickers.</li> To see how the layout affects the problem, modify the top attributes of one of the IFRAMEs to a value other than 300. Make sure that the IFRAME is not completely covered. Refresh or resize the page. Notice that the frame does not flicker.</li></ol>

NOTE: This problem occurs if one of the dimensions (the width or the height) of the IFRAME that contains the MFC ActiveX control is completely covered by the other IFRAME.

<div class="references_section">