Specifying Windows "Bounding Box" Coordinates

Last reviewed: November 2, 1995
Article ID: Q27585
The information in this article applies to:
  • Microsoft Windows Software Development Kit (SDK) for Windows versions 3.1 and 3.0
  • Microsoft Win32 Application Programming Interface (API) included with:

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

SUMMARY

GDI functions, such as Rectangle, Ellipse, RoundRect, Chord, and Pie, have parameters that specify the coordinates of a "bounding box" into which the figure is drawn. Windows draws the figure up to, but not including, the right and bottom coordinates.

MORE INFORMATION

Suppose the following call is made:

   Rectangle(hDC, 1, 1, 5, 3)

Assuming that the device context is using the MM_TEXT mapping mode (in which case logical units map directly to physical pixels), the resulting rectangle will be 4 pixels wide and 2 pixels tall. The following diagram shows which pixels are affected:

            ---0-----1-----2-----3-----4-----5-----6-
            |     |     |     |     |     |     |
            0     |     |     |     |     |     |
            |-----|-----|-----|-----|-----|-----|----
            |     |     |     |     |     |     |
            1     |  X  |  X  |  X  |  X  |     |
            |-----|-----|-----|-----|-----|-----|----
            |     |     |     |     |     |     |
            2     |  X  |  X  |  X  |  X  |     |
            |-----|-----|-----|-----|-----|-----|----
            |     |     |     |     |     |     |
            3     |     |     |     |     |     |
            |-----|-----|-----|-----|-----|-----|----
            |     |     |     |     |     |     |
            4     |     |     |     |     |     |


It may be helpful to think of the display as a grid, with each pixel contained in a grid cell. The X1, Y1, X2, and Y2 parameters to the Rectangle function specify an imaginary "bounding box" drawn on the grid. The rectangle is drawn within the bounding box.

The height, width, and area of the resulting rectangle have the following useful properties:

   Height = X2 - X1
   Width  = Y2 - Y1
   Area   = Height * Width


Additional reference words: 3.00 3.10 3.50 4.00 95
KBCategory: kbgraphic
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: November 2, 1995
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.