Declare Function PtInRect Lib "user32.dll" (lpRect As RECT, ByVal x As Long, ByVal y As Long) As Long
PtInRect determines if a point lies inside or outside of a rectangle. Note that Windows considers the left and top edges of a rectangle to be inside it, and the right and bottom edges to be outside. The function returns 1 if the point is inside or 0 if it is outside.
Example:
'Example of inside/outside a rectangle
Dim r As RECT
x = SetRect(r, 50, 50, 150, 150) ' API function sets r = (50,50)-(150,150)
Debug.Print PtInRect(r, 75, 100) ' returns 1 -- inside
Debug.Print PtInRect(r, 100, 100) ' returns 0 -- outside
Category: Rectangles
Back to the index.