Share via


Classe CPoint

Simile alla struttura POINT di Windows.

Sintassi

class CPoint : public tagPOINT

Membri

Costruttori pubblici

Nome Descrizione
CPoint::CPoint Costruisce un oggetto CPoint.

Metodi pubblici

Nome Descrizione
CPoint::Offset Aggiunge valori ai x membri e y dell'oggetto CPoint.

Operatori pubblici

Nome Descrizione
CPoint::operator - Restituisce la differenza di un CPoint oggetto e un SIZEoggetto o la negazione di un POINToggetto o la CSize differenza tra due POINTo l'offset da un valore negativo SIZE.
CPoint::operator != Verifica la disuguaglianza tra due POINTs.
CPoint::operator + Restituisce la somma di un CPoint oggetto e di un SIZE oggetto o POINToppure un CRect offset di un oggetto SIZE.
CPoint::operator += CPoint Offset aggiungendo un SIZE oggetto o POINT.
CPoint::operator -= CPoint Offset sottraendo un SIZE oggetto o POINT.
CPoint::operator == Verifica l'uguaglianza tra due POINT.

Osservazioni:

Include anche funzioni membro per modificare CPoint e POINT strutture.

Un CPoint oggetto può essere utilizzato ovunque venga utilizzata una POINT struttura. Gli operatori di questa classe che interagiscono con un SIZE accettare CSize oggetti o SIZE strutture, poiché i due sono intercambiabili.

Nota

Questa classe è derivata dalla tagPOINT struttura . Il nome tagPOINT è un nome meno comunemente usato per la POINT struttura. Ciò significa che i membri dati della POINT struttura x e y, sono membri dati accessibili di CPoint.

Nota

Per altre informazioni sulle classi di utilità condivise (ad esempio CPoint), vedere Classi condivise.

Gerarchia di ereditarietà

tagPOINT

CPoint

Requisiti

Intestazione:atltypes.h

CPoint::CPoint

Costruisce un oggetto CPoint.

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

Parametri

initX
Specificare il valore del membro x di CPoint.

initY
Specificare il valore del membro y di CPoint.

initPt
POINT struttura o CPoint che specifica i valori utilizzati per inizializzare CPoint.

initSize
SIZE struttura o CSize che specifica i valori utilizzati per inizializzare CPoint.

dwPoint
Imposta il x membro sulla parola di ordine basso di dwPoint e sul y membro sulla parola dell'ordine elevato di dwPoint.

Osservazioni:

Se non viene fornito alcun argomento, i membri x e y vengono impostate su 0.

Esempio

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

Aggiunge valori ai x membri e y dell'oggetto CPoint.

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

Parametri

xOffset
Specifica la quantità di offset del x membro dell'oggetto CPoint.

yOffset
Specifica la quantità di offset del y membro dell'oggetto CPoint.

point
Specifica l'importo (POINT o CPoint) per compensare l'oggetto CPoint.

size
Specifica l'importo (SIZE o CSize) per compensare l'oggetto CPoint.

Esempio

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 ==

Verifica l'uguaglianza tra due POINT.

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

Parametri

point
Contiene una struttura o CPoint un POINT oggetto .

Valore restituito

Diverso da zero se gli POINToggetti sono uguali; in caso contrario, 0.

Esempio

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 !=

Verifica la disuguaglianza tra due POINTs.

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

Parametri

point
Contiene una struttura o CPoint un POINT oggetto .

Valore restituito

Diverso da zero se l'oggetto POINTnon è uguale; in caso contrario, 0.

Esempio

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 +=

Il primo overload aggiunge un SIZE oggetto all'oggetto CPoint.

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

Parametri

size
Contiene una struttura o CSize un SIZE oggetto .

point
Contiene una struttura o CPoint un POINT oggetto .

Osservazioni:

Il secondo overload aggiunge un oggetto POINT all'oggetto CPoint.

In entrambi i casi, l'aggiunta viene eseguita aggiungendo il membro (o ) dell'operando x di destra al x membro di CPoint e aggiungendo il y membro (o cy) dell'operando di destra al y membro dell'oggetto CPoint.cx

