PRB: RoundRect() and Ellipse() Don't Match Same Shaped Regions

Last reviewed: September 29, 1995
Article ID: Q119455
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.1, 3.5, and 3.51
        - Microsoft Windows 95 version 4.0
    

SYMPTOMS

When CreateRoundRectrRgn() is used to create a region with the shape of a rectangle that has rounded corners and RoundRect() is called with the same parameters to draw the same rectangle that has rounded corners, the calculated region does not match the drawn rectangle. The same can be said of the ellipses created by CreateEllipticRgn() and Ellipse().

CAUSE

This behavior is because of the design on Windows. The mismatch between fills and frames is because of the way that the boundaries and fills must be specified in order to get polygons to fit together properly. Windows NT duplicates this behavior for compatibility.

RESOLUTION

Perform the fill first, then draw the frame. Some of the frame pixels will overwrite fill pixels and some will not; however, there will be no gap between the frame and the fill, and the fill will not extend past the frame. Use CreateRoundRectRgn() or CreateEllipticRgn() for the fill and RoundRect() or Ellipse, respectively, for the frame. Use the same parameters for both the region API and the filled-shape API.

NOTE: If you use a NULL pen when drawing the filled shape, the pixels will match those drawn by creating a region through the corresponding region API and then calling FillRgn() with the same parameters. It draws the frame with the pen from the filled-shape API that causes the discrepancy.


Additional reference words: 3.10 3.50 4.00 95
KBCategory: kbgraphic kbprb
KBSubcategory: GdiDrw


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: September 29, 1995
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.