谁能帮我解释一下Petzold这些话的意思:

vcbacker 2001-07-17 02:58:09
SetViewportOrgEx (hdc, cxClient / 2, cyClient / 2, NULL) ;
SetWindowOrgEx (hdc, -cxClient / 2, -cyClient / 2, NULL) ;

This means that the logical point (-cxClient/2, -cyClient/2) is mapped to the device point (cxClient/2, cyClient/2), ......

我对这段话极不理解!
他在前面说:
You can achieve the same result with SetWindowOrgEx as you did when you used SetViewportOrgEx:
SetWindowOrgEx (hdc, -cxClient / 2, -cyClient / 2, NULL)
说明这两句话的作用是一样的,并且他很明确地说视口原点是不变的。
为何作用会有“叠加”的效果?
以窗口宽高1,1,MM_TEXT为例,为何窗口原点是(1,1)而不是(0.5,0.5)?
...全文
206 18 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
18 条回复
切换为时间正序
请发表友善的回复…
发表回复
vcbacker 2001-07-18
  • 打赏
  • 举报
回复
这个贴子太长了,请大家到新贴讨论
vcbacker 2001-07-18
  • 打赏
  • 举报
回复
to chendd2001(饿狼传说):
首先感谢你的回答,如果这样理解的确可以解释通,
但是:petzold明确地说:设备原点(0,0)不变!
Regardless of any changes you make to the window and viewport origins, the device point (0, 0) is always the upper left corner of the client area.
而msdn的解释是:
The SetViewportOrgEx function specifies which device point maps to the window origin (0,0).
The SetWindowOrgEx function specifies which window point maps to the viewport origin (0,0).
而petzold前面也说:
SetViewportOrgEx其实做的是设置逻辑点(0,0)对应的设备点!并不是改变设备原点的函数!
这一点和msdn相符合。
chendd2001 2001-07-17
  • 打赏
  • 举报
回复
我知道,SetViewportOrgEx (hdc, cxClient / 2, cyClient / 2, NULL) ;
SetWindowOrgEx (hdc, -cxClient / 2, -cyClient / 2, NULL) ;

这两个函数,只要用一个就能达到效果,两个一起用就叠加效果。

windoworg是逻辑原点 viewportorg是设备原点
1。)如果你仅用setWindowOrgEx(...),相当影含了setViewOrgEX(hdc,0,0,NULL)
这两个函数有次序之分的,
必须setViewOrgEx首先调用。
上面的意思是现在你的逻辑点(-cxClient/2,-cyClient/2)被印射成设备点(0,0)
换句话说,如果setViewportOrgEX不是(0,0)那么上句中的设备点也应变成相应的点

我前几天才搞清这问题,也干拢了我好久,希望你能看明白
vcbacker 2001-07-17
  • 打赏
  • 举报
回复
Section 1 Chapter 5 The GDI Map Mode
大家应该都有这本书吧,
看看他的讲解
vcbacker 2001-07-17
  • 打赏
  • 举报
回复
他还专门给出了一个图片,不可能是笔误。
那么他这句话就和msdn的精神不符,:)
谢谢ed9er(始祖鸟)给出的msdn的“圣谕”。
vcbacker 2001-07-17
  • 打赏
  • 举报
回复
我本来已经理解清楚了,但是他这么一说,我又迷糊起来了。
不知道你们看到这里的时候有没有同样的想法,他前后说法不一致。
当然,很大的可能性是我理解错误,希望能指出我到底错在那里?
SetViewportOrgEx (hdc, cxClient / 2, cyClient / 2, NULL) ;
SetWindowOrgEx (hdc, -cxClient / 2, -cyClient / 2, NULL) ;

This means that the logical point (-cxClient/2, -cyClient/2) is mapped to the device point (cxClient/2, cyClient/2), ......
他说这句话到底指的什么意思????????????
~~~~~~~~~~~~~~~~~~~~~~~~~~
vcbacker 2001-07-17
  • 打赏
  • 举报
