共用方式為


CRect::PtInRect

判斷指定的點是否包含在 CRect

BOOL PtInRect( 
   POINT point  
) const throw( );

參數

  • point
    包含 結構或 CPoint 物件。

傳回值

如果不是零,指向 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