Windows mapping model and solutions to related problems

Source: Internet
Author: User

When a Windows application draws a graphic, it uses a logical unit, the size of each logical unit is determined by the mapping mode, which can be the same as a unit of equipment (a pixel on screen or printer), a physical unit (such as millimeters), or a user-defined unit. In a Windows application, you use the mapping mode whenever you have a relationship with the output. The purpose of this article is to help readers understand some of the basics of mapping patterns and to propose solutions to problems that often arise in use.

Basic knowledge of mapping mode

When a Windows application draws a graphic in its client area, it must give its location in the customer area, in X and y two coordinates, x for the horizontal axis, and y for ordinate. In all GDI drawing functions, these coordinates use a "logical unit". When the GDI function sends output to a physical device, Windows converts logical coordinates to device coordinates, such as the pixel points of the screen or printer. The transformation of logical coordinates and device coordinates is determined by the mapping pattern. The mapping mode is stored in the device environment. The Getmapmode function is used to get the current mapping pattern from the device environment, and the Setmapmode function is used to set the mapping mode for the device environment.

1. Logical coordinates

Logical coordinates are independent of the device, regardless of the size of the device point. The use of logical units is the basis for achieving what is WYSIWYG. When a programmer calls a line GDI function LineTo and draws 25.4mm (1-inch) long lines, he does not need to consider what device is being exported. If the device is a VGA monitor, Windows automatically converts it to a 96 pixel point, and Windows automatically converts it to 300 pixels if the device is a 300dpi laser printer.

2. Equipment coordinates

Windows maps the logical coordinates specified in GDI functions to device coordinates, in all device coordinate systems, the unit is pixel-wide, the horizontal value increases from left to right, and the vertical value increases from top to bottom.

The following 3 device coordinates are included in Windows to meet a variety of needs:

(1) Customer area coordinates, including the client area of the application, and the upper-left corner of the customer area (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 (all for non-child windows), GetMessage, GetCursorPos, GetWindowRect , Windowfrompoint and setbrushorg. Use function ClientToScreen and screentoclient to convert client area coordinates to screen area coordinates, or vice versa.

(3) Full window coordinates, including the entire window of a program, including title bar, menu, scroll bar and window box, the upper-left corner of the window is (0,0). You can convert logical units to window coordinates using the Windows device environment that GETWINDOWDC.

Related Article

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.