UnionRect Function

Declare Function UnionRect Lib "user32.dll" (lpDestRect As RECT, lpSrc1Rect As RECT, lpSrc2Rect As RECT) As Long

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

UnionRect determines the smallest possible rectangle that contains two other rectangles. This rectangle is called the union rectangle because it is derived from the union of the areas that the two source rectangles occupy. The union rectangle is put into the variable passed as lpDestRect. The function returns 0 if an error occured, or 1 if successful.

lpDestRect
Variable that receives the union rectangle.
lpSrc1Rect
The first of the two source rectangles.
lpSrc2Rect
The second of the two source rectangles.

Example:

' Create a large rectangle that contains the areas occupied by
' rectangles s and t.  The new rectangle will fully contain both smaller rectangles.
' s = (20,30)-(60,80); t = (100,110)-(200,300)
Dim s As RECT, t As RECT  ' small rectangles
Dim urect As RECT  ' receives the union rectangle
Dim retval As Long  ' return value

' Set the small rectangles
retval = SetRect(s, 20, 30, 60, 80)  ' set s = (20,30)-(60,80)
retval = SetRect(t, 100, 110, 200, 300)  ' set t = (100,110)-(200,300)

' Figure out the union rectangle
retval = UnionRect(urect, s, t)  ' now urect = (20,30)-(200,300)

Related Calls: IntersectRect, SubtractRect
Category: Rectangles
Back to the index.


Go to Paul Kuliniewicz's Home Page.
E-mail: rogue953@hotmail.com
This page is at http://skyscraper.fortunecity.com/transmission/45/api/u/unionrect.html