The coordinate mechanism of MFC

Source: Internet
Author: User

Reference documents:

Liu Tao http://tech.sina.com.cn/s/2005-06-20/1143640450.shtml

First, the basic knowledge
 
 

(a) logical coordinates. Logical coordinates are device independent, and by default, a logical unit equals one pixel in the device. It is the basis for realizing what "WYSIWYG" means. For example, when a programmer calls the LineTo function to draw a line with a length of 25.4mm (1 inches), he simply uses the appropriate mapping mode, and does not need to consider what device the output is.    If the device is a VGA monitor, Windows automatically converts it to 96 pixels, and Windows automatically converts it to 300 pixels if the device is a 300dpi laser printer. (ii) Equipment coordinates. Graphics output, Windows maps the logical coordinates specified in the GDI function to device coordinates, in all device coordinate systems, the units are pixel-specific, the horizontal values increase from left to right (positive direction to right), and the vertical values increase from top to bottom (positive direction downward).    Windows includes the following 3 device coordinates to meet a variety of different needs: 1, customer area coordinates, including the customer area of the application, the upper-left corner of the customer area is (0, 0). 2, screen coordinates, including the entire screen, the upper left corner of the screen is (0, 0). Screen coordinates are used in Wm_move messages (for non-child windows) and in the following Windows functions: CreateWindow and MoveWindow (both for non-child windows), GetMessage, GetCursorPos, GetWindowRect , Windowfrompoint and setbrushorg. With functions ClientToScreen and screentoclient, you can convert customer area coordinates to screen area coordinates, or vice versa.
3, full window coordinates, including a program of the entire window, including the title bar, menu, scroll bar and window box, the upper left corner of the window is (0,0). You can convert a logical unit to a window "coordinate by using the GETWINDOWDC window device environment.
(c) mapping. mapping defines how Windows maps the logical coordinates specified in GDI functions to device coordinates. In the following section we will describe common mapping methods.

 

In practice, we refer to the coordinate system where the logical coordinates are called "Windows", and the coordinate system in which the device coordinates are called "viewports". Windows relies on logical coordinates, which can be pixels, millimeters, or other scales. Knowledge Points:

1, GDI functions, image manipulation, drawing and so on are almost all in the logical coordinates. Very few of them, such as GetDeviceCaps, are GDI functions, but use device coordinates. The window completes the work of converting from logical coordinates to device coordinates.

2, almost all non-GDI functions, all use the device coordinates. In addition, MFC received the message, mouse movement wm_mousemove, mouse click Wm_lbuttondown, there are window redraw wm_size and so on, all use the device coordinates. So click the mouse to get the point position, generally need to use the DPTOLP function to convert it to logical coordinates later use.

3, regardless of the window and the origin of the viewport changes, the device origin (0,0) is always the upper left corner of the customer area.

4, the device origin (0,0) and the viewport origin (viewportorg) is not a concept, they are the same by default, but after using the setviewportorg function, it is not the same.

Windows defines 8 ways to map:

Mapping method Logical units X axis Increase Y axis Increase mm
Mm_text Pixel points Right Under Device-related
Mm_lometric 0.1mm Right On 0.1
Mm_himetric 0.01mm Right On 0.01
Mm_loenglish 0.254mm Right On 0.254
Mm_hienglish 0.0254mm Right On 0.0254
Mm_twips 0.0176mm Right On 0.0176
Mm_isotropic Any (x=y) Options available Options available Can be set
Mm_anisotropic Any (x!=y) Options available Options available Can be set

The coordinate mechanism of MFC

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.