MFC基本绘图函数
在Windows平台上,应用程序的图形设备接口(Graphics Device Interface, GDI)被抽象为设备上下文CDC类(Device Context, DC)。因此,直接接受图形数据信息的不是显示器和打印机等硬件设备,而是CDC对象。
CDC类结构
CDC类
- CDC类派生:CClientDC类、CMetaFileDC类、CPaintDC类和CWindowDC类
- CClientDC类:显示器客户区设备上下文类,只能在窗口的客户区进行绘图,点(0,0)是客户区的左上角。构造函数自动调用GetDC()函数,析构函数自动调用ReleaseDC()函数
- CMetaFileDC类:Windows图元文件设备上下文类,封装了在Windows中绘图图元的方法
- CPaintDC类:只在响应WM_PAINT消息时使用,构造函数自动调用BeginPaint()函数,析构函数自动调用EndPaint()函数。使用在视图窗口中绘图时,需要先添加WM_PAINT消息的映射函数OnPaint(),然后在OnPaint()函数编写与CPaintDC类相关的代码,而不是编写在OnDraw()中。如果使用OnPaint()函数响应了WM_PAINT消息,OnDraw()函数会自动屏蔽
- CWindowDC类:整个屏幕区域的显示器设备上下文类,包括客户区和非客户区,允许在整个屏幕区域内进行绘图,构造函数自动调用GetWindowDC(),析构函数自动调用ReleaseDC()函数。点(0, 0) 位于屏幕的左上角,而CClientDC和CPaintDC中的点(0, 0)在屏幕客户区的左上角。如果在CTestView类中是同CWindowDC类对象进行绘图,只有在使用GetParent()函数获得CWnd指针后,才能在整个屏幕区域内绘图。
简单的数据类型
CPont, CSize, CRect是对Windows的POINT, RECT, SIZE结构体的封装(继承)
在c:\Program(x86)\Windows Kits\8.1\Include\Shared\windef.h已经定义了以上结构体:
POINT结构:
typedef struct tagPOINT
{
LONG x;
LONG y;
} POINT, *PPOINT, NEAR *NPPOINT, FAR *LPPOINT;
SIZE结构体:
typedef struct tagSIZE
{
LONG cx;
LONG cy;
} SIZE, *PSIZE, *LPSIZE;
RECT结构体:
typedef struct tagRECT
{
LONG left;
LONG top;
LONG right;
LONG bottom;
} RECT, *PRECT, NEAR *NPRECT, FAR *LPRECT;
在c:\Program Files(x86)\Microsoft Visual Studio 12.0\VC\arlmfc\include\atltypes.h定义了以下类:
CPoint类:
class CPoint :
public tagPOINT
{
public:
// Constructors
// create an uninitialized point
CPoint() throw();
// create from two integers
CPoint(
_In_ int initX,
_In_ int initY) throw();
// create from another point
CPoint(_In_ POINT initPt) throw();
// create from a size
CPoint(_In_ SIZE initSize) throw();
// create from an LPARAM: x = LOWORD(dw) y = HIWORD(dw)
CPoint(_In_ LPARAM dwPoint) throw();
// Operations
// translate the point
void Offset(
_In_ int xOffset,
_In_ int yOffset) throw();
void Offset(_In_ POINT point) throw();
void Offset(_In_ SIZE size) throw();
void SetPoint(
_In_ int X,
_In_ int Y) throw();
BOOL operator==(_In_ POINT point) const throw();
BOOL operator!=(_In_ POINT point) const throw();
void operator+=(_In_ SIZE size) throw();
void operator-=(_In_ SIZE size) throw();
void operator+=(_In_ POINT point) throw();
void operator-=(_In_ POINT point) throw();
// Operators returning CPoint values
CPoint operator+(_In_ SIZE size) const throw();
CPoint operator-(_In_ SIZE size) const throw();
CPoint operator-() const throw();
CPoint operator+(_In_ POINT point) const throw();
// Operators returning CSize values
CSize operator-(_In_ POINT point) const throw();
// Operators returning CRect values
CRect operator+(_In_ const RECT* lpRect) const throw();
CRect operator-(_In_ const RECT* lpRect) const throw();
};
initX和initY是点x, y坐标,initPt是一个POINT结构
其中:函数后面加throw()的作用可以参考:C++函数后面加throw关键字的含义
CPoint类及其成员函数的初始化:
// CPoint
inline CPoint::CPoint() throw()
{
x = 0;
y = 0;
}
inline CPoint::CPoint(
_In_ int initX,
_In_ int initY) throw()
{
x = initX;
y = initY;
}
inline CPoint::CPoint(_In_ POINT initPt) throw()
{
*(POINT*)this = initPt;
}
inline CPoint::CPoint(_In_ SIZE initSize) throw()
{
*(SIZE*)this = initSize;
}
inline CPoint::CPoint(_In_ LPARAM dwPoint) throw()
{
x = (short)LOWORD(dwPoint);
y = (short)HIWORD(dwPoint);
}
inline void CPoint::Offset(
_In_ int xOffset,
_In_ int yOffset) throw()
{
x += xOffset;
y += yOffset;
}
inline void CPoint::Offset(_In_ POINT point) throw()
{
x += point.x;
y += point.y;
}
inline void CPoint::Offset(_In_ SIZE size) throw()
{
x += size.cx;
y += size.cy;
}
inline void CPoint::SetPoint(
_In_ int X,
_In_ int Y) throw()
{
x = X;
y = Y;
}
CPoint类的操作符重载:
inline BOOL CPoint::operator==(_In_ POINT point) const throw()
{
return (x == point.x && y == point.y);
}
inline BOOL CPoint::operator!=(_In_ POINT point) const throw()
{
return (x != point.x || y != point.y);
}
inline void CPoint::operator+=(_In_ SIZE size) throw()
{
x += size.cx;
y += size.cy;
}
inline void CPoint::operator-=(_In_ SIZE size) throw()
{
x -= size.cx;
y -= size.cy;
}
inline void CPoint::operator+=(_In_ POINT point) throw()
{
x += point.x;
y += point.y;
}
inline void CPoint::operator-=(_In_ POINT point) throw()
{
x -= point.x;
y -= point.y;
}
inline CPoint CPoint::operator+(_In_ SIZE size) const throw()
{
return CPoint(x + size.cx, y + size.cy);
}
inline CPoint CPoint::operator-(_In_ SIZE size) const throw()
{
return CPoint(x - size.cx, y - size.cy);
}
inline CPoint CPoint::operator-() const throw()
{
return CPoint(-x, -y);
}
inline CPoint CPoint::operator+(_In_ POINT point) const throw()
{
return CPoint(x + point.x, y + point.y);
}
inline CSize CPoint::operator-(_In_ POINT point) const throw()
{
return CSize(x - point.x, y - point.y);
}
inline CRect CPoint::operator+(_In_ const RECT* lpRect) const throw()
{
return CRect(lpRect) + *this;
}
inline CRect CPoint::operator-(_In_ const RECT* lpRect) const throw()
{
return CRect(lpRect) - *this;
}
CSize类:
class CSize :
public tagSIZE
{
public:
// Constructors
// construct an uninitialized size
CSize() throw();
// create from two integers
CSize(
_In_ int initCX,
_In_ int initCY) throw();
// create from another size
CSize(_In_ SIZE initSize) throw();
// create from a point
CSize(_In_ POINT initPt) throw();
// create from a DWORD: cx = LOWORD(dw) cy = HIWORD(dw)
CSize(_In_ DWORD dwSize) throw();
// Operations
BOOL operator==(_In_ SIZE size) const throw();
BOOL operator!=(_In_ SIZE size) const throw();
void operator+=(_In_ SIZE size) throw();
void operator-=(_In_ SIZE size) throw();
void SetSize(_In_ int CX, _In_ int CY) throw();
// Operators returning CSize values
CSize operator+(_In_ SIZE size) const throw();
CSize operator-(_In_ SIZE size) const throw();
CSize operator-() const throw();
// Operators returning CPoint values
CPoint operator+(_In_ POINT point) const throw();
CPoint operator-(_In_ POINT point) const throw();
// Operators returning CRect values
CRect operator+(_In_ const RECT* lpRect) const throw();
CRect operator-(_In_ const RECT* lpRect) const throw();
};
initCX和initCY是举行的x, y长度,initSize是一个SIZE结构
CSize类及其成员函数的初始化:
// CSize
inline CSize::CSize() throw()
{
cx = 0;
cy = 0;
}
inline CSize::CSize(
_In_ int initCX,
_In_ int initCY) throw()
{
cx = initCX;
cy = initCY;
}
inline CSize::CSize(_In_ SIZE initSize) throw()
{
*(SIZE*)this = initSize;
}
inline CSize::CSize(_In_ POINT initPt) throw()
{
*(POINT*)this = initPt;
}
inline CSize::CSize(_In_ DWORD dwSize) throw()
{
cx = (short)LOWORD(dwSize);
cy = (short)HIWORD(dwSize);
}
CSize类的操作符重载:
inline BOOL CSize::operator==(_In_ SIZE size) const throw()
{
return (cx == size.cx && cy == size.cy);
}
inline BOOL CSize::operator!=(_In_ SIZE size) const throw()
{
return (cx != size.cx || cy != size.cy);
}
inline void CSize::operator+=(_In_ SIZE size) throw()
{
cx += size.cx;
cy += size.cy;
}
inline void CSize::operator-=(_In_ SIZE size) throw()
{
cx -= size.cx;
cy -= size.cy;
}
inline void CSize::SetSize(
_In_ int CX,
_In_ int CY) throw()
{
cx = CX;
cy = CY;
}
inline CSize CSize::operator+(_In_ SIZE size) const throw()
{
return CSize(cx + size.cx, cy + size.cy);
}
inline CSize CSize::operator-(_In_ SIZE size) const throw()
{
return CSize(cx - size.cx, cy - size.cy);
}
inline CSize CSize::operator-() const throw()
{
return CSize(-cx, -cy);
}
inline CPoint CSize::operator+(_In_ POINT point) const throw()
{
return CPoint(cx + point.x, cy + point.y);
}
inline CPoint CSize::operator-(_In_ POINT point) const throw()
{
return CPoint(cx - point.x, cy - point.y);
}
inline CRect CSize::operator+(_In_ const RECT* lpRect) const throw()
{
return CRect(lpRect) + *this;
}
inline CRect CSize::operator-(_In_ const RECT* lpRect) const throw()
{
return CRect(lpRect) - *this;
}
CRect类:
class CRect :
public tagRECT
{
// Constructors
public:
// uninitialized rectangle
CRect() throw();
// from left, top, right, and bottom
CRect(
_In_ int l,
_In_ int t,
_In_ int r,
_In_ int b) throw();
// copy constructor
CRect(_In_ const RECT& srcRect) throw();
// from a pointer to another rect
CRect(_In_ LPCRECT lpSrcRect) throw();
// from a point and size
CRect(
_In_ POINT point,
_In_ SIZE size) throw();
// from two points
CRect(
_In_ POINT topLeft,
_In_ POINT bottomRight) throw();
// Attributes (in addition to RECT members)
// retrieves the width
int Width() const throw();
// returns the height
int Height() const throw();
// returns the size
CSize Size() const throw();
// reference to the top-left point
CPoint& TopLeft() throw();
// reference to the bottom-right point
CPoint& BottomRight() throw();
// const reference to the top-left point
const CPoint& TopLeft() const throw();
// const reference to the bottom-right point
const CPoint& BottomRight() const throw();
// the geometric center point of the rectangle
CPoint CenterPoint() const throw();
// swap the left and right
void SwapLeftRight() throw();
static void WINAPI SwapLeftRight(_Inout_ LPRECT lpRect) throw();
// convert between CRect and LPRECT/LPCRECT (no need for &)
operator LPRECT() throw();
operator LPCRECT() const throw();
// returns TRUE if rectangle has no area
BOOL IsRectEmpty() const throw();
// returns TRUE if rectangle is at (0,0) and has no area
BOOL IsRectNull() const throw();
// returns TRUE if point is within rectangle
BOOL PtInRect(_In_ POINT point) const throw();
// Operations
// set rectangle from left, top, right, and bottom
void SetRect(
_In_ int x1,
_In_ int y1,
_In_ int x2,
_In_ int y2) throw();
void SetRect(
_In_ POINT topLeft,
_In_ POINT bottomRight) throw();
// empty the rectangle
void SetRectEmpty() throw();
// copy from another rectangle
void CopyRect(_In_ LPCRECT lpSrcRect) throw();
// TRUE if exactly the same as another rectangle
BOOL EqualRect(_In_ LPCRECT lpRect) const throw();
// Inflate rectangle's width and height by
// x units to the left and right ends of the rectangle
// and y units to the top and bottom.
void InflateRect(
_In_ int x,
_In_ int y) throw();
// Inflate rectangle's width and height by
// size.cx units to the left and right ends of the rectangle
// and size.cy units to the top and bottom.
void InflateRect(_In_ SIZE size) throw();
// Inflate rectangle's width and height by moving individual sides.
// Left side is moved to the left, right side is moved to the right,
// top is moved up and bottom is moved down.
void InflateRect(_In_ LPCRECT lpRect) throw();
void InflateRect(
_In_ int l,
_In_ int t,
_In_ int r,
_In_ int b) throw();
// deflate the rectangle's width and height without
// moving its top or left
void DeflateRect(
_In_ int x,
_In_ int y) throw();
void DeflateRect(_In_ SIZE size) throw();
void DeflateRect(_In_ LPCRECT lpRect) throw();
void DeflateRect(
_In_ int l,
_In_ int t,
_In_ int r,
_In_ int b) throw();
// translate the rectangle by moving its top and left
void OffsetRect(
_In_ int x,
_In_ int y) throw();
void OffsetRect(_In_ SIZE size) throw();
void OffsetRect(_In_ POINT point) throw();
void NormalizeRect() throw();
// absolute position of rectangle
void MoveToY(_In_ int y) throw();
void MoveToX(_In_ int x) throw();
void MoveToXY(
_In_ int x,
_In_ int y) throw();
void MoveToXY(_In_ POINT point) throw();
// set this rectangle to intersection of two others
BOOL IntersectRect(
_In_ LPCRECT lpRect1,
_In_ LPCRECT lpRect2) throw();
// set this rectangle to bounding union of two others
BOOL UnionRect(
_In_ LPCRECT lpRect1,
_In_ LPCRECT lpRect2) throw();
// set this rectangle to minimum of two others
BOOL SubtractRect(
_In_ LPCRECT lpRectSrc1,
_In_ LPCRECT lpRectSrc2) throw();
// Additional Operations
void operator=(_In_ const RECT& srcRect) throw();
BOOL operator==(_In_ const RECT& rect) const throw();
BOOL operator!=(_In_ const RECT& rect) const throw();
void operator+=(_In_ POINT point) throw();
void operator+=(_In_ SIZE size) throw();
void operator+=(_In_ LPCRECT lpRect) throw();
void operator-=(_In_ POINT point) throw();
void operator-=(_In_ SIZE size) throw();
void operator-=(_In_ LPCRECT lpRect) throw();
void operator&=(_In_ const RECT& rect) throw();
void operator|=(_In_ const RECT& rect) throw();
// Operators returning CRect values
CRect operator+(_In_ POINT point) const throw();
CRect operator-(_In_ POINT point) const throw();
CRect operator+(_In_ LPCRECT lpRect) const throw();
CRect operator+(_In_ SIZE size) const throw();
CRect operator-(_In_ SIZE size) const throw();
CRect operator-(_In_ LPCRECT lpRect) const throw();
CRect operator&(_In_ const RECT& rect2) const throw();
CRect operator|(_In_ const RECT& rect2) const throw();
CRect MulDiv(
_In_ int nMultiplier,
_In_ int nDivisor) const throw();
};
- l, t是矩形左上角的x,y坐标;r,b是矩形右下角的x,y坐标
- srcRect是一个RECT结构
- lpSrcRect是RECT结构的指针
- point 用来指定矩形的左上角,size指定矩形的x,y方向长度
- topLeft, bottomRight是矩形的POINT结构的左上角和右下角点
CRect类及其成员函数的初始化:
// CRect
inline CRect::CRect() throw()
{
left = 0;
top = 0;
right = 0;
bottom = 0;
}
inline CRect::CRect(
_In_ int l,
_In_ int t,
_In_ int r,
_In_ int b) throw()
{
left = l;
top = t;
right = r;
bottom = b;
}
inline CRect::CRect(_In_ const RECT& srcRect) throw()
{
::CopyRect(this, &srcRect);
}
inline CRect::CRect(_In_ LPCRECT lpSrcRect) throw()
{
::CopyRect(this, lpSrcRect);
}
inline CRect::CRect(
_In_ POINT point,
_In_ SIZE size) throw()
{
right = (left = point.x) + size.cx;
bottom = (top = point.y) + size.cy;
}
inline CRect::CRect(
_In_ POINT topLeft,
_In_ POINT bottomRight) throw()
{
left = topLeft.x;
top = topLeft.y;
right = bottomRight.x;
bottom = bottomRight.y;
}
inline int CRect::Width() const throw()
{
return right - left;
}
inline int CRect::Height() const throw()
{
return bottom - top;
}
inline CSize CRect::Size() const throw()
{
return CSize(right - left, bottom - top);
}
inline CPoint& CRect::TopLeft() throw()
{
return *((CPoint*)this);
}
inline CPoint& CRect::BottomRight() throw()
{
return *((CPoint*)this+1);
}
inline const CPoint& CRect::TopLeft() const throw()
{
return *((CPoint*)this);
}
inline const CPoint& CRect::BottomRight() const throw()
{
return *((CPoint*)this+1);
}
inline CPoint CRect::CenterPoint() const throw()
{
return CPoint((left+right)/2, (top+bottom)/2);
}
inline void CRect::SwapLeftRight() throw()
{
SwapLeftRight(LPRECT(this));
}
inline void WINAPI CRect::SwapLeftRight(_Inout_ LPRECT lpRect) throw()
{
LONG temp = lpRect->left;
lpRect->left = lpRect->right;
lpRect->right = temp;
}
inline BOOL CRect::IsRectEmpty() const throw()
{
return ::IsRectEmpty(this);
}
inline BOOL CRect::IsRectNull() const throw()
{
return (left == 0 && right == 0 && top == 0 && bottom == 0);
}
inline BOOL CRect::PtInRect(_In_ POINT point) const throw()
{
return ::PtInRect(this, point);
}
inline void CRect::SetRect(
_In_ int x1,
_In_ int y1,
_In_ int x2,
_In_ int y2) throw()
{
::SetRect(this, x1, y1, x2, y2);
}
inline void CRect::SetRect(
_In_ POINT topLeft,
_In_ POINT bottomRight) throw()
{
::SetRect(this, topLeft.x, topLeft.y, bottomRight.x, bottomRight.y);
}
inline void CRect::SetRectEmpty() throw()
{
::SetRectEmpty(this);
}
inline void CRect::CopyRect(_In_ LPCRECT lpSrcRect) throw()
{
::CopyRect(this, lpSrcRect);
}
inline BOOL CRect::EqualRect(_In_ LPCRECT lpRect) const throw()
{
return ::EqualRect(this, lpRect);
}
inline void CRect::InflateRect(
_In_ int x,
_In_ int y) throw()
{
::InflateRect(this, x, y);
}
inline void CRect::InflateRect(_In_ SIZE size) throw()
{
::InflateRect(this, size.cx, size.cy);
}
inline void CRect::DeflateRect(
_In_ int x,
_In_ int y) throw()
{
::InflateRect(this, -x, -y);
}
inline void CRect::DeflateRect(_In_ SIZE size) throw()
{
::InflateRect(this, -size.cx, -size.cy);
}
inline void CRect::OffsetRect(
_In_ int x,
_In_ int y) throw()
{
::OffsetRect(this, x, y);
}
inline void CRect::OffsetRect(_In_ POINT point) throw()
{
::OffsetRect(this, point.x, point.y);
}
inline void CRect::OffsetRect(_In_ SIZE size) throw()
{
::OffsetRect(this, size.cx, size.cy);
}
inline void CRect::MoveToY(_In_ int y) throw()
{
bottom = Height() + y;
top = y;
}
inline void CRect::MoveToX(_In_ int x) throw()
{
right = Width() + x;
left = x;
}
inline void CRect::MoveToXY(
_In_ int x,
_In_ int y) throw()
{
MoveToX(x);
MoveToY(y);
}
inline void CRect::MoveToXY(_In_ POINT pt) throw()
{
MoveToX(pt.x);
MoveToY(pt.y);
}
inline BOOL CRect::IntersectRect(
_In_ LPCRECT lpRect1,
_In_ LPCRECT lpRect2) throw()
{
return ::IntersectRect(this, lpRect1, lpRect2);
}
inline BOOL CRect::UnionRect(
_In_ LPCRECT lpRect1,
_In_ LPCRECT lpRect2) throw()
{
return ::UnionRect(this, lpRect1, lpRect2);
}
inline BOOL CRect::SubtractRect(
_In_ LPCRECT lpRectSrc1,
_In_ LPCRECT lpRectSrc2) throw()
{
return ::SubtractRect(this, lpRectSrc1, lpRectSrc2);
}
inline void CRect::NormalizeRect() throw()
{
int nTemp;
if (left > right)
{
nTemp = left;
left = right;
right = nTemp;
}
if (top > bottom)
{
nTemp = top;
top = bottom;
bottom = nTemp;
}
}
inline void CRect::InflateRect(_In_ LPCRECT lpRect) throw()
{
left -= lpRect->left;
top -= lpRect->top;
right += lpRect->right;
bottom += lpRect->bottom;
}
inline void CRect::InflateRect(
_In_ int l,
_In_ int t,
_In_ int r,
_In_ int b) throw()
{
left -= l;
top -= t;
right += r;
bottom += b;
}
inline void CRect::DeflateRect(_In_ LPCRECT lpRect) throw()
{
left += lpRect->left;
top += lpRect->top;
right -= lpRect->right;
bottom -= lpRect->bottom;
}
inline void CRect::DeflateRect(
_In_ int l,
_In_ int t,
_In_ int r,
_In_ int b) throw()
{
left += l;
top += t;
right -= r;
bottom -= b;
}
inline CRect CRect::MulDiv(
_In_ int nMultiplier,
_In_ int nDivisor) const throw()
{
return CRect(
::MulDiv(left, nMultiplier, nDivisor),
::MulDiv(top, nMultiplier, nDivisor),
::MulDiv(right, nMultiplier, nDivisor),
::MulDiv(bottom, nMultiplier, nDivisor));
}
- CRect::Width()计算宽度函数
- CRect::Height()计算高度函数
- CRect::TopLeft()计算左上角点函数
- CRect::BottomRight()计算右下角点函数
- CRect::CenterPoint()计算中心点函数
- CRect::InflateRect()扩大矩形函数
- CRect::DeflateRect()缩小矩形函数
- CRect::OffsetRect()移动矩形函数
CRect类的操作符重载:
inline CRect::operator LPRECT() throw()
{
return this;
}
inline CRect::operator LPCRECT() const throw()
{
return this;
}
inline void CRect::operator=(_In_ const RECT& srcRect) throw()
{
::CopyRect(this, &srcRect);
}
inline BOOL CRect::operator==(_In_ const RECT& rect) const throw()
{
return ::EqualRect(this, &rect);
}
inline BOOL CRect::operator!=(_In_ const RECT& rect) const throw()
{
return !::EqualRect(this, &rect);
}
inline void CRect::operator+=(_In_ POINT point) throw()
{
::OffsetRect(this, point.x, point.y);
}
inline void CRect::operator+=(_In_ SIZE size) throw()
{
::OffsetRect(this, size.cx, size.cy);
}
inline void CRect::operator+=(_In_ LPCRECT lpRect) throw()
{
InflateRect(lpRect);
}
inline void CRect::operator-=(_In_ POINT point) throw()
{
::OffsetRect(this, -point.x, -point.y);
}
inline void CRect::operator-=(_In_ SIZE size) throw()
{
::OffsetRect(this, -size.cx, -size.cy);
}
inline void CRect::operator-=(_In_ LPCRECT lpRect) throw()
{
DeflateRect(lpRect);
}
inline void CRect::operator&=(_In_ const RECT& rect) throw()
{
::IntersectRect(this, this, &rect);
}
inline void CRect::operator|=(_In_ const RECT& rect) throw()
{
::UnionRect(this, this, &rect);
}
inline CRect CRect::operator+(_In_ POINT pt) const throw()
{
CRect rect(*this);
::OffsetRect(&rect, pt.x, pt.y);
return rect;
}
inline CRect CRect::operator-(_In_ POINT pt) const throw()
{
CRect rect(*this);
::OffsetRect(&rect, -pt.x, -pt.y);
return rect;
}
inline CRect CRect::operator+(_In_ SIZE size) const throw()
{
CRect rect(*this);
::OffsetRect(&rect, size.cx, size.cy);
return rect;
}
inline CRect CRect::operator-(_In_ SIZE size) const throw()
{
CRect rect(*this);
::OffsetRect(&rect, -size.cx, -size.cy);
return rect;
}
inline CRect CRect::operator+(_In_ LPCRECT lpRect) const throw()
{
CRect rect(this);
rect.InflateRect(lpRect);
return rect;
}
inline CRect CRect::operator-(_In_ LPCRECT lpRect) const throw()
{
CRect rect(this);
rect.DeflateRect(lpRect);
return rect;
}
inline CRect CRect::operator&(_In_ const RECT& rect2) const throw()
{
CRect rect;
::IntersectRect(&rect, this, &rect2);
return rect;
}
inline CRect CRect::operator|(_In_ const RECT& rect2) const throw()
{
CRect rect;
::UnionRect(&rect, this, &rect2);
return rect;
}
CRect类重载了LPCRECT操作符,可以将CRect对象自动转换为CRect指针,为以CRect对象为参数的函数提供自动类型转换,包括InflateRect(), DeflateRect(), Rectangle(), GetClientRect()
文章介绍了MFC中用于图形绘制的CDC类,包括CClientDC、CMetaFileDC、CPaintDC和CWindowDC的用途。CDC类作为图形设备接口的抽象,不直接与硬件交互,而是通过CDC对象处理图形数据。同时,文章详细讲解了CPoint、CSize和CRect这三个辅助类,用于处理点、尺寸和矩形的相关操作。

被折叠的 条评论
为什么被折叠?



