VC中CRect类的简介
我想知道所有有关CRect类的简介。包括成员函数,成员变量。还有派生类的成员变量成员函数。谢谢了。...
我想知道所有有关CRect类的简介。包括成员函数,成员变量。还有派生类的成员变量成员函数。谢谢了。
展开
展开全部
类CRect是对Windows结构RECT的封装,凡是能用RECT结构的地方都可以用CRect代替。
结构RECT表示一个矩形的位置和尺寸,其定义为:
typedef struct tagRECT{
LONG left;
LONG top;
LONG right;
LONG bottom;
} RECT;
其中 left、top分别表示矩形左上角顶点的横坐标和纵坐标,right、bottom分别表示矩形右下角顶点的横坐标和纵坐标。由于CRect提供了一些成员函数和重载运算符,使得CRect的操作更加方便。 1.CRect的构造函数 CRect有如下6个构造函数:
CRect( );
CRect( int l, int t, int r, int b );
CRect( const RECT& srcRect );
CRect( LPCRECT lpSrcRect );
CRect( POINT point, SIZE size );
CRect( POINT topLeft, POINT bottomRight );
说明:分别以不同的方式构造CRect对象,参数l,t,r,b分别指定矩形的左边、上边、右边和底边。SrcRect是一个RECT结构的引用。LpSrcRect是一个指向RECT结构的指针。Point指定矩形的左上角顶点的坐标,size指定矩形的长度和宽度。topLeft指定矩形的左上角顶点的坐标,bottomRight指定矩形的右下角顶点的坐标。
结构RECT表示一个矩形的位置和尺寸,其定义为:
typedef struct tagRECT{
LONG left;
LONG top;
LONG right;
LONG bottom;
} RECT;
其中 left、top分别表示矩形左上角顶点的横坐标和纵坐标,right、bottom分别表示矩形右下角顶点的横坐标和纵坐标。由于CRect提供了一些成员函数和重载运算符,使得CRect的操作更加方便。 1.CRect的构造函数 CRect有如下6个构造函数:
CRect( );
CRect( int l, int t, int r, int b );
CRect( const RECT& srcRect );
CRect( LPCRECT lpSrcRect );
CRect( POINT point, SIZE size );
CRect( POINT topLeft, POINT bottomRight );
说明:分别以不同的方式构造CRect对象,参数l,t,r,b分别指定矩形的左边、上边、右边和底边。SrcRect是一个RECT结构的引用。LpSrcRect是一个指向RECT结构的指针。Point指定矩形的左上角顶点的坐标,size指定矩形的长度和宽度。topLeft指定矩形的左上角顶点的坐标,bottomRight指定矩形的右下角顶点的坐标。
展开全部
CRec类是MFC的一个类,用于记录一个矩形的位置以及对矩形的相关操作
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
//Microsoft Visual Studio\VC98\Include\wtypes.h中
typedef struct tagRECT
{
LONG left;
LONG top;
LONG right;
LONG bottom;
} RECT;
//Microsoft Visual Studio\VC98\MFC\Include\afxwin.h中
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;
};
可以搜索到具体的实现,
typedef struct tagRECT
{
LONG left;
LONG top;
LONG right;
LONG bottom;
} RECT;
//Microsoft Visual Studio\VC98\MFC\Include\afxwin.h中
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;
};
可以搜索到具体的实现,
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询