Confused between logical coordinates and device coordinates in Windows API(Windows API 中逻辑坐标和设备坐标之间的混淆)
问题描述
我一直在研究一个 Visual Studio C++ Windows 应用程序项目,它使用了两个函数 SetWindowExt (...) 和 SetViewportExt (...).我对这两个功能的作用以及为什么它们是必要的感到困惑.搜索这些函数,我想到了逻辑坐标和设备坐标的概念.
I have been looking into a Visual Studio C++ Windows application project which used two functions SetWindowExt (...) and SetViewportExt (...). I am confused about what these two functions do and why they are necessary. Searching about these functions, I came to the concept of logical coordinates and device coordinates.
谁能解释一下这两个概念的重要性?
Can anyone please explain what is the importance of these two concepts?
推荐答案
设备坐标是最容易理解的.它们与您使用的设备直接相关,例如屏幕或打印机.
Device coordinates are the simplest to understand. They are directly related to the device that you're using—e.g., the screen or a printer.
例如,让我们看一下屏幕上显示的窗口.设备坐标是相对于特定设备定义的,因此在窗口的情况下,一切都将在客户端坐标中.这意味着原点将是窗口客户区的左上角,y 轴将从上到下运行.所有单位都以像素为单位,因为这是一个屏幕元素.
For an example, let's look at a window displayed on the screen. Device coordinates are defined relative to a particular device, so in the case of a window, everything will be in client coordinates. That means the origin will be the upper-left corner of the window's client area and the y-axis will run from top to bottom. All units are measured in pixels, since this is an on-screen element.
你一直在使用这些,所以你可能已经比你想象的更了解它们了.例如,每当您处理鼠标事件或调整窗口大小时,您都会获取并设置设备坐标.
You use these all the time, so you probably already understand them better than you think. For example, whenever you handle a mouse event or a window resize, you get and set device coordinates.
逻辑坐标考虑当前的映射模式.每个设备上下文 (DC) 都可以应用一个映射模式(GetMapMode 和 SetMapMode).各种可用的映射模式由 MM_Xxx 值定义.这些不同的映射模式中的每一种都会导致原点和 y 轴方向的解释不同.文档会告诉你它们是如何工作的.
Logical coordinates take the current mapping mode into account. Each device context (DC) can have a mapping mode applied to it (GetMapMode and SetMapMode). The various available mapping modes are defined by the MM_Xxx values. Each of these different mapping modes will cause the origin and y-axis direction to be interpreted differently. The documentation will tell you exactly how they work.
当您操作设备上下文(例如,在其上绘制)时,会考虑当前的映射模式,因此您可以使用逻辑坐标.
When you manipulate a device context (e.g., draw onto it), the current mapping mode is taken into account and thus you work with logical coordinates.
使用默认的 MM_TEXT 映射模式,每个逻辑单元映射到一个设备单元(请记住,对于窗口,这将是一个像素),因此不需要转换.在这种映射模式下,逻辑坐标系和设备坐标系的工作方式完全相同.由于这是默认设置,并且可能是您大部分时间使用的默认设置,因此它可能是您困惑的根源.
With the default MM_TEXT mapping mode, each logical unit maps to one device unit (remember, for a window, this would be one pixel), so no conversion is required. In this mapping mode, the logical and device coordinate systems work exactly the same way. And since this is the default and probably the one you work with most of the time, it is probably the source of your confusion.
相关阅读: 坐标空间和变换一个>(MSDN)
这篇关于Windows API 中逻辑坐标和设备坐标之间的混淆的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:Windows API 中逻辑坐标和设备坐标之间的混淆
基础教程推荐
- 我有静态或动态 boost 库吗? 2021-01-01
- 如何将 std::pair 的排序 std::list 转换为 std::map 2022-01-01
- 这个宏可以转换成函数吗? 2022-01-01
- 如何检查GTK+3.0中的小部件类型? 2022-11-30
- 在 C++ 中计算滚动/移动平均值 2021-01-01
- C++结构和函数声明。为什么它不能编译? 2022-11-07
- 如何通过C程序打开命令提示符Cmd 2022-12-09
- 如何在 C++ 中初始化静态常量成员? 2022-01-01
- 常量变量在标题中不起作用 2021-01-01
- 静态库、静态链接动态库和动态链接动态库的 .lib 文件里面是什么? 2021-01-01
