共用方式為


CPoint 類別

類似於 Windows POINT 結構。

語法

class CPoint : public tagPOINT

成員

公用建構函式

名稱 描述
CPoint::CPoint 建構 CPoint

公用方法

名稱 描述
CPoint::Offset 將值加入 至 xCPointy 成員。

公用運算子

名稱 描述
CPoint::operator - 傳回 和 的差異 CPoint ,或 的否定 POINT ,或 CSizePOINT 個 s 之間的差異,或負的 SIZESIZE 移。
CPoint::operator != 檢查兩 POINT 者之間的不相等。
CPoint::operator + 傳回 和 或 POINT 的總 CPointSIZE ,或 CRect 位移。 SIZE
CPoint::operator += CPoint藉由新增 SIZEPOINT 來位移。
CPoint::operator -= CPoint藉由減去 SIZEPOINT 來位移。
CPoint::operator == 檢查兩 POINT 者之間是否相等。

備註

它也包含操作 CPointPOINT 結構的成員函式。

CPoint只要使用 結構, POINT 就可以使用 物件。 這個類別的運算子,與接受 CSize 物件或 SIZE 結構互動 SIZE ,因為兩者是可互換的。

注意

這個類別衍生自 tagPOINT 結構。 (此名稱 tagPOINT 是結構較不常使用的名稱 POINT 。這表示 結構的資料成員 POINTxy 是 的可存取資料成員 CPoint

注意

如需共用公用程式類別的詳細資訊(例如 CPoint ),請參閱 共用類別

繼承階層架構

tagPOINT

CPoint

需求

標頭:atltypes.h

CPoint::CPoint

建構 CPoint 物件。

CPoint() throw();
CPoint(int initX, int initY) throw();
CPoint(POINT initPt) throw();
CPoint(SIZE initSize) throw();
CPoint(LPARAM dwPoint) throw();

參數

initX
指定 xCPoint 成員的值。

initY
指定 yCPoint 成員的值。

initPt
POINT 結構或 CPoint ,指定用來初始化 CPoint 的值。

initSize
SIZE 結構或 CSize ,指定用來初始化 CPoint 的值。

dwPoint
x 成員設定為 的低序字 dwPoint ,並將 y 成員設定為 的高序字 dwPoint

備註

如果未提供引數,xy 成員都會設定為 0。

範例

CPoint   ptTopLeft(0, 0);
// works from a POINT, too

POINT   ptHere;
ptHere.x = 35;
ptHere.y = 95;

CPoint   ptMFCHere(ptHere);

// works from a SIZE
SIZE   sHowBig;
sHowBig.cx = 300;
sHowBig.cy = 10;

CPoint ptMFCBig(sHowBig);
// or from a DWORD

DWORD   dwSize;
dwSize = MAKELONG(35, 95);

CPoint ptFromDouble(dwSize);
ASSERT(ptFromDouble == ptMFCHere);

CPoint::Offset

將值加入 至 xCPointy 成員。

void Offset(int xOffset, int yOffset) throw();
void Offset(POINT point) throw();
void Offset(SIZE size) throw();

參數

xOffset
指定要位移 x 的成員 CPoint 數量。

yOffset
指定要位移 y 的成員 CPoint 數量。

point
指定要位移 的 CPoint 量 ( POINTCPoint )。

size
指定要位移 的 CPoint 量 ( SIZECSize )。

範例

CPoint   ptStart(100, 100);
ptStart.Offset(35, 35);

CPoint   ptResult(135, 135);
ASSERT(ptStart == ptResult);

// works with POINT, too

ptStart = CPoint(100, 100);
POINT pt;

pt.x = 35;
pt.y = 35;

ptStart.Offset(pt);

ASSERT(ptStart == ptResult);

// works with SIZE, too

ptStart = CPoint(100, 100);
SIZE size;

size.cx = 35;
size.cy = 35;

ptStart.Offset(size);

ASSERT(ptStart == ptResult);   

CPoint::operator ==

檢查兩 POINT 者之間是否相等。

BOOL operator==(POINT point) const throw();

參數

point
包含 POINT 結構或 CPoint 物件。

傳回值

如果 s 相等,則為 POINT 非零,否則為 0。

範例

CPoint ptFirst(256, 128);
CPoint ptTest(256, 128);

ASSERT(ptFirst == ptTest);

// works with POINTs, too

POINT pt;
pt.x = 256;
pt.y = 128;

ASSERT(ptTest == pt);

// note that pt == ptTest isn't correct!   

CPoint::operator !=

檢查兩 POINT 者之間的不相等。

BOOL operator!=(POINT point) const throw();

參數

point
包含 POINT 結構或 CPoint 物件。

傳回值

如果 不相等則 POINT 為非零,否則為 0。

範例

CPoint ptFirst(256, 128);
CPoint ptTest(111, 333);

ASSERT(ptFirst != ptTest);

// works with POINTs, too

POINT pt;
pt.x = 333;
pt.y = 111;

ASSERT(ptTest != pt);

// note that pt != ptTest isn't correct!   

CPoint::operator +=

第一個多載會將 加入 SIZECPoint

void operator+=(SIZE size) throw();
void operator+=(POINT point) throw();

參數

size
包含 SIZE 結構或 CSize 物件。

point
包含 POINT 結構或 CPoint 物件。

備註

第二個多載會將 加入 POINTCPoint

在這兩種情況下,新增的方法是將右運算元的 (或) 成員加入 xx 的成員 CPoint ,並將右側運算元的 (或 cy ) 成員加入 yy 的成員 CPointcx

例如,將 新增 CPoint(5, -7) 至包含 CPoint(30, 40) 將變數變更為 CPoint(35, 33) 的變數。

範例

CPoint   ptStart(100, 100);
CSize   szOffset(35, 35);

ptStart += szOffset;

CPoint   ptResult(135, 135);

ASSERT(ptResult == ptStart);

// also works on SIZE

ptStart = CPoint(100, 100);

SIZE   sz;
sz.cx = 35;
sz.cy = 35;

ptStart += sz;

ASSERT(ptResult == ptStart);   

CPoint::operator -=

第一個多載會從 CPoint 減去 SIZE

void operator-=(SIZE size) throw();
void operator-=(POINT point) throw();

參數

size
包含 SIZE 結構或 CSize 物件。

point
包含 POINT 結構或 CPoint 物件。

備註

第二個多載會 POINTCPoint 減去 。

在這兩種情況下,減法是藉由從 的成員減去 x 右操作 xCPoint 數的 (或 cx ) 成員,並從 的成員減去 ycy 右運算元 y 的成員 CPoint

例如,從包含 CPoint(30, 40) 將變數變更為 的變數減 CPoint(5, -7)CPoint(25, 47)

範例

CPoint   ptStart(100, 100);
CSize   szOffset(35, 35);

ptStart -= szOffset;

CPoint   ptResult(65, 65);

ASSERT(ptResult == ptStart);

// also works on SIZE

ptStart = CPoint(100, 100);

SIZE   sz;
sz.cx = 35;
sz.cy = 35;

ptStart -= sz;

ASSERT(ptResult == ptStart);   

CPoint::operator +

使用此運算子來依 或 物件位移 CPoint ,或以 位移 CPointCRectCSizeCPoint

CPoint operator+(SIZE size) const throw();
CPoint operator+(POINT point) const throw();
CRect operator+(const RECT* lpRect) const throw();

參數

size
包含 SIZE 結構或 CSize 物件。

point
包含 POINT 結構或 CPoint 物件。

lpRect
包含結構或 CRect 物件的指標 RECT

傳回值

CPoint,由 SIZE 位移、 CPointPOINT 位移的 ,或 CRect 由 位移的 POINT

備註

例如,使用前兩個多載的其中一個,以點或大小 CSize(15, 5) 來位移點 CPoint(25, -19) 會傳回值 CPoint(40, -14)CPoint(15, 5)

CRect將 加入 至 POINT 會傳回 CRect 之後,由 x 中指定的 和 y 值所位移。 POINT 例如,使用最後一個多載以點 CPoint(25, -19) 傳回 CRect(150, 200, 350, 400) 來位移矩形 CRect(125, 219, 325, 419)

範例

CPoint   ptStart(100, 100);
CSize   szOffset(35, 35);
CPoint   ptEnd;

ptEnd = ptStart + szOffset;

CPoint   ptResult(135, 135);

ASSERT(ptResult == ptEnd);

// also works on SIZE

ptStart = CPoint(100, 100);

SIZE   sz;
sz.cx = 35;
sz.cy = 35;

ptEnd = ptStart + sz;

ASSERT(ptResult == ptEnd);   

CPoint::operator -

使用前兩個多載的其中一個,從 減去 CPointCSize 物件 CPoint

CSize operator-(POINT point) const throw();
CPoint operator-(SIZE size) const throw();
CRect operator-(const RECT* lpRect) const throw();
CPoint operator-() const throw();

參數

point
POINT結構或 CPoint 物件。

size
SIZE結構或 CSize 物件。

lpRect
結構或 CRect 物件的指標 RECT

傳回值

CSize,其為兩 POINT 個 s 之間的差異, CPoint 其會由 的否定 SIZE 位移、 CRect 由 的否定 POINT 所位移,或 CPoint 為 否定的 POINT

備註

第三個多載會 CRect 以 的否定 CPoint 位移 。 最後,使用一元運算子來否定 CPoint

例如,使用第一個多載來尋找兩個點 CPoint(25, -19) 之間的差異,並 CPoint(15, 5)CSize(10, -24) 回 。

從 減 CSizeCPoint 去 會執行與上述相同的計算,但會 CPoint 傳回 物件,而不是 CSize 物件。 例如,使用第二個多載來尋找點 CPoint(25, -19) 與大小 CSize(15, 5) 之間的差異會傳 CPoint(10, -24) 回 。

從 減去矩形 POINT ,會傳回 由 中指定的 負 xy 所位移的 POINT 矩形。 例如,使用最後一個多載來位移矩形 CRect(125, 200, 325, 400) 的點 CPoint(25, -19) 會傳 CRect(100, 219, 300, 419) 回 。

使用一元運算子來否定 POINT 。 例如,使用具有 點 CPoint(25, -19) 的一元運算子會傳 CPoint(-25, 19) 回 。

範例

// example for CPoint subtraction
CPoint   ptStart(100, 100);
CSize   szOffset(35, 35);
CPoint   ptEnd;

ptEnd = ptStart - szOffset;

CPoint   ptResult(65, 65);

ASSERT(ptResult == ptEnd);

// also works on SIZE

ptStart = CPoint(100, 100);

SIZE   sz;
sz.cx = 35;
sz.cy = 35;

ptEnd = ptStart - sz;

ASSERT(ptResult == ptEnd);

// example for CPoint unary operator
CPoint   pt(35, 35);
pt = -pt;

CPoint ptNeg(-35, -35);
ASSERT(pt == ptNeg);   

另請參閱

MFC 範例 MDI
階層架構圖表
POINT 結構
CRect
CSize