PRB: SelectClipRgn() Cannot Grow Clip Region in WM_PAINT

Last reviewed: July 2, 1997
Article ID: Q118472
3.10 4.00 | 3.50 3.51
WINDOWS   | WINDOWS NT
kbgraphic kbprb docerr

The information in this article applies to:

  • Microsoft Windows Software Development Kit (SDK) for Windows version 3.1
  • Microsoft Win32 Application Programming Interface (API) included with:

        - Microsoft Windows NT versions 3.5 and 3.51
        - Microsoft Windows 95 version 4.0
    

SYMPTOMS

Setting a smaller clipping region in WM_PAINT by using SelectClipRgn() works fine; however, setting a larger clipping region seems to have no effect. GetClipBox() can be used to verify this after calling SelectClipRgn().

CAUSE

When you call SelectClipRgn() within a BeginPaint()/EndPaint() block in an application's WM_PAINT case, the maximum size to which you can set your clipping region is the size of the update region of your paint structure. This is because the resulting clip region is the intersection of the update region and the region specified in the call to SelectClipRgn(). In other words, you can use SelectClipRgn() to shrink your update region, but not to grow it. This behavior is by design.

RESOLUTION

Invalidate the clipping region area you want before calling BeginPaint(). For example:

case WM_PAINT:

   InvalidateRect(hWnd, ....); // Invalidate the size you'll want
                               // for the clip region.
   BeginPaint()
   SelectClipRgn();
   ... paint away ...
   EndPaint();
   break;

Something similar could be done in the Microsoft Foundation Classes (MFC), such as:

void CMyView::OnPaint()
{
   InvalidateRect(...); // Invalidate the size you'll want.
   CPaintDC dc(this);   // CPaintDC wraps BeginPaint()/EndPaint().
   // Do drawing here...
}

MORE INFORMATION

This is addressed in the documentation for the Windows NT SDK version 3.1 [Section 20.1.5, "Window Regions" in Chapter 20, "Painting and Drawing" in the "Microsoft Win32 Programmer's Reference, Volume 1" or in the Win32 API Reference online help (search on "Window Regions")] which states:

   In addition to the update region, every window has a visible region that
   defines the window portion visible to the user. The system changes the
   visible region for the window whenever the window changes size or
   whenever another window is moved such that it obscures or exposes a
   portion of the window. Applications cannot change the visible region
   directly, but Windows automatically uses the visible region to create
   the clipping region for any display DC retrieved for the window.

   The clipping region determines where the system permits drawing. When
   the application retrieves a display DC using the BeginPaint, GetDC, or
   GetDCEx function, the system sets the clipping region for the DC to the
   intersection of the visible region and the update region. Applications
   can change the clipping region by using functions such as SelectClipPath
   and SelectClipRgn, to further limit drawing to a particular portion of
   the update area.


Additional reference words: 3.10 3.50 4.00 SelectClipRegion big small large
KBCategory: kbgraphic kbprb
KBSubcategory: GdiMisc
Technology : kbMfc


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: July 2, 1997
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.