win32中的度量方式

 众所周知,在win32编程中,关于度量的问题是一个及其让人讨厌的问题,在这篇文章里,我将一些关于度量的问题进行一下总结。

 

一.窗口和视口

在win32程序中,映射方式决定了如何将逻辑坐标映射为设备坐标,二设备坐标系完全取决于所使用的获取设备描述表的API函数。

而窗口到视口的映射对于映射方式同样有着巨大的影响。

 

“视口”:它是基于设备坐标(像素)而言的。通常情况下,视口与客户区相同,当然你可以通过使用GetWindowDC或者CreateDC获取设备描述表,以此获取整个屏幕或者屏幕的坐标。

 

“窗口”:窗口是基于逻辑坐标而言的,它的坐标系可以依据你选择的映射方式的改变而改变。

 

在windows下,通过SetViewportOrgEx()和SetWindowportOrgEx()来改变视口和窗口的原点的坐标。

例如:

      SetViewportOrgEx(hdc,cxClient/2,cyClient/2,NULL);                 //将视口的原点设置为整个视口的中心

 

这时候

 

      TextOut(hdc,0,0,Text("Hello"),5);

 

字符将会在视口的中心输出;

 

而你如果使用

      SetWindowportEx(hdc,-cxClient/2,-cyClient/2,NULL);

 

可以达到同样的效果。

 

 

 

二.设备坐标和逻辑坐标

 

在windows中,对于任何消息(即使是WM_SIZE),任何非GDI函数以及部分的GDI函数,均采用设备坐标。从某种程度上来说,映射方式是设备描述表的属性,对于不使用设备描述表句柄作为参数的函数,映射方式自然不会起到作用。

不过,需要注意,GetTextMetrics是使用逻辑单位的。

 

 

三.映射方式

在windows下,存在多种的逻辑坐标映射为设备坐标的映射方式:

  • MM_ANISOTROPIC   Logical units are converted to arbitrary units with arbitrarily scaled axes. Setting the mapping mode to MM_ANISOTROPIC does not change the current window or viewport settings. To change the units, orientation, and scaling, call the SetWindowExt and SetViewportExt member functions.

  • MM_HIENGLISH   Each logical unit is converted to 0.001 inch. Positive x is to the right; positive y is up.

  • MM_HIMETRIC   Each logical unit is converted to 0.01 millimeter. Positive x is to the right; positive y is up.

  • MM_ISOTROPIC   Logical units are converted to arbitrary units with equally scaled axes; that is, 1 unit along the x-axis is equal to 1 unit along the y-axis. Use the SetWindowExt and SetViewportExt member functions to specify the desired units and the orientation of the axes. GDI makes adjustments as necessary to ensure that the x and y units remain the same size.

  • MM_LOENGLISH   Each logical unit is converted to 0.01 inch. Positive x is to the right; positive y is up.

  • MM_LOMETRIC   Each logical unit is converted to 0.1 millimeter. Positive x is to the right; positive y is up.

  • MM_TEXT   Each logical unit is converted to 1 device pixel. Positive x is to the right; positive y is down.

  • MM_TWIPS   Each logical unit is converted to 1/20 of a point. (Because a point is 1/72 inch, a twip is 1/1440 inch.) Positive x is to the right; positive y is up.

这是我从MSDN中摘录的。

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值