CRect::CRect

Constructs a CRect object.

CRect( ) throw( ); 
CRect( 
   int l, 
   int t, 
   int r, 
   int b  
) throw( );
CRect( 
   const RECT& srcRect  
) throw( );
CRect( 
   LPCRECT lpSrcRect  
) throw( );
CRect( 
   POINT point, 
   SIZE size  
) throw( );
CRect( 
   POINT topLeft, 
   POINT bottomRight  
) throw( );

Parameters

  • l
    Specifies the left position of CRect.

  • t
    Specifies the top of CRect.

  • r
    Specifies the right position of CRect.

  • b
    Specifies the bottom of CRect.

  • srcRect
    Refers to the RECT structure with the coordinates for CRect.

  • lpSrcRect
    Points to the RECT structure with the coordinates for CRect.

  • point
    Specifies the origin point for the rectangle to be constructed. Corresponds to the top-left corner.

  • size
    Specifies the displacement from the top-left corner to the bottom-right corner of the rectangle to be constructed.

  • topLeft
    Specifies the top-left position of CRect.

  • bottomRight
    Specifies the bottom-right position of CRect.

Remarks

If no arguments are given, left, top, right, and bottom members are not initialized.

The CRectconst RECT& ) and CRectLPCRECT ) constructors perform a CopyRect. The other constructors initialize the member variables of the object directly.

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
CPoint ptBottomRight(100, 50);
CRect rect5(pt, ptBottomRight);
ASSERT(rect5 == rect4);   

Requirements

Header: atltypes.h

See Also

Concepts

CRect Class

CRect Members

Hierarchy Chart

CRect::SetRect

CRect::CopyRect

CRect::operator =

CRect::SetRectEmpty