SubtractRect Function

Declare Function SubtractRect Lib "user32.dll" (lprcDst As RECT, lprcSrc1 As RECT, lprcSrc2 As RECT) As Long

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

SubtractRect subtracts a smaller rectangle from a larger one. Rectangle subtraction is defined as follows. The large and small rectangles must intersect completely along one entire side, neither extanding farther along that side than the other. In other words, they must share a common side. If this is true, then all of the large rectangle that is not also part of the small rectangle is also a rectangle. This rectangle is the subtraction rectangle. This rectangle is put into the variable passed as lprcDst. If the two rectangles fail to meet the criteria, lprcDst is set equal to the large rectangle and the function returns 0. If subtraction is possible, the function returns 1.

lprcDst
Variable that receives the subtraction rectangle.
lprcSrc1
The large rectangle; that is, the rectangle subtracted from.
lprcSrc2
The small rectange; that is, the rectangle subtracted.

Example:

' A demonstration of rectangle subtract.  target = big - small.
' big = (20,30)-(70,80).  small = (20,30)-(40,80).  Note that the left side of the two rectangles is
' common.  target will be set to (41,30)-(70,80).
Dim target As RECT, big As RECT, small As RECT
Dim retval As Long  ' return value

' Set the big and small rectangles
retval = SetRect(big, 20, 30, 70, 80)  ' big = (20,30)-(70,80)
retval = SetRect(small, 20, 30, 40, 80)  ' small = (20,30)-(40,80)

' Subtract small from big and put the result into target
retval = SubtractRect(target, big, small)  ' now target = (41,30)-(70,80)

See Also: IntersectRect, UnionRect
Category: Rectangles

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/s/subtractrect.html