Ad esempio, l'aggiunta CPoint(5, -7) a una variabile che contiene CPoint(30, 40) modifica la variabile in CPoint(35, 33).

Esempio

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 -=

Il primo overload sottrae un oggetto SIZE da CPoint.

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

Parametri

size
Contiene una struttura o CSize un SIZE oggetto .

point
Contiene una struttura o CPoint un POINT oggetto .

Osservazioni:

Il secondo overload sottrae un oggetto POINT da CPoint.

In entrambi i casi, la sottrazione viene eseguita sottraendo il x membro (o cx) dell'operando di destra dal x membro di CPoint e sottraendo il y membro (o cy) dell'operando di destra dal y membro dell'oggetto CPoint.

Ad esempio, sottraendo CPoint(5, -7) da una variabile che contiene CPoint(30, 40) le modifiche apportate alla variabile in CPoint(25, 47).

Esempio

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 +

Utilizzare questo operatore per eseguire l'offset da un oggetto o CSize oppure per eseguire l'offset CPoint di un oggetto CRect da un oggetto CPoint.CPoint

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

Parametri

size
Contiene una struttura o CSize un SIZE oggetto .

point
Contiene una struttura o CPoint un POINT oggetto .

lpRect
Contiene un puntatore a una struttura o CRect a un RECT oggetto .

Valore restituito

Oggetto CPoint che viene scostato da un SIZEoggetto , che CPoint viene offset da un POINToggetto o da un CRect offset di un oggetto POINT.

Osservazioni:

Ad esempio, l'utilizzo di uno dei primi due overload per sfalsare il punto in base a un punto CPoint(25, -19)CPoint(15, 5) o a una dimensione CSize(15, 5) restituisce il valore CPoint(40, -14).

L'aggiunta di un CRectPOINT oggetto a restituisce l'oggetto dopo l'offset CRect in base ai x valori e y specificati in POINT. Ad esempio, l'utilizzo dell'ultimo overload per sfalsare un rettangolo CRect(125, 219, 325, 419) in base a un punto CPoint(25, -19) restituisce CRect(150, 200, 350, 400).

Esempio

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 -

Utilizzare uno dei primi due overload per sottrarre un CPoint oggetto o CSize da CPoint.

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

Parametri

point
Struttura POINT o CPoint oggetto .

size
Struttura SIZE o CSize oggetto .

lpRect
Puntatore a una RECT struttura o a un CRect oggetto .

Valore restituito

Oggetto CSize che rappresenta la differenza tra due POINToggetti , un CPoint oggetto offset dalla negazione di un SIZEoggetto , CRect che viene offset dalla negazione di un POINToggetto o un oggetto CPoint che rappresenta la negazione di un oggetto POINT.

Osservazioni:

Il terzo overload esegue l'offset di un oggetto CRect dalla negazione di CPoint. Usare infine l'operatore unario per negare CPoint.

Ad esempio, usando il primo overload per trovare la differenza tra due punti CPoint(25, -19) e CPoint(15, 5) restituisce CSize(10, -24).

La sottrazione di un CSize oggetto da CPoint esegue lo stesso calcolo di quanto sopra, ma restituisce un CPoint oggetto, non un CSize oggetto . Ad esempio, usando il secondo overload per trovare la differenza tra il punto CPoint(25, -19) e la dimensione CSize(15, 5) restituisce CPoint(10, -24).

Sottraendo un rettangolo da un POINT oggetto restituisce l'offset del rettangolo in base ai negativi dei x valori e y specificati in POINT. Ad esempio, l'utilizzo dell'ultimo overload per sfalsare il rettangolo CRect(125, 200, 325, 400) in base al punto CPoint(25, -19) restituisce CRect(100, 219, 300, 419).

Usare l'operatore unario per negare un oggetto POINT. Ad esempio, l'uso dell'operatore unario con il punto CPoint(25, -19) restituisce CPoint(-25, 19).

Esempio

// 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);   

Vedi anche

MDI di esempio MFC
Grafico della gerarchia
POINT Struttura
CRect Classe
CSize Classe