Microsoft KB Archive/280801

= INFO: Avoid WS_CLIPCHILDREN and ActiveX Control Painting Problems =

Article ID: 280801

Article Last Modified on 10/24/2003

-

APPLIES TO


 * Microsoft ActiveX Template Library 3.0
 * Microsoft Foundation Class Library 4.2

-



This article was previously published under Q280801



SUMMARY
An in-place container must use the WS_CLIPCHILDREN window style for the window that it uses as the parent for an ActiveX Control in order to avoid repainting problems.



MORE INFORMATION
The WS_CLIPCHILDREN style excludes the area occupied by child windows when you draw within the parent window:

http://msdn.microsoft.com/library/psdk/winui/windows_2v90.htm

To avoid repainting over an in-place object's output, the style must be applied to the parent window of the object.

For Microsoft Foundation Classes (MFC) OLE (and Active) Document Containers, the framework implicitly sets this style during in-place activation. However, the style must be explicitly added for other situations in which in-place activation is involved. From the point of view of MFC and Active Template Library (ATL) containers, this is typically when hosting ActiveX controls.

Approaches for MFC Containers
  For MFC CWnd (including CView and CDialog) derived classes that host ActiveX controls, the style can be added by adding an override for the virtual PreCreateWindow function and modifying cs.style. For instance, here's how PreCreateWindow would look in a CView-derived class: BOOL CMyView::PreCreateWindow(CREATESTRUCT& cs) {   // Add the WS_CLIPCHILDREN style to avoid repaint problems: cs.style |= WS_CLIPCHILDREN;

return CView::PreCreateWindow(cs); }                    Another way of adding the WS_CLIPCHILDREN style to a CDialog-derived class is through the Dialog editor, Styles tab, by selecting Clip children.

Approaches for ATL Containers
 For ATL-based container windows derived from CWindowImpl, the WS_CLIPCHILDREN style can be specified through Window Traits. For CWindowImpl-derived classes, the default traits are specified in the CControlWinTraits class, which does include the WS_CLIPCHILDREN style by default. For more information on ATL windowing classes and window traits, see the following Microsoft Web page:

ATL 3.0 Window Classes: An Introduction (SubTopic: Using Window Traits to Specify Styles)

http://msdn.microsoft.com/library/techart/atlwindow.htm#atlwindow_topic13

 For ATL-based dialog boxes, the base class CAxDialogImpl does not derive from CWindowImpl, and hence does not have these traits. Custom CWinTraits cannot be specified for CAxDialogImpl either. The WS_CLIPCHILDREN style can be added through the Dialog editor, Styles tab, by selecting Clip children.

Approaches Common to MFC and ATL

 * If the windows are being created explicitly through either CWnd::Create (for MFC) or CWindow::Create (for ATL), the WS_CLIPCHILDREN style can be specified through the dwStyle parameter.
 * A way of dynamically modifying the style, once the window has been created and has a valid HWND, is through CWnd::ModifyStyle for MFC windows, or CWindow::ModifyStyle for ATL windows.

