我写了一个类CPoint1 它基于tagPOINT1 结构。代码:typedef struct tagPOINT1
{
long double x;
long double y;
} POINT1;
class CPoint1 : public tagPOINT1
{
public:
// Constructors // create an uninitialized point
CPoint1();
// create from two integers
CPoint1(double initX, double initY);
// create from another point
CPoint1(POINT1 initPt);
// create from a size
CPoint1(SIZE initSize);
// create from a dword: x = LOWORD(dw) y = HIWORD(dw)
CPoint1(DWORD dwPoint);// Operations// translate the point
void Offset(double xOffset, double yOffset);
void Offset(POINT1 point);
void Offset(SIZE size); BOOL operator==(POINT1 point) const;
BOOL operator!=(POINT1 point) const;
void operator+=(SIZE size);
void operator-=(SIZE size);
void operator+=(POINT1 point);
void operator-=(POINT1 point);// Operators returning CPoint values
CPoint1 operator+(SIZE size) const;
CPoint1 operator-(SIZE size) const;
CPoint1 operator-() const;
CPoint1 operator+(POINT1 point) const;
};
CPoint1::CPoint1()
{ /* random filled */ }
CPoint1::CPoint1(double initX, double initY)
{ x = initX; y = initY; }
CPoint1::CPoint1(POINT1 initPt)
{ *(POINT1*)this = initPt; }
CPoint1::CPoint1(SIZE initSize)
{ *(SIZE*)this = initSize; } CPoint1::CPoint1(DWORD dwPoint)
{
x = (short)LOWORD(dwPoint);
y = (short)HIWORD(dwPoint);
}
void CPoint1::Offset(double xOffset, double yOffset)
{ x += xOffset; y += yOffset; }
void CPoint1::Offset(POINT1 point)
{ x += point.x; y += point.y; }
void CPoint1::Offset(SIZE size)
{ x += size.cx; y += size.cy; }
BOOL CPoint1::operator==(POINT1 point) const
{ return (x == point.x && y == point.y); }
BOOL CPoint1::operator!=(POINT1 point) const
{ return (x != point.x || y != point.y); }
void CPoint1::operator+=(SIZE size)
{ x += size.cx; y += size.cy; }
void CPoint1::operator-=(SIZE size)
{ x -= size.cx; y -= size.cy; }
void CPoint1::operator+=(POINT1 point)
{ x += point.x; y += point.y; }
void CPoint1::operator-=(POINT1 point)
{ x -= point.x; y -= point.y; }
CPoint1 CPoint1::operator+(SIZE size) const
{ return CPoint1(x + size.cx, y + size.cy); }
CPoint1 CPoint1::operator-(SIZE size) const
{ return CPoint1(x - size.cx, y - size.cy); }
CPoint1 CPoint1::operator-() const
{ return CPoint1(-x, -y); }
CPoint1 CPoint1::operator+(POINT1 point) const
{ return CPoint1(x + point.x, y + point.y); }然后我在鼠标按下时调用。
void CDemo2View::OnLButtonDown(UINT nFlags, CPoint1 point) //已改为我的类
{
// TODO: Add your message handler code here and/or call default
CDC * pDC=GetDC();
double x=point.x+100;
double y=point.y+100;
pDC->MoveTo(50,50);
pDC->LineTo(x,y);
ReleaseDC(pDC);
}
结果取出的xy没有值,请问这是为什么?
谢谢
{
long double x;
long double y;
} POINT1;
class CPoint1 : public tagPOINT1
{
public:
// Constructors // create an uninitialized point
CPoint1();
// create from two integers
CPoint1(double initX, double initY);
// create from another point
CPoint1(POINT1 initPt);
// create from a size
CPoint1(SIZE initSize);
// create from a dword: x = LOWORD(dw) y = HIWORD(dw)
CPoint1(DWORD dwPoint);// Operations// translate the point
void Offset(double xOffset, double yOffset);
void Offset(POINT1 point);
void Offset(SIZE size); BOOL operator==(POINT1 point) const;
BOOL operator!=(POINT1 point) const;
void operator+=(SIZE size);
void operator-=(SIZE size);
void operator+=(POINT1 point);
void operator-=(POINT1 point);// Operators returning CPoint values
CPoint1 operator+(SIZE size) const;
CPoint1 operator-(SIZE size) const;
CPoint1 operator-() const;
CPoint1 operator+(POINT1 point) const;
};
CPoint1::CPoint1()
{ /* random filled */ }
CPoint1::CPoint1(double initX, double initY)
{ x = initX; y = initY; }
CPoint1::CPoint1(POINT1 initPt)
{ *(POINT1*)this = initPt; }
CPoint1::CPoint1(SIZE initSize)
{ *(SIZE*)this = initSize; } CPoint1::CPoint1(DWORD dwPoint)
{
x = (short)LOWORD(dwPoint);
y = (short)HIWORD(dwPoint);
}
void CPoint1::Offset(double xOffset, double yOffset)
{ x += xOffset; y += yOffset; }
void CPoint1::Offset(POINT1 point)
{ x += point.x; y += point.y; }
void CPoint1::Offset(SIZE size)
{ x += size.cx; y += size.cy; }
BOOL CPoint1::operator==(POINT1 point) const
{ return (x == point.x && y == point.y); }
BOOL CPoint1::operator!=(POINT1 point) const
{ return (x != point.x || y != point.y); }
void CPoint1::operator+=(SIZE size)
{ x += size.cx; y += size.cy; }
void CPoint1::operator-=(SIZE size)
{ x -= size.cx; y -= size.cy; }
void CPoint1::operator+=(POINT1 point)
{ x += point.x; y += point.y; }
void CPoint1::operator-=(POINT1 point)
{ x -= point.x; y -= point.y; }
CPoint1 CPoint1::operator+(SIZE size) const
{ return CPoint1(x + size.cx, y + size.cy); }
CPoint1 CPoint1::operator-(SIZE size) const
{ return CPoint1(x - size.cx, y - size.cy); }
CPoint1 CPoint1::operator-() const
{ return CPoint1(-x, -y); }
CPoint1 CPoint1::operator+(POINT1 point) const
{ return CPoint1(x + point.x, y + point.y); }然后我在鼠标按下时调用。
void CDemo2View::OnLButtonDown(UINT nFlags, CPoint1 point) //已改为我的类
{
// TODO: Add your message handler code here and/or call default
CDC * pDC=GetDC();
double x=point.x+100;
double y=point.y+100;
pDC->MoveTo(50,50);
pDC->LineTo(x,y);
ReleaseDC(pDC);
}
结果取出的xy没有值,请问这是为什么?
谢谢
解决方案 »
- 【统计帖】不用任何翻译软件的话,大家能不能看懂英文的MSDN?
- vc2008 mfc 对话框设置器的标尺的单位是什么啊?
- 500分,求高人翻译以下代码为:C++,谢谢!!另开4贴散分,在线等候!!高手前辈请进!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
- 请问MDI风格的MFC程序中 CMyView(派生自CView)的窗口函数是什么?
- 如何用VC在硬盘上申请一段空间?在线等提示
- 在单机环境下,可否能用TCP实现客户机/服务器简单的聊天程序,
- 关于safe array 和asp的问题
- 关于指针问题?
- 关于CListBox的水平滚动条问题,谢谢!
- 请各位介绍几本学习openGL的书
- 如何修改????
- http里面的中文是怎么编码的?
这样不行。
你可以使用原来的
OnLButtonDown(UINT nFlags, CPoint point)
{
CPoint1 p = point;
p ,,,,,
}