類似於 Windows POINT 結構。
語法
class CPoint : public tagPOINT
成員
公用建構函式
| 名稱 | 描述 |
|---|---|
CPoint::CPoint |
建構 CPoint。 |
公用方法
| 名稱 | 描述 |
|---|---|
CPoint::Offset |
將值加入 至 x 的CPoint和 y 成員。 |
公用運算子
| 名稱 | 描述 |
|---|---|
CPoint::operator - |
傳回 和的差異CPoint,或的否定POINT,或CSize兩POINT個 s 之間的差異,或負的SIZE位SIZE移。 |
CPoint::operator != |
檢查兩 POINT者之間的不相等。 |
CPoint::operator + |
傳回和 或 POINT的總CPoint和SIZE,或 CRect 位移。SIZE |
CPoint::operator += |
CPoint藉由新增 SIZE 或POINT來位移。 |
CPoint::operator -= |
CPoint藉由減去 SIZE 或 POINT來位移。 |
CPoint::operator == |
檢查兩 POINT者之間是否相等。 |
備註
它也包含操作 CPoint 和 POINT 結構的成員函式。
CPoint只要使用 結構,POINT就可以使用物件。 這個類別的運算符,與接受CSize對象或SIZE結構互動SIZE,因為兩者是可互換的。
注意
這個類別衍生自 tagPOINT 結構。 (此名稱 tagPOINT 是結構較不常使用的名稱 POINT 。這表示 結構的數據成員 POINT 和 x y是的可存取數據成員 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
指定 x 之 CPoint 成員的值。
initY
指定 y 之 CPoint 成員的值。
initPt
POINT 結構或 CPoint ,指定用來初始化 CPoint的值。
initSize
SIZE 結構或 CSize ,指定用來初始化 CPoint的值。
dwPoint
將 x 成員設定為的低序字 dwPoint ,並將 y 成員設定為 的高序字 dwPoint。
備註
如果未提供引數,x 和 y 成員都會設定為 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
將值加入 至 x 的CPoint和 y 成員。
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量 (POINT或 CPoint)。
size
指定要位移的CPoint量 (SIZE或 CSize)。
範例
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 +=
第一個多載會將 加入 SIZE 。CPoint
void operator+=(SIZE size) throw();
void operator+=(POINT point) throw();
參數
備註
第二個多載會將 加入 POINT 。CPoint
在這兩種情況下,新增的方法是將右操作數的 (或) 成員加入 x 至 x 的成員CPoint,並將右側操作數的 (或cy) 成員加入y至 y 的成員CPoint。cx
例如,將 新增 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();
參數
備註
第二個多載會 POINT 從 CPoint減去 。
在這兩種情況下,減法是藉由從的成員減去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,或以 位移 CPointCRectCSize CPoint
CPoint operator+(SIZE size) const throw();
CPoint operator+(POINT point) const throw();
CRect operator+(const RECT* lpRect) const throw();
參數
傳回值
CPoint,由SIZE位移、CPoint由 POINT位移的 ,或 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 -
使用前兩個多載的其中一個,從減去 CPoint 或 CSize 物件 CPoint。
CSize operator-(POINT point) const throw();
CPoint operator-(SIZE size) const throw();
CRect operator-(const RECT* lpRect) const throw();
CPoint operator-() const throw();
參數
傳回值
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 ,會傳回 由 中指定的 負 x 值 y 所位移的 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);