MFC中的CPoint类仅支持INT整型数据,我要使用这个类表示DOUBLE的数据怎么办

pctongxie 2014-02-23 06:38:58
MFC中CPoint的构造函数只支持int类型的数据,可是我要使用double类型的数据来表示一个点,怎么办呢,这样直接转换的话会丢失精度,有没有办法解决这个问题?
举个例子:
double x=1.234;
double y=2.354;
CPoint.x=x;
CPoint.y=y;
这样会丢失精度怎么办?
...全文
604 16 打赏 收藏 转发到动态 举报
写回复
用AI写文章
16 条回复
切换为时间正序
请发表友善的回复…
发表回复
cbNotes 2014-03-10
  • 打赏
  • 举报
回复
POINTF typedef struct tagPOINTF { FLOAT x; FLOAT y; } POINTF, *LPPOINTF; http://msdn.microsoft.com/query/dev10.query?appId=Dev10IDEF1&l=EN-US&k=k(POINTF);k(DevLang-%22C%2B%2B%22);k(TargetOS-WINDOWS)&rd=true
赵4老师 2014-02-27
  • 打赏
  • 举报
回复
世界坐标是浮点数,设备坐标是整数。
pctongxie 2014-02-27
  • 打赏
  • 举报
回复
引用 13 楼 zhao4zhong1 的回复:
参考Microsoft SDK\samples\multimedia\Gdi\WinNT\WxForm\*.*
你说的这个是世界坐标系转换的吧,用于平移、缩放、剪切图形。我还不是太了解,跟我说的问题联系在哪
赵4老师 2014-02-25
  • 打赏
  • 举报
回复
参考Microsoft SDK\samples\multimedia\Gdi\WinNT\WxForm\*.*
buyong 2014-02-24
  • 打赏
  • 举报
回复
double x=1.234; double y=2.354; CPoint.x=x*1000; CPoint.y=y*1000;
沙尘暗影 2014-02-24
  • 打赏
  • 举报
回复
自己写一个呗
cbNotes 2014-02-24
  • 打赏
  • 举报
回复
CPointF
赵4老师 2014-02-24
  • 打赏
  • 举报
回复
SetWorldTransform The SetWorldTransform function sets a two-dimensional linear transformation between world space and page space for the specified device context. This transformation can be used to scale, rotate, shear, or translate graphics output. BOOL SetWorldTransform( HDC hdc, // handle of device context CONST XFORM *lpXform // address of transformation data ); Parameters hdc Handle to the device context. lpXform Pointer to an XFORM structure that contains the transformation data. Return Values If the function succeeds, the return value is nonzero. If the function fails, the return value is zero. Windows NT: To get extended error information, callGetLastError. Remarks For any coordinates (x, y) in world space, the transformed coordinates in page space (x', y') can be determined by the following algorithm: x' = x * eM11 + y * eM21 + eDx, y' = x * eM12 + y * eM22 + eDy, where the transformation matrix is represented by the following: | eM11 eM12 0 | | eM21 eM22 0 | | eDx eDy 1 | The mapping mode (defined by the current window and viewport extents origins) serves to define units and scales. The world transformation is usually used to scale or rotate logical images in a device-independent way. The default world transformation is the identity matrix with zero offset. The SetWorldTransform function will fail unless the graphics mode for the given device context has been set to GM_ADVANCED by previously calling the SetGraphicsMode function. Likewise, it will not be possible to reset the graphics mode for the device context to the default GM_COMPATIBLE mode, unless the world transformation has first been reset to the default identity transformation by calling SetWorldTransform or ModifyWorldTransform. QuickInfo Windows NT: Requires version 3.1 or later. Windows: Unsupported. Windows CE: Unsupported. Header: Declared in wingdi.h. Import Library: Use gdi32.lib. See Also Coordinate Spaces and Transformations Overview, Coordinate Space and Transformation Functions, GetWorldTransform, ModifyWorldTransform, SetGraphicsMode, SetMapMode, SetViewportExtEx, SetViewportOrgEx, SetWindowExtEx, SetWindowOrgEx, XFORM
vipcxj 2014-02-24
  • 打赏
  • 举报
回复
引用 2 楼 u012883857 的回复:
我也想到定义一个自己的点类,但是我还要用MFC的函数啊,比如,我要画一条直线,只能用MoveTo(CPoint point),LineTo(CPoint point)来进行,这两个函数的参数要求必须是CPoint类,那我自己定义的类也用不上啊,难道还要自己写划线的函数?
那就像我说的那样,是你用错了,既然API是要求整数的,你弄个小数有何意义,你再double,也没法提高精度,人家API根本不认
神-气 2014-02-24
  • 打赏
  • 举报
回复
屏幕坐标不可能为小数,你这double用了等于没用。
jiandingzhe 2014-02-24
  • 打赏
  • 举报
回复
1:你可以选择不用MFC画图。 2:你可以选择在调用画图API的时候才转换类型。
pctongxie 2014-02-24
  • 打赏
  • 举报
回复
引用 9 楼 buyong 的回复:
double x=1.234; double y=2.354; CPoint.x=x*1000; CPoint.y=y*1000;
这方法应该可以用
pctongxie 2014-02-24
  • 打赏
  • 举报
回复
引用 5 楼 vipcxj 的回复:
[quote=引用 2 楼 u012883857 的回复:] 我也想到定义一个自己的点类,但是我还要用MFC的函数啊,比如,我要画一条直线,只能用MoveTo(CPoint point),LineTo(CPoint point)来进行,这两个函数的参数要求必须是CPoint类,那我自己定义的类也用不上啊,难道还要自己写划线的函数?
那就像我说的那样,是你用错了,既然API是要求整数的,你弄个小数有何意义,你再double,也没法提高精度,人家API根本不认[/quote] 恩啊 我现在就是想解决这个问题啊 不知道有没有好的办法
pctongxie 2014-02-24
  • 打赏
  • 举报
回复
引用 7 楼 cbNotes 的回复:
CPointF
CPointF是什么?
pctongxie 2014-02-23
  • 打赏
  • 举报
回复
我也想到定义一个自己的点类,但是我还要用MFC的函数啊,比如,我要画一条直线,只能用MoveTo(CPoint point),LineTo(CPoint point)来进行,这两个函数的参数要求必须是CPoint类,那我自己定义的类也用不上啊,难道还要自己写划线的函数?
vipcxj 2014-02-23
  • 打赏
  • 举报
回复
那自己弄个MyCPoint。如果API要求必须是CPoint,那么说明API只要求整形,你用double就是错的。如果你自己的程序需要类似CPoint的结构,并且需要double,那么你就自己写个CPoint嘛,因为现成的CPoint已经满足不了你的需要了

64,654

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

试试用AI创作助手写篇文章吧