Width Calculates the width of CRect. Height Calculates the height of CRect. Size Calculates the size of CRect. TopLeft Returns the top-left point of CRect. BottomRight Returns the bottom-right point of CRect.
CPoint& TopLeft( );--> 如何得到 CPoint 的 Top Left ?
什么意思? CRect rt; rt.Top; rt.Left;
你该不会是想得到那个4个单值吧 CRect本来就是一个类,有4个成员变量就是top,left,right, bottomCRect rect; int top = rect.m_top; 其他类似
error C2039: 'Top' : is not a member of 'CRect'error C2039: 'm_top' : is not a member of 'CRect'c:\program files\microsoft visual studio\vc98\mfc\include\afxwin.h(225) : see declaration of 'CRect'
Example// default constructor doesn't initialize! CRect rectUnknown;// four-integers are left, top, right, and bottom CRect rect(0, 0, 100, 50); ASSERT(rect.Width() == 100); ASSERT(rect.Height() == 50);// Initialize from RECT stucture RECT sdkRect; sdkRect.left = 0; sdkRect.top = 0; sdkRect.right = 100; sdkRect.bottom = 50;CRect rect2(sdkRect); // by reference CRect rect3(&sdkRect); // by address ASSERT(rect2 == rect); ASSERT(rect3 == rect);// from a point and a size CPoint pt(0, 0); CSize sz(100, 50); CRect rect4(pt, sz); ASSERT(rect4 == rect2);// from two points CSize szTopLeft(0, 0); CRect rect5(szTopLeft, sz); ASSERT(rect5 == rect4);
class CRect : public tagRECT { public:// Constructors // uninitialized rectangle CRect(); // from left, top, right, and bottom CRect(int l, int t, int r, int b); // copy constructor CRect(const RECT& srcRect); // from a pointer to another rect CRect(LPCRECT lpSrcRect); // from a point and size CRect(POINT point, SIZE size); // from two points CRect(POINT topLeft, POINT bottomRight);// Attributes (in addition to RECT members) // retrieves the width int Width() const; // returns the height int Height() const; // returns the size CSize Size() const; // reference to the top-left point CPoint& TopLeft(); // reference to the bottom-right point CPoint& BottomRight(); // const reference to the top-left point const CPoint& TopLeft() const; // const reference to the bottom-right point const CPoint& BottomRight() const; // the geometric center point of the rectangle CPoint CenterPoint() const; // swap the left and right void SwapLeftRight(); static void SwapLeftRight(LPRECT lpRect); // convert between CRect and LPRECT/LPCRECT (no need for &) operator LPRECT(); operator LPCRECT() const; // returns TRUE if rectangle has no area BOOL IsRectEmpty() const; // returns TRUE if rectangle is at (0,0) and has no area BOOL IsRectNull() const; // returns TRUE if point is within rectangle BOOL PtInRect(POINT point) const;// Operations // set rectangle from left, top, right, and bottom void SetRect(int x1, int y1, int x2, int y2); void SetRect(POINT topLeft, POINT bottomRight); // empty the rectangle void SetRectEmpty(); // copy from another rectangle void CopyRect(LPCRECT lpSrcRect); // TRUE if exactly the same as another rectangle BOOL EqualRect(LPCRECT lpRect) const; // inflate rectangle's width and height without // moving its top or left void InflateRect(int x, int y); void InflateRect(SIZE size); void InflateRect(LPCRECT lpRect); void InflateRect(int l, int t, int r, int b); // deflate the rectangle's width and height without // moving its top or left void DeflateRect(int x, int y); void DeflateRect(SIZE size); void DeflateRect(LPCRECT lpRect); void DeflateRect(int l, int t, int r, int b); // translate the rectangle by moving its top and left void OffsetRect(int x, int y); void OffsetRect(SIZE size); void OffsetRect(POINT point); void NormalizeRect(); // set this rectangle to intersection of two others BOOL IntersectRect(LPCRECT lpRect1, LPCRECT lpRect2); // set this rectangle to bounding union of two others BOOL UnionRect(LPCRECT lpRect1, LPCRECT lpRect2); // set this rectangle to minimum of two others BOOL SubtractRect(LPCRECT lpRectSrc1, LPCRECT lpRectSrc2);// Additional Operations void operator=(const RECT& srcRect); BOOL operator==(const RECT& rect) const; BOOL operator!=(const RECT& rect) const; void operator+=(POINT point); void operator+=(SIZE size); void operator+=(LPCRECT lpRect); void operator-=(POINT point); void operator-=(SIZE size); void operator-=(LPCRECT lpRect); void operator&=(const RECT& rect); void operator|=(const RECT& rect);// Operators returning CRect values CRect operator+(POINT point) const; CRect operator-(POINT point) const; CRect operator+(LPCRECT lpRect) const; CRect operator+(SIZE size) const; CRect operator-(SIZE size) const; CRect operator-(LPCRECT lpRect) const; CRect operator&(const RECT& rect2) const; CRect operator|(const RECT& rect2) const; CRect MulDiv(int nMultiplier, int nDivisor) const; };
Height Calculates the height of CRect.
Size Calculates the size of CRect.
TopLeft Returns the top-left point of CRect.
BottomRight Returns the bottom-right point of CRect.
如何得到 CPoint 的 Top Left ?
CRect rt;
rt.Top;
rt.Left;
CRect本来就是一个类,有4个成员变量就是top,left,right, bottomCRect rect;
int top = rect.m_top;
其他类似
CRect rectUnknown;// four-integers are left, top, right, and bottom
CRect rect(0, 0, 100, 50);
ASSERT(rect.Width() == 100);
ASSERT(rect.Height() == 50);// Initialize from RECT stucture
RECT sdkRect;
sdkRect.left = 0;
sdkRect.top = 0;
sdkRect.right = 100;
sdkRect.bottom = 50;CRect rect2(sdkRect); // by reference
CRect rect3(&sdkRect); // by address
ASSERT(rect2 == rect);
ASSERT(rect3 == rect);// from a point and a size
CPoint pt(0, 0);
CSize sz(100, 50);
CRect rect4(pt, sz);
ASSERT(rect4 == rect2);// from two points
CSize szTopLeft(0, 0);
CRect rect5(szTopLeft, sz);
ASSERT(rect5 == rect4);
{
public:// Constructors // uninitialized rectangle
CRect();
// from left, top, right, and bottom
CRect(int l, int t, int r, int b);
// copy constructor
CRect(const RECT& srcRect);
// from a pointer to another rect
CRect(LPCRECT lpSrcRect);
// from a point and size
CRect(POINT point, SIZE size);
// from two points
CRect(POINT topLeft, POINT bottomRight);// Attributes (in addition to RECT members) // retrieves the width
int Width() const;
// returns the height
int Height() const;
// returns the size
CSize Size() const;
// reference to the top-left point
CPoint& TopLeft();
// reference to the bottom-right point
CPoint& BottomRight();
// const reference to the top-left point
const CPoint& TopLeft() const;
// const reference to the bottom-right point
const CPoint& BottomRight() const;
// the geometric center point of the rectangle
CPoint CenterPoint() const;
// swap the left and right
void SwapLeftRight();
static void SwapLeftRight(LPRECT lpRect); // convert between CRect and LPRECT/LPCRECT (no need for &)
operator LPRECT();
operator LPCRECT() const; // returns TRUE if rectangle has no area
BOOL IsRectEmpty() const;
// returns TRUE if rectangle is at (0,0) and has no area
BOOL IsRectNull() const;
// returns TRUE if point is within rectangle
BOOL PtInRect(POINT point) const;// Operations // set rectangle from left, top, right, and bottom
void SetRect(int x1, int y1, int x2, int y2);
void SetRect(POINT topLeft, POINT bottomRight);
// empty the rectangle
void SetRectEmpty();
// copy from another rectangle
void CopyRect(LPCRECT lpSrcRect);
// TRUE if exactly the same as another rectangle
BOOL EqualRect(LPCRECT lpRect) const; // inflate rectangle's width and height without
// moving its top or left
void InflateRect(int x, int y);
void InflateRect(SIZE size);
void InflateRect(LPCRECT lpRect);
void InflateRect(int l, int t, int r, int b);
// deflate the rectangle's width and height without
// moving its top or left
void DeflateRect(int x, int y);
void DeflateRect(SIZE size);
void DeflateRect(LPCRECT lpRect);
void DeflateRect(int l, int t, int r, int b); // translate the rectangle by moving its top and left
void OffsetRect(int x, int y);
void OffsetRect(SIZE size);
void OffsetRect(POINT point);
void NormalizeRect(); // set this rectangle to intersection of two others
BOOL IntersectRect(LPCRECT lpRect1, LPCRECT lpRect2); // set this rectangle to bounding union of two others
BOOL UnionRect(LPCRECT lpRect1, LPCRECT lpRect2); // set this rectangle to minimum of two others
BOOL SubtractRect(LPCRECT lpRectSrc1, LPCRECT lpRectSrc2);// Additional Operations
void operator=(const RECT& srcRect);
BOOL operator==(const RECT& rect) const;
BOOL operator!=(const RECT& rect) const;
void operator+=(POINT point);
void operator+=(SIZE size);
void operator+=(LPCRECT lpRect);
void operator-=(POINT point);
void operator-=(SIZE size);
void operator-=(LPCRECT lpRect);
void operator&=(const RECT& rect);
void operator|=(const RECT& rect);// Operators returning CRect values
CRect operator+(POINT point) const;
CRect operator-(POINT point) const;
CRect operator+(LPCRECT lpRect) const;
CRect operator+(SIZE size) const;
CRect operator-(SIZE size) const;
CRect operator-(LPCRECT lpRect) const;
CRect operator&(const RECT& rect2) const;
CRect operator|(const RECT& rect2) const;
CRect MulDiv(int nMultiplier, int nDivisor) const;
};
CPoint *BR=rect.BottomRight();
CPoint *TL=rect.TopLeft();
int BR_x,BR_y,TL_x,TL_y;
BR_x=BR->x;
BR_y=BR->y;
TL_x=TL->x;
TL_y=TL->y;
CRectI.SetRect(1,1,3,3);
int nI=CRectI.BottomRight().x;