Confused between logical coordinates and device coordinates in Windows API

感情迁移 提交于 2020-01-23 05:41:07

问题


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?


回答1:


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.

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.

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.

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.

Relevant reading: Coordinate Spaces and Transformations (MSDN)



来源:https://stackoverflow.com/questions/15862205/confused-between-logical-coordinates-and-device-coordinates-in-windows-api

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!