CPoint
類別
類似於 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
右操作 x
CPoint
數的 (或 cx
) 成員,並從 的成員減去 y
cy
右運算元 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
,或以 位移 CPoint
CRect
。 CSize
CPoint
CPoint operator+(SIZE size) const throw();
CPoint operator+(POINT point) const throw();
CRect operator+(const RECT* lpRect) const throw();
參數
lpRect
包含結構或 CRect
物件的指標 RECT
。
傳回值
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)
回 。
從 減 CSize
CPoint
去 會執行與上述相同的計算,但會 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);
另請參閱
意見反應
https://aka.ms/ContentUserFeedback。
即將登場:在 2024 年,我們將逐步淘汰 GitHub 問題作為內容的意見反應機制,並將它取代為新的意見反應系統。 如需詳細資訊,請參閱:提交並檢視相關的意見反應