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. 
我的理解是基于这段话的,但是看他最后的结论一下子弄糊涂了。

解决方案 »

  1.   

    这种象素为单位的坐标怎么可能存在小数位...0.5,0.5转为物理坐标当然是1,1了...而且SetWindowOrgEx还要看你是如何设置这个DC的MAP方式;MAP方式和精度有关,当然可能造成叠加效果了。
      

  2.   

    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)
      

  3.   

    啊……原来只是这个问题啊,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里面的一个例子……那个我现在还没搞懂
      

  4.   

    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 ,看看是否是我理解错误。
      

  5.   

    我本来已经理解清楚了,但是他这么一说,我又迷糊起来了。
    不知道你们看到这里的时候有没有同样的想法,他前后说法不一致。
    当然,很大的可能性是我理解错误,希望能指出我到底错在那里?
    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), ......
    他说这句话到底指的什么意思????????????
    ~~~~~~~~~~~~~~~~~~~~~~~~~~
      

  6.   

    他还专门给出了一个图片,不可能是笔误。
    那么他这句话就和msdn的精神不符,:)
    谢谢ed9er(始祖鸟)给出的msdn的“圣谕”。
      

  7.   

    Section 1 Chapter 5 The GDI Map Mode 
    大家应该都有这本书吧,
    看看他的讲解
      

  8.   

      我知道,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)那么上句中的设备点也应变成相应的点  我前几天才搞清这问题,也干拢了我好久,希望你能看明白
      

  9.   

    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相符合。