CRect::PtInRect

确定指定的是否在 CRect点之间。

BOOL PtInRect( 
   POINT point  
) const throw( );

参数

返回值

非零,则点在 CRect之间;否则为0。

备注

该点位于 CRect 中,如果它在左侧或左上角端位于或在所有四个边中。 向右或底端的点是外部 CRect

备注

矩形必须进行规范化或此功能可能会失败。可以调用 NormalizeRect 在调用此功能之前规范化矩形。

示例

CRect rect(5, 5, 100, 100);
CPoint pt1(35, 50);
CPoint pt2(125, 298);

// this is true, because pt1 is inside the rectangle
ASSERT(rect.PtInRect(pt1));

// this is NOT true, because pt2 is outside the rectangle
ASSERT(!rect.PtInRect(pt2));

// note that the right and the bottom aren't inside
ASSERT(!rect.PtInRect(CPoint(35, 100)));
ASSERT(!rect.PtInRect(CPoint(100, 98)));

// but the top and the left are inside
ASSERT(rect.PtInRect(CPoint(5, 65)));
ASSERT(rect.PtInRect(CPoint(88, 5)));

// and that PtInRect() works against a POINT, too
POINT pt;
pt.x = 35;
pt.y = 50;
ASSERT(rect.PtInRect(pt));   

要求

Header: atltypes.h

请参见

参考

CRect选件类

层次结构图

CRect::NormalizeRect

PtInRect