Confusion between logical and device coordinates in the Windows API

I was studying a Visual Studio C ++ Windows application project that used the two functions SetWindowExt (...) and SetViewportExt (...) . I am confused by what these two functions do and why they are necessary. Searching for these functions, I came to the concept of logical coordinates and device coordinates.

Can someone explain what is the importance of these two concepts?

+4
source share
1 answer

The coordinates of the device are the easiest to understand. They are directly related to the device used - for example, a screen or printer.

As an example, consider the window displayed on the screen. The coordinates of the device are determined relative to a specific device, so in the case of a window everything will be in the coordinates of the client. This means that the source will be the upper left corner of the window window area, and the y axis will be executed from top to bottom. All units are measured in pixels, as this is an element on the screen.

You use them all the time, so you probably already understand them better than you think. For example, whenever you handle a mouse event or window resizing, you get and set the coordinates of the device.

Logical coordinates take into account the current display mode. Each device context (DC) can have a display mode applicable to it ( GetMapMode and SetMapMode ). The various available display modes are determined by the values ​​of MM_Xxx . Each of these different display modes will interpret the start direction and y axis differently. The documentation will tell you exactly how they work.

When you manipulate a device’s context (for example, pull it on it), the current matching mode is taken into account and, therefore, you work with logical coordinates.

In the default display mode, MM_TEXT each logical block is mapped to one block of the device (remember that for the window it will be one pixel), so conversion is not required. In this mapping mode, logical and coordinate systems work exactly the same. And since this is the default and probably the one you work with most of the time, this is probably the source of your confusion.

Relevant Reading: Coordinate Spaces and Transformations (MSDN)

+10
source

All Articles