GetRgnBox Function

Declare Function GetRgnBox Lib "gdi32.dll" (ByVal hRgn As Long, lpRect As RECT) As Long

Platforms: Win 32s, Win 95/98, Win NT

GetRgnBox determines the bounding rectangle of a given region. The bounding rectangle is the smallest possible rectangle which fully encompases the region. The bounding rectangle is placed in the structure passed as lpRect. The function returns 0 if an error occured, or exactly one of the following flags specifying the shape of the input region:

COMPLEXREGION = 3
The region is not empty but is not rectangular.
NULLREGION = 1
The region is empty, i.e., null.
SIMPLEREGION = 2
The region is rectangular in shape.
hRgn
A handle to the region to get the bounding rectangle of.
lpRect
Receives the coordinates of the region's bounding rectangle.

Example:

' Fill a triangular region on Form1 in dark gray and fill its bounding
' rectangle (behind it) in light gray.
Dim triangle(0 To 2) As POINT_TYPE  ' vertices of triangular region
Dim hRgn As Long  ' handle to the triangular region
Dim hLightBrush As Long, hDarkBrush As Long  ' handles to the two brushes
Dim bounding As RECT  ' receives bounding rectangle of region
Dim retval As Long  ' generic return value

' Create the triangular region.
triangle(0).x = 150: triangle(0).y = 100  ' point #1: (150,100)
triangle(1).x = 200: triangle(1).y = 150  ' point #2: (200,150)
triangle(2).x = 175: triangle(2).y = 200  ' point #3: (175,200)
hRgn = CreatePolygonRgn(triangle(0), 3, ALTERNATE)  ' create the region
' Get handles to the light and dark gray solid stock brushes to use.
hLightBrush = GetStockObject(LTGRAY_BRUSH)
hDarkBrush = GetStockObject(DKGRAY_BRUSH)

' Calculate the triangular region's bounding rectangle.
retval = GetRgbBox(hRgn, bounding)  ' now bounding is the bounding rectangle
' Fill the bounding rectangle in ligh gray, the region in dark gray.
retval = FillRect(Form1.hDC, bounding, hLightBrush)
retval = FillRgn(Form1.hDC, hRgn, hDarkBrush)

' Delete the region to free up resources.
retval = DeleteObject(hRgn)

Category: Regions

Go back to the alphabetical Function listing.
Go back to the Reference section index.


This page is copyright © 2000 Paul Kuliniewicz. Copyright Information.
Go back to the Windows API Guide home page.
E-mail: vbapi@vbapi.com Send Encrypted E-Mail
This page is at http://www.vbapi.com/ref/g/getrgnbox.html