Logical coordinate system device coordinate system client coordinate system screen coordinate system

Source: Internet
Author: User

(1) Windows coordinate system

The Windows coordinate system is divided into logical and device coordinate systems, both of which are supported by GDI. In general, GDI's text and graphics output functions use logical coordinates, while the mouse position in the client area is moved or the mouse is pressed with device coordinates.

The <1> logical coordinate system (Logical coordinate) is a DC-oriented coordinate system that does not take into account the specific device type, and when drawing, Windows converts the logical coordinates to device coordinates based on the mapping mode currently set.

<2> equipment coordinates (device coordinate), also known as physical coordinates (physical coordinate), refer to the coordinates on the output device. Typically, the device coordinates on the screen are called screen coordinates. Device coordinates specify the position of the object by the horizontal distance and vertical distance of the object from the upper-left corner of the window, expressed in pixels, the x-axis of the device coordinate is positive, the y-axis is positive, and the coordinate origin is in the upper-left corner of the window, not in the upper-left corner of the device display area.

Equipment Coordinate system is divided into screen coordinate system, window coordinate system and client area coordinate system three kinds of independent coordinate system.

    • The screen coordinate system is the origin of the upper-left corner of the screen, and some functions related to the entire screen use screen coordinates such as GetCursorPos (), Setcursorpos (), CreateWindow (), MoveWindow (). The pop-up menu also uses screen coordinates.
    • The window coordinate system is the origin of the coordinates in the upper-left corner of the window, including the window title bar, menu bar, and toolbar.
    • The customer area coordinate system is the origin point in the upper left corner of the window client area, which is mainly used for drawing output and window message processing of the client area. The coordinate parameter of the mouse message uses the client area coordinates, and the CDC class drawing member function uses the logical coordinates that correspond to the client area coordinates.

The following three are the physical coordinates of the display device , which are represented on the screen by real physical pixels

    • Screen coordinates: Origin (0,0) in the upper-left corner of the screen
    • Window coordinates: Origin (0,0) in the upper-left corner of the window (including non-client areas, such as the title bar)
    • client area coordinates Client-window coordinates: Origin (0,0) in the upper-left corner of the customer window

Logical coordinates are the coordinates that GDI functions use to display data on the screen, and the logical coordinates are not justified unless they are associated with physical coordinates. Windows relies on the mapping mode to interpret logical coordinates. For example, the default mode is Mm_text, in which the physical coordinates and the logical coordinates are one to the other.

Logical coordinates (Logical coordinate) are the coordinates that the system uses as records. In the default mode (Mm_text), the direction and units of the logical coordinates are the same as the direction and units of the device coordinates, are expressed in pixels, the x-axis is positive, the y-axis is positive, and the coordinate origin is in the upper-left corner of the window. Logical and device coordinates even in the default mode, their values may not be the same, except in the following two cases:
1. Window is not a scrolling window
2. The window is a scrolling window, but the vertical scrollbar is at the top of the scroll border and the horizontal scroll bar is at the leftmost end, but if you move the scroll bar, the coordinates are inconsistent.
The coordinate position of the mouse coordinates in the VC is represented by the device coordinates, but all GDI plots are represented by the logical coordinates, so when drawing with the mouse, the device coordinates must be converted to logic coordinates, and the device coordinates can be converted to logical coordinates using the CDC function Dptolp (). You can also use LPTODP () to convert logical coordinates into device coordinates.

(2) mutual conversion between coordinates

When programming, it is sometimes necessary to convert between three device coordinates or with logical coordinates, depending on the current situation.

MFC provides two functions for CDC::D PTOLP () and CDC:: LPTODP () for mutual conversion between device coordinates and logical coordinates.

MFC provides two functions Cwnd::screentoclient () and Cwnd::clienttoscreen () to convert the screen coordinates to the client area coordinates.

(3) Mapping mode

The mapping mode determines the coordinate system in which the drawing is drawn, defining the actual size of the logical units, the direction of the coordinate growth, and the coordinates origin of all mapping modes in the upper-left corner of the device output area, such as the customer or print area. In addition, for some mapping modes, the user can also customize the length and width of the window to set the physical extent of the view area.

Windows defines 8 mapping modes, as shown in the following table.

Attention:
First, remember two points:
1. The (0, 0) point of the device coordinates is always the upper-left corner of the customer area.
2. The points we specify at the time of drawing are all logical coordinate points.
Coordinate transformation
Call CDC::LPTODP to convert the logical coordinates to device coordinates;
High-use CDC::D PTOLP can convert device coordinates to logical coordinates;
What coordinate system do you use?
You can assume that all member functions of the CDC take logical coordinates as arguments
You can assume that all member functions of CWnd use device coordinates as their parameters

Device coordinates should be considered in all selected test operations. The definition of a region should be in device coordinates.
Some functions like CRect::P tinrect are only guaranteed to have the correct results when using device coordinate parameters.
Save some values that need to be used for long periods in logical or physical coordinates. If you use logical coordinates to hold the coordinates of a point, the coordinates of that point are no longer valid as long as the user scrolls through the window.
The coordinates obtained under the mouse click event are device coordinates!
Move Origin Point
Cdc::setviewportorg () Move the origin of the viewport cdc::setwindwosorg () Move the origin of the window
Under normal circumstances, only one of them can be used, while two will make a mess.
Get device information Get system resolution
CCLIENTDC DC (this);
int cx = DC. GetDeviceCaps (Horzres);
int cy = DC. GetDeviceCaps (Vertres);

Logical coordinate system device coordinate system client coordinate system screen coordinate system

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.