Transfer:
http://baike.baidu.com/view/2406388.htm?fr=ala0
CRect and Windows RECT structure similar class, and further includes an operation member functions CRect Windows RECT objects and structures.
Anywhere delivery LPRECT, LPCRECT RECT structure or as a parameter, the object can pass CRect instead.
Note: This class is derived from the structure of tagRECT. (TagRECT is less commonly used aliases RECT structure.) This means that members of the RECT data structure (left, top, right, and bottom) also CRect accessible data members.
CRect contains a member variable is used to define the left and right corners of the rectangle points.
When specifying a CRect time, it must be carefully constructed so that it meet specifications - that is, so that the left and right coordinate values of the coordinate value is smaller than the top coordinate value is smaller than the coordinate value of the bottom. For example, the upper left corner (10,10), the lower right corner (20, 20) to define a rectangle meet specifications, but the upper left corner is (20, 20) and the lower right corner (10,10) value definition a rectangle does not meet specifications. If the rectangle is not compliant, the CRect many members will function in line with incorrect results. (See CRect :: NormalizeRect can get a list of these functions.) Before you call a rectangular function in line with the requirements of the specification, you can not conform to the specifications of the rectangle by calling the function into a rectangular NormalizeRect compliant.
When CRect to deal with the member function CDC :: DPtoLP and CDC :: LPtoDP to be careful. If the mapping mode environment is negative y-extent, as in the MM_LOENGLISH, the CDC :: DPtoLP CRect converted, so that its top larger than the bottom coordinate of the coordinates. Like function is then Size Height and height of the rectangle is returned as negative after conversion, the rectangle will be non-compliant.
When using CRect overloaded operators, a first operand must be a CRect; second operand may be a RECT structure or a CRect object.
#include <afxwin.h>
See: CPoint , CSize , RECT
CRect class members
structure
CRect construct a CRect object
Operation
Width of the width calculation CRect
Height calculate the height of CRect
Size calculates the size of CRect
TopLeft return to the upper left corner of CRect
BottomRight return to the lower right corner of CRect
CenterPoint Returns the center point of CRect
IsRectEmpty determine whether CRect is empty. If CRect width and / or height of 0, then it is empty.
IsRectNull determine the top CRect, bottom, left, and right are each equal to 0
PtInRect Determines whether the specified point is within the CRect
SetRect is sized CRect
SetRectEmpty CRect set to an empty rectangle (the coordinates are all equal to 0)
CopyRect a copy to the size of the source rectangle CRect
EqualRect determine whether a given rectangle is equal CRect
InflateRect CRect increase the width and height (to ensure that the center position of the rectangle, each of the expansion units to the surrounding parameter)
DeflateRect reduce the width and height of CRect
NormalizeRect so that the height and width specifications return CRect
OffsetRect to move to a specified offset CRect
SubtractRect subtracted from one another rectangle rectangle
IntersectRect set equal to the intersection of two rectangles CRect
the LP operator CRECT a convert a CRect the LP CRECT
an operator LPRECT CRect convert a LPRECT
The size of a rectangle operator = to copy CRect
operator == determines whether a rectangle equal CRect
operator! = not equal determines whether another rectangle CRect
operator + = increased so CRect specified offset, or to enlarge CRect
operator - = CRect subtracted from the specified offset, or out CRect
operator & = CRect set equal to one and a rectangular cross CRect
operator | = CRect set equal to CRect and a rectangle and
operator + to increase CRect given offset, and returns the resulting object CRect
operator - CRect from subtracting a given offset, and returns the resulting CRect object
operator & create a rectangle with a cross CRect, and returns the resulting object CRect
operator | CRect and create a rectangle and, and returns the resulting object CRect
CRect MFC class is commonly used class, very basic, it is sorted out for New reference.
Kingsoft translation with no checked rect word, it is estimated that rectangle shorthand, rectangle rectangular, rectangular meaning.
The default coordinate system: top-left corner is the origin, the right direction is a positive x-axis, y-axis positive direction for the lower side.
Constructor (CRect) five prototypes, second and third prototype prototype copy constructor. I now with a further upper-left corner coordinates of the three constructors configured to (10,20), x direction side length of 100, y direction side
Long rectangular 200.
A prototype:
CRect r1(10,20,110,220);
Prototype Four:
POINT pt = {10,20};
SIZE size = {100,200};
CRect r2(pt,size);
Prototype five:
POINT topLeft = {10,20};
POINT bottomRight = {110,220} ;
CRect r3(topLeft,bottomRight);
The following code can check the size of a rectangle, create a single document project Sdi, modify the OnDraw function:
void CSdiView::OnDraw(CDC* pDC)
{
CSdiDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
CRect r1(10,20,110,220);
pDC->Rectangle(&r1);
}
int Width( ) const;
Obtaining width, int iWidth = r1.Width (); iWidth is at 100.
int Height( ) const;
Obtaining the height, int iHeight = r1.Height (); iHeight result is 200.
CSize Size( ) const;
To obtain the width and height, CSize size = r1.Size (); size.cx to 100, size.cy 200.
CPoint& TopLeft( );
Obtain the coordinates of the upper left corner, because the return value is a reference, so you can return by this value, modify the function of the upper left corner.
CRect r1(10,20,110,220);
r1.TopLeft().x = 0;
r1.TopLeft().y = 0 ;
R1 becomes the upper-left coordinates (0, 0), the coordinates of the upper left corner can be achieved by this function.
CRect r1(10,20,110,220);
CPoint TopLeft = r1.TopLeft();
TopLeft.x value of 10, TopLeft.y is 20.
BottomRight obtain the coordinates of the lower right corner
CPoint CenterPoint () const; obtaining the center coordinates obtained, CPoint pt = r1.CenterPoint (); pt is (60,120).
BOOL IsRectEmpty () const; if long seats or width of 0 or illegal, returns true; otherwise it returns false.
CRect r1(210,20,110,220);
bool bEmpty = r1.IsRectEmpty();
The result is true, because the left is greater than the right.
CRect :: IsRectNull, the coordinates of the four sides are zero, the result is true, otherwise false.
BOOL PtInRect (POINT point) const; see whether a point is within the rectangle.
CRect r1(10,20,110,220);
POINT pt1={10,10};
POINT pt2={10,30};
bool bIn1 = r1.PtInRect(pt1);
bool bIn2 = r1.PtInRect(pt2);
bIn1 is false, bIn2 is true.
CRect :: SetRect, four sides of the set value, similar to the use of a prototype of the constructor.
CRect :: SetRectEmpty, the coordinates of the four sides is set to 0.
CopyRect void (the LP CRECT LPSR CRect ); replication.
CRect r2;
r2.CopyRect(&r1);
The same value of r1 and r2 values.
CRect :: EqualRect, two rectangles are not the same, the coordinates of the four sides must be the same.
CRect r1(10,20,110,220);
CRect r2(110,220,10,20);
bool bEqual = r1.EqualRect(r2);
bEqual is false, because the left and right sides of their upper and lower different, is reversed.
CRect r1(110,220,10,20);
CRect r2(110,220,10,20);
bool bEqual = r1.EqualRect(r2);
bEqual is true because the same four sides.
CRect :: InflateRect, increasing the width and height.
CRect r(0,0,0,0);
r.InflateRect (2,3); // result is (-2, -3,2,3);
SIZE size = {3,2};
r.InflateRect (size); // result is (-5, -5,5,5);
CRect r1(-5,-5,-5,-5);
r.InflateRect (& r1); // results (0,0,0,0);
// left left -1 (1 right), the edge shift -1, 2 the right to the right, down the lower 2
r.InflateRect (-1, -1,2,2); // results (1,1,2,2);
CRect :: DeflateRect, reducing the width and height, and InflateRect similar methods.
CRect :: NormalizeRect, standardization, and adjust the upper and lower left and right side, so that the logic in line with humans.
CRect r(10,10,0,0);
r.NormalizeRect();
Results (0,0,10,10)
CRect :: OffsetRect, move the entire rectangle.
CRect r(0,0,10,10);
r.OffsetRect (1,1); // 1 right, down 1
POINT point = {1,1};
r.OffsetRect (point); // 1 then right, then down 1
SIZE size = {-2,-2};
r.OffsetRect (size); // right -2, -2 down
CRect :: SubtractRect, lpRectSrc1 minus lpRectSrc2, note that not a minus. Expression process is not good, run the following code to see the effects.
void CSdiView::OnDraw(CDC* pDC)
{
pDC->SelectStockObject(NULL_BRUSH);
CRect r1(10,10, 100,100);
CRect r2 (50, 10, 150, 150); // and CRect r2 (50, 50, 150, 150); the results are not the same
pDC->Rectangle(r1);
pDC->Rectangle(r2);
{// red area is the result of SubtractRect
CRect r ;
r.SubtractRect(r1,r2);
CBrush brush(RGB(255,0,0));
pDC->SelectObject(&brush);
pDC->Rectangle(&r);
}
}
CRect :: IntersectRect, intersection of
void CSdiView::OnDraw(CDC* pDC)
{
pDC->SelectStockObject(NULL_BRUSH);
CRect r1(10,10, 100,100);
CRect r2 (50, 10, 150, 150); // and CRect r2 (50, 50, 150, 150); the results are not the same
pDC->Rectangle(r1);
pDC->Rectangle(r2);
{// green area is the result of IntersectRect
CRect r ;
r.IntersectRect(r1,r2);
CBrush brush(RGB(0,255,0));
pDC->SelectObject(&brush);
pDC->Rectangle(&r);
}
}
CRect :: UnionRect, seeking union
void CSdiView::OnDraw(CDC* pDC)
{
pDC->SelectStockObject(NULL_BRUSH);
CRect r1(10,10, 100,100);
CRect r2 (50, 50, 150, 150); // and CRect r2 (50, 50, 150, 150); the results are not the same
pDC->Rectangle(r1);
pDC->Rectangle(r2);
{// blue border is the result of UnionRect
CRect r ;
r.UnionRect(r1,r2);
CPen pen(PS_DOT,1,RGB(0,0,255));
pDC->SelectObject(&pen);
pDC->Rectangle(&r);
}
}
The LP :: operator CRect CRECT , converted to LPCRECT type.
CRect :: operator LPRECT, converted into LPRECT
CRect r(0,0,100,100);
LP CRECT p CRect = r;
LPRECT pRect = r;
The second line calls LPCRECT operator, the third row LPRECT call operator.
typedef const RECT* LPCRECT; // pointer to read/only RECT
typedef struct tagRECT
{
LONG left;
LONG top;
LONG right;
LONG bottom;
} RECT, *PRECT, NEAR *NPRECT, FAR *LPRECT;
CRect :: operator =, overloaded "=" operator, the actual call CopyRect.
CRect :: operator ==, heavy-duty "==" operator, the actual call EqualRect.
operator! =, heavy-duty "! =" operator, the actual call EqualRect.
CRect :: operator + =, overloaded "= +" operator, the first and second prototype prototype OffsetRect offsets call, the third call prototype InflateRect.
CRect :: operator - =, Overload "- =" operator, the first and second prototype prototype OffsetRect offsets call, the third call prototype InflateRect.
CRect :: operator & =, Overload "& =" operator, the actual call IntersectRect.
CRect :: operator | = overload "| =" operator, the actual call UnionRect.
+, -, &, |, and similar to the above, it is not explained in detail
A, CRect class presentation
CRect and Windows RECT structure similar class, and further includes an operation member functions CRect Windows RECT objects and structures.
Anywhere delivery LPRECT, LPCRECT RECT structure or as a parameter, the object can pass CRect instead.
Note: This class is derived from the structure of tagRECT. (TagRECT is less commonly used aliases RECT structure.) This means that members of the RECT data structure (left, top, right, and bottom) also CRect accessible data members.
CRect contains a member variable is used to define the left and right corners of the rectangle points.
When specifying a CRect time, it must be carefully constructed so that it meet specifications - that is, so that the left and right coordinate values of the coordinate value is smaller than the top coordinate value is smaller than the coordinate value of the bottom. For example, the upper left corner (10,10), the lower right corner (20, 20) to define a rectangle meet specifications, but the upper left corner is (20, 20) and the lower right corner (10,10) value definition a rectangle does not meet specifications. If the rectangle is not compliant, the CRect many members will function in line with incorrect results. (See CRect :: NormalizeRect can get a list of these functions.) Before you call a rectangular function in line with the requirements of the specification, you can not conform to the specifications of the rectangle by calling the function into a rectangular NormalizeRect compliant.
When CRect to deal with the member function CDC :: DPtoLP and CDC :: LPtoDP to be careful. If the mapping mode environment is negative y-extent, as in the MM_LOENGLISH, the CDC :: DPtoLP CRect converted, so that its top larger than the bottom coordinate of the coordinates. Like function is then Size Height and height of the rectangle is returned as negative after conversion, the rectangle will be non-compliant.
When using CRect overloaded operators, a first operand must be a CRect; second operand may be a RECT structure or a CRect object.
#include <afxwin.h>
See: CPoint , CSize , RECT
CRect class members
structure
CRect construct a CRect object
Operation
Width of the width calculation CRect
Height calculate the height of CRect
Size calculates the size of CRect
TopLeft return to the upper left corner of CRect
BottomRight return to the lower right corner of CRect
CenterPoint Returns the center point of CRect
IsRectEmpty determine whether CRect is empty. If CRect width and / or height of 0, then it is empty.
IsRectNull determine the top CRect, bottom, left, and right are each equal to 0
PtInRect Determines whether the specified point is within the CRect
SetRect is sized CRect
SetRectEmpty CRect set to an empty rectangle (the coordinates are all equal to 0)
CopyRect a copy to the size of the source rectangle CRect
EqualRect determine whether a given rectangle is equal CRect
InflateRect CRect increase the width and height (to ensure that the center position of the rectangle, each of the expansion units to the surrounding parameter)
DeflateRect reduce the width and height of CRect
NormalizeRect so that the height and width specifications return CRect
OffsetRect to move to a specified offset CRect
SubtractRect subtracted from one another rectangle rectangle
IntersectRect set equal to the intersection of two rectangles CRect
UnionRect provided CRect set equal to two rectangles and
MoveToX rectangular translated to the same position as its left argument and
MoveToXY so
MoveToY so
the LP operator CRECT a convert a CRect the LP CRECT
an operator LPRECT CRect convert a LPRECT
The size of a rectangle operator = to copy CRect
operator == determines whether a rectangle equal CRect
operator! = not equal determines whether another rectangle CRect
operator + = increased so CRect specified offset, or to enlarge CRect
operator - = CRect subtracted from the specified offset, or out CRect
operator & = CRect set equal to one and a rectangular cross CRect
operator | = CRect set equal to CRect and a rectangle and
operator + to increase CRect given offset, and returns the resulting object CRect
operator - CRect from subtracting a given offset, and returns the resulting CRect object
operator & create a rectangle with a cross CRect, and returns the resulting object CRect
operator | CRect and create a rectangle and, and returns the resulting object CRect
Second, personal experience
CRect MFC class is commonly used class, very basic, it is sorted out for New reference.
Kingsoft translation with no checked rect word, it is estimated that rectangle shorthand, rectangle rectangular, rectangular meaning.
The default coordinate system: top-left corner is the origin, the right direction is a positive x-axis, y-axis positive direction for the lower side.
Constructor (CRect) five prototypes, second and third prototype prototype copy constructor. I now with a further upper-left corner coordinates of the three constructors configured to (10,20), x direction side length of 100, y direction side
Long rectangular 200.
A prototype:
CRect r1(10,20,110,220);
Prototype Four:
POINT pt = {10,20};
SIZE size = {100,200};
CRect r2(pt,size);
Prototype five:
POINT topLeft = {10,20};
POINT bottomRight = {110,220} ;
CRect r3(topLeft,bottomRight);
The following code can check the size of a rectangle, create a single document project Sdi, modify the OnDraw function:
void CSdiView::OnDraw(CDC* pDC)
{
CSdiDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
CRect r1(10,20,110,220);
pDC->Rectangle(&r1);
}
int Width( ) const;
Obtaining width, int iWidth = r1.Width (); iWidth is at 100.
int Height( ) const;
Obtaining the height, int iHeight = r1.Height (); iHeight result is 200.
CSize Size( ) const;
To obtain the width and height, CSize size = r1.Size (); size.cx to 100, size.cy 200.
CPoint& TopLeft( );
Obtain the coordinates of the upper left corner, because the return value is a reference, so you can return by this value, modify the function of the upper left corner.
CRect r1(10,20,110,220);
r1.TopLeft().x = 0;
r1.TopLeft().y = 0 ;
R1 becomes the upper-left coordinates (0, 0), the coordinates of the upper left corner can be achieved by this function.
CRect r1(10,20,110,220);
CPoint TopLeft = r1.TopLeft();
TopLeft.x value of 10, TopLeft.y is 20.
BottomRight obtain the coordinates of the lower right corner
CPoint CenterPoint () const; obtaining the center coordinates obtained, CPoint pt = r1.CenterPoint (); pt is (60,120).
BOOL IsRectEmpty () const; if long seats or width of 0 or illegal, returns true; otherwise it returns false.
CRect r1(210,20,110,220);
bool bEmpty = r1.IsRectEmpty();
The result is true, because the left is greater than the right.
CRect :: IsRectNull, the coordinates of the four sides are zero, the result is true, otherwise false.
BOOL PtInRect (POINT point) const; see whether a point is within the rectangle.
CRect r1(10,20,110,220);
POINT pt1={10,10};
POINT pt2={10,30};
bool bIn1 = r1.PtInRect(pt1);
bool bIn2 = r1.PtInRect(pt2);
bIn1 is false, bIn2 is true.
CRect :: SetRect, four sides of the set value, similar to the use of a prototype of the constructor.
CRect :: SetRectEmpty, the coordinates of the four sides is set to 0.
CopyRect void (the LP CRECT LPSR CRect ); replication.
CRect r2;
r2.CopyRect(&r1);
The same value of r1 and r2 values.
CRect :: EqualRect, two rectangles are not the same, the coordinates of the four sides must be the same.
CRect r1(10,20,110,220);
CRect r2(110,220,10,20);
bool bEqual = r1.EqualRect(r2);
bEqual is false, because the left and right sides of their upper and lower different, is reversed.
CRect r1(110,220,10,20);
CRect r2(110,220,10,20);
bool bEqual = r1.EqualRect(r2);
bEqual is true because the same four sides.
CRect :: InflateRect, increasing the width and height.
CRect r(0,0,0,0);
r.InflateRect (2,3); // result is (-2, -3,2,3);
SIZE size = {3,2};
r.InflateRect (size); // result is (-5, -5,5,5);
CRect r1(-5,-5,-5,-5);
r.InflateRect (& r1); // results (0,0,0,0);
// left left -1 (1 right), the edge shift -1, 2 the right to the right, down the lower 2
r.InflateRect (-1, -1,2,2); // results (1,1,2,2);
CRect :: DeflateRect, reducing the width and height, and InflateRect similar methods.
CRect :: NormalizeRect, standardization, and adjust the upper and lower left and right side, so that the logic in line with humans.
CRect r(10,10,0,0);
r.NormalizeRect();
Results (0,0,10,10)
CRect :: OffsetRect, move the entire rectangle.
CRect r(0,0,10,10);
r.OffsetRect (1,1); // 1 right, down 1
POINT point = {1,1};
r.OffsetRect (point); // 1 then right, then down 1
SIZE size = {-2,-2};
r.OffsetRect (size); // right -2, -2 down
CRect :: SubtractRect, lpRectSrc1 minus lpRectSrc2, note that not a minus. Expression process is not good, run the following code to see the effects.
void CSdiView::OnDraw(CDC* pDC)
{
pDC->SelectStockObject(NULL_BRUSH);
CRect r1(10,10, 100,100);
CRect r2 (50, 10, 150, 150); // and CRect r2 (50, 50, 150, 150); the results are not the same
pDC->Rectangle(r1);
pDC->Rectangle(r2);
{// red area is the result of SubtractRect
CRect r ;
r.SubtractRect(r1,r2);
CBrush brush(RGB(255,0,0));
pDC->SelectObject(&brush);
pDC->Rectangle(&r);
}
}
CRect :: IntersectRect, intersection of
void CSdiView::OnDraw(CDC* pDC)
{
pDC->SelectStockObject(NULL_BRUSH);
CRect r1(10,10, 100,100);
CRect r2 (50, 10, 150, 150); // and CRect r2 (50, 50, 150, 150); the results are not the same
pDC->Rectangle(r1);
pDC->Rectangle(r2);
{// green area is the result of IntersectRect
CRect r ;
r.IntersectRect(r1,r2);
CBrush brush(RGB(0,255,0));
pDC->SelectObject(&brush);
pDC->Rectangle(&r);
}
}
CRect :: UnionRect, seeking union
void CSdiView::OnDraw(CDC* pDC)
{
pDC->SelectStockObject(NULL_BRUSH);
CRect r1(10,10, 100,100);
CRect r2 (50, 50, 150, 150); // and CRect r2 (50, 50, 150, 150); the results are not the same
pDC->Rectangle(r1);
pDC->Rectangle(r2);
{// blue border is the result of UnionRect
CRect r ;
r.UnionRect(r1,r2);
CPen pen(PS_DOT,1,RGB(0,0,255));
pDC->SelectObject(&pen);
pDC->Rectangle(&r);
}
}
The LP :: operator CRect CRECT , converted to LPCRECT type.
CRect :: operator LPRECT, converted into LPRECT
CRect r(0,0,100,100);
LP CRECT p CRect = r;
LPRECT pRect = r;
The second line calls LPCRECT operator, the third row LPRECT call operator.
typedef const RECT* LPCRECT; // pointer to read/only RECT
typedef struct tagRECT
{
LONG left;
LONG top;
LONG right;
LONG bottom;
} RECT, *PRECT, NEAR *NPRECT, FAR *LPRECT;
CRect :: operator =, overloaded "=" operator, the actual call CopyRect.
CRect :: operator ==, heavy-duty "==" operator, the actual call EqualRect.
operator! =, heavy-duty "! =" operator, the actual call EqualRect.
CRect :: operator + =, overloaded "= +" operator, the first and second prototype prototype OffsetRect offsets call, the third call prototype InflateRect.
CRect :: operator - =, Overload "- =" operator, the first and second prototype prototype OffsetRect offsets call, the third call prototype InflateRect.
CRect :: operator & =, Overload "& =" operator, the actual call IntersectRect.
CRect :: operator | = overload "| =" operator, the actual call UnionRect.
+, -, &, |, and similar to the above, it is not explained in detail