How to Get Smallest Bounding Rectangle for Drawing Functions

Last reviewed: March 10, 1997
Article ID: Q139217
3.50 3.51 | 4.00
WINDOWS   | WINDOWS NT
kbgraphic kbhowto

The information in this article applies to:

  • Microsoft Win32 Application Programming Interface (API) included with:

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

SUMMARY

Windows maintains an accumulated bounding rectangle for each application. An application can retrieve this bounding rectangle by calling GetBoundsRect, and it can set this rectangle by calling SetBoundsRect. But this rectangle may not be the smallest bounding rectangle if your drawing functions contain functions doing text output such as TextOut. GDI does not calculate ahead of time how far across the TextOut functions are going to draw. GDI just sets the right side of the bounding rectangle to a large number.

MORE INFORMATION

To get an accurate and smallest bounding rectangle, call LockWindowUpdate and pass the handle of the window to which you are going to draw. Then Windows records the extent of any attempted operations in a bounding rectangle without doing the actual drawing. When the window is unlocked by LockWindowUpdate(NULL), you can either use GetUpdateRect or intercept the rcPaint member of the PAINTSTRUCT in your WM_PAINT message handler to retrieve this smallest bounding rectangle.


Additional reference words: 3.50 4.00 GetUpdateRect
KBCategory: kbgrahpic kbhowto
KBSubcategory: GdiDrw GdiMisc

Keywords : GdiDrw GdiMisc kbgraphic kbhowto
Version : 3.50 3.51 | 4.00
Platform : NT WINDOWS


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: March 10, 1997
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.