次の方法で共有


CRect::PtInRect

指定した点が CRect内にあるかどうかを判定します。

BOOL PtInRect( 
   POINT point  
) const throw( );

パラメーター

戻り値

点が CRect内にある場合は、; それ以外の場合は 0。

解説

点が CRect 内に左端または上端にある場合、すべての 4 辺の内にあります。 右端または下端側のポイントは外側の 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));   

必要条件

ヘッダー: atltypes.h

参照

関連項目

CRect クラス

階層図

CRect::NormalizeRect

PtInRect