Declare Function IntersectRect Lib "user32.dll" (lpDestRect As RECT, lpSrc1Rect As RECT, lpSrc2Rect As RECT) As Long
IntersectRect creates a rectangle based on the intersecting part of two other rectangles. The rectangular region where the two source rectangles overlap is the intersection rectangle. If one or both of the source rectangles are empty or there is no intersection, the function returns 0 and the lpDestRect rectangle is set to (0,0)-(0,0). If the source rectangles do overlap, the intersection is put into lpDestRect and the function returns 1.
Example:
'Demonstration of IntersectRect
Dim target As RECT, s1 As RECT, s2 As RECT
x = SetRect(s1, 50, 50, 150, 150) ' API sets s1 = (50,50)-(150,150)
x = SetRect(s2, 100, 100, 200, 200) ' s2 = (100,100)-(200,200)
x = IntersectRect(target, s1, s2)
' target = (100,100)-(150,150)
Related Calls: SubtractRect, UnionRect
Category: Rectangles
Back to the index.