回复
to ed9er(始祖鸟):
我也是这样理解阿,但是您看petzold怎么说的:
This means that the logical point (-cxClient/2, -cyClient/2) is mapped to the device point (cxClient/2, cyClient/2)
后来的图片也说明了他认为经过这两个语句以后,窗口的右下角(而不是中间)才是window的原点!
但是他前面的意思应该是中间阿,所以我正是因为这个迷惑阿。
你看一下Section 1 Chapter 5 The GDI Map Mode
This means that the logical point (-cxClient/2, -cyClient/2) is mapped to the device point (cxClient/2, cyClient/2)
这句话我实在无法理解,我认为应该是:
This means that the logical point (-cxClient/2, -cyClient/2) is mapped to the device point (0, 0),这也正是你的观点。
但是要说petzold错了,我有点不敢,:)
你看一下Section 1 Chapter 5 The GDI Map Mode ,看看是否是我理解错误。

ed9er 2001-07-17
  • 打赏
  • 举报
回复
啊……原来只是这个问题啊,easy啦,注意MSDN的解释:
The SetViewportOrgEx function specifies which device point maps to the window origin (0,0).
The SetWindowOrgEx function specifies which window point maps to the viewport origin (0,0).
那么,对于第一个调法,SetViewportOrg,结论很显然
对于第二个调法,SetWindowOrg,参数是负数,也就是把-x,-y放到device coordinates的原点(0,0),而device的(0,0)永远是左上角的那点,MM_TEXT里y是向下为正,那么你向右,向下移动x,y,到屏幕中间,那就是window的原点

我以为你说的是后面bitmap里面的一个例子……那个我现在还没搞懂
vcbacker 2001-07-17
  • 打赏
  • 举报
回复
to davidprg():
你误会了,我说的0.5就是一半的意思,你也可以理解为50,总之是总长度的1/2。
这个问题和精度无关。是petzold所说的我感觉前后不一致,
SetViewportOrgEx (hdc, cxClient / 2, cyClient / 2, NULL) ;
SetWindowOrgEx (hdc, -cxClient / 2, -cyClient / 2, NULL) ;

This means that the logical point (-cxClient/2, -cyClient/2) is mapped to the device point (cxClient/2, cyClient/2),
我认为应该是device point(0,0)
davidprg 2001-07-17
  • 打赏
  • 举报
回复
这种象素为单位的坐标怎么可能存在小数位...0.5,0.5转为物理坐标当然是1,1了...

而且SetWindowOrgEx还要看你是如何设置这个DC的MAP方式;MAP方式和精度有关,当然可能造成叠加效果了。
vcbacker 2001-07-17
  • 打赏
  • 举报
回复
up
vcbacker 2001-07-17
  • 打赏
  • 举报
回复
up
jiagh 2001-07-17
  • 打赏
  • 举报
回复
我也很想知道
vcbacker 2001-07-17
  • 打赏
  • 举报
回复
看过的人应该很多吧,大家说说自己的理解吧
ed9er 2001-07-17
  • 打赏
  • 举报
回复
gz,过会再回来
vcbacker 2001-07-17
  • 打赏
  • 举报
回复
各位在看这一段的时候有没有感到前后矛盾的地方?
我不是大明 2001-07-17
  • 打赏
  • 举报
回复
这里是比较难懂!
vcbacker 2001-07-17
  • 打赏
  • 举报
回复
Here's how the functions work: If you change the viewport origin to (xViewOrg, yViewOrg), the logical point (0, 0) will be mapped to the device point (xViewOrg, yViewOrg). If you change the window origin to (xWinOrg, yWinOrg), the logical point (xWinOrg, yWinOrg) will be mapped to the device point (0, 0), which is the upper left corner. Regardless of any changes you make to the window and viewport origins, the device point (0, 0) is always the upper left corner of the client area.
我的理解是基于这段话的,但是看他最后的结论一下子弄糊涂了。

16,548

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC相关问题讨论
社区管理员
  • 基础类社区
  • AIGC Browser
  • encoderlee
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

        VC/MFC社区版块或许是CSDN最“古老”的版块了,记忆之中,与CSDN的年龄几乎差不多。随着时间的推移,MFC技术渐渐的偏离了开发主流,若干年之后的今天,当我们面对着微软的这个经典之笔,内心充满着敬意,那些曾经的记忆,可以说代表着二十年前曾经的辉煌……
        向经典致敬,或许是老一代程序员内心里面难以释怀的感受。互联网大行其道的今天,我们期待着MFC技术能够恢复其曾经的辉煌,或许这个期待会永远成为一种“梦想”,或许一切皆有可能……
        我们希望这个版块可以很好的适配Web时代,期待更好的互联网技术能够使得MFC技术框架得以重现活力,……

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