1. ing mode in Windows
1. the purpose of defining the ing mode in Windows
After my synthesis, Windows defines the ing mode for the following purposes: 1. Use habits of different people. People in different countries, regions, and people prefer to use different measurement units. Some people prefer to use inches, while others prefer to use centimeters and millimeters in the metric system. Others prefer other units. 2. Separate the software from the hardware. Allows the software to be developed to the maximum extent unrelated to the hardware. 3. provides a logical and physical conversion. It is equivalent to the bank's interest rate.
2. Default ing mode
The default ing mode is mm_text, which is in pixels. The X axis is positive to the left, and the Y axis is downward. The default coordinate origin is in the upper left corner.
3. fixed proportion ing mode
Fixed proportion ing modes include mm_lometric, mm_himetric, mm_loenglish, mm_hienglish, and mm_twips. Their default coordinate origins are all in the upper left corner. The difference is that the physical size of each logical unit is different. The logical units used are 0.1mm, 0.01mm, 0.01 inch, 0.001 inch, 1/1440 inch (0.0007 inch ).
4. Variable Ratio ing mode
For the ing mode with variable proportions, you can define the size of a logical unit, which can be any size. It can also change the size with the environment change. There are two ing modes: mm_isotropic and mm_anisotropic. The size of the logical unit is equal to the ratio of the window range and the window range. The difference between the two lies in that the measurement units of the X and Y axes must be the same, while the latter does not.
Ii. Coordinate Systems in Windows
1. screen coordinates
Screen coordinates describe a coordinate system of physical devices (monitors, printers, etc.). The coordinate origin is in the upper left corner of the screen. The X axis is right, and the Y axis is downward. The measurement unit is pixel. The Origin, axis direction, and measurement unit cannot be changed.
2. device coordinates (also known as physical coordinates)
Device coordinates are a coordinate system that describes the forms displayed or printed on the screen and printer. The default coordinate origin is in the upper left corner of the customer zone. The X axis is positive to the right, and the Y axis is downward. The measurement unit is pixel. The source and axis direction can be changed, but the measurement unit cannot be changed.
3. Logical coordinates
Logical coordinates are the coordinate system used to control the display and print in the program. The coordinate system is closely related to the defined ing mode. The default ing mode is mm_text. We can change the default behavior of the coordinate system by setting different ing modes.
Iii. Conversion between logical coordinates and device coordinates
The following code is available:
Void cmapmodeview: onpaint ()
{
Cpaintdc DC (this );
// Obtain the device class settings
Cpoint ptorgview, ptorgwindow;
Csize sizeview, sizewindow;
Cstring strmsg;
Ptorgview = Dc. getviewportorg (); // get the origin of the View
Ptorgwindow = Dc. get1_worg (); // obtain the window Origin
Sizeview = Dc. getviewportext (); // get the view range
Sizewindow = Dc. getjavaswext (); // obtain the window range
Strmsg. format (_ T ("viewport extent :( % d, % d),/tviewport org :( % d, % d)/twindow extent :( % d, % d) /twindow ORG (% d, % d )"),
Sizeview. CX, sizeview. Cy, ptorgview. X, ptorgview. y,
Sizewindow. CX, sizewindow. Cy, ptorgwindow. X, ptorgwindow. y );
Trace ("% s/n", strmsg );
// Set the ing mode and Origin
DC. setmapmode (mm_text); // you can specify the ing mode.
DC. set1_worg (100,100); // you can specify the coordinates of the window.
DC. setviewportorg (200,200); // you can specify the coordinates of the source.
DC. setwindowext (5, 10); // This statement is only valid for the variable ratio ing mode
DC. setviewportext (); // same as above
Ptorgview = Dc. getviewportorg ();
Ptorgwindow = Dc. get1_worg ();
Sizeview = Dc. getviewportext ();
Sizewindow = Dc. getw.wext ();
Strmsg. format (_ T ("viewport extent :( % d, % d),/tviewport org :( % d, % d)/twindow extent :( % d, % d) /twindow ORG (% d, % d )"),
Sizeview. CX, sizeview. Cy, ptorgview. X, ptorgview. y,
Sizewindow. CX, sizewindow. Cy, ptorgwindow. X, ptorgwindow. y );
Trace ("% s/n", strmsg );
// Map a vertex (300,400) from the logical coordinate system to the device coordinate system.
Cpoint ptmap;
Ptmap = cpoint (300,400 );
DC. lptodp (& ptmap );
Strmsg. Format (_ T ("the orginal point (in LP): cpoint (300,400), convert to DP is: cpoint (% d, % d )"),
Ptmap. X, ptmap. y );
Trace ("% s/n", strmsg );
// Map the point (300,400) from the device coordinate system to the logical coordinate system
Ptmap = cpoint (300,400 );
DC. dptolp (& ptmap );
Strmsg. Format (_ T ("the orginal point (In DP): cpoint (300,400), convert to LP is: cpoint (% d, % d )"),
Ptmap. X, ptmap. y );
Trace ("% s/n", strmsg );
}
The final debugging result of the above Code is:
Viewport extent :( 1, 1), viewport org :( 0, 0) window extent :( 1, 1) window ORG (0, 0)
Viewport extent :( 200,200), viewport org :( 100,100) window extent :() window ORG)
The orginal point (in LP): cpoint (300,400), convert to DP is: cpoint (400,500)
The orginal point (In DP): cpoint (300,400), convert to LP is: cpoint (200,300)
According to msdn, The setworg (x, y) function sets the point (x, y) under the device coordinate to correspond to the origin of the logical coordinate. Setvieportorg (x, y) sets the origin of the logical coordinate corresponding to the point (x, y) under the logical coordinate. In fact, if both the logical coordinates and the device coordinate origin are set, the above statements are incorrect.
In the default mming mode mm_text, a logical unit corresponds to a pixel under the device coordinate. Shows the coordinate system after the default origin point is changed:
(0, 0) dx, lx (0, 0)
(100,100) lx
(200,200) dx
. (300,400)
Dy, Ly ly DY
In VC, the coordinate system transformation is different from the mathematical transformation in mathematics. Here, distance is used as the standard. First, let's take a look at how to convert a point (300,400) from a device to a logical coordinate.
In the device coordinate system, the distance between the point (300,400) and the Y axis is 100 logical units. The corresponding logical coordinates must be 100 units away from the y-axis of the logical coordinates. Another logical unit corresponds to one pixel. Therefore, the X value of the corresponding device coordinate is 100 + 100 = 200. Similarly, the Y value of the corresponding logical coordinate is 300.
In the same way, we can convert the point (300,400) under the logical coordinate to the device coordinate. The distance between the point (300,400) and the y-axis of the logical coordinate is 200. In the device coordinate system, the distance between the device coordinate and the device coordinate Y axis is also 200. Another logical unit corresponds to one pixel, so the X value of the corresponding device coordinate is 200 + 200 = 400. In the same way, we can find that the corresponding device coordinate Y is 500.
Here, because logical units correspond to device units one by one, we can also regard this issue as a very simple coordinate translation problem. The result is obvious.
I also found another article:
I. Basic knowledge about ing Modes
When a Windows application draws a graph in its customer zone, it must provide the location in the customer zone. The location is represented by the X and Y coordinates, the X represents the X coordinate, and the Y represents the Y coordinate. Among all the GDI plot functions, these coordinates use a "logical unit ". When the GDI function sends the output to a physical device, Windows converts the logical coordinates to the device coordinates (such as the pixels of the screen or printer ). The conversion between logical coordinates and device coordinates is determined by the ing mode. The ing mode is stored in the device environment. The getmapmode function is used to obtain the current ing mode from the device environment. The setmapmode function is used to set the ing mode of the device environment.
1. Logical coordinates
The logical coordinate is independent of the device. It is independent of the device point size. Using logical units is the basis for achieving "WYSIWYG. When a programmer calls a line-drawn GDI function lineto to draw a line with a length of 25.4 (1 inch), he does not need to consider the device to output. If the device is a VGA display, Windows automatically converts it to 96 pixels. If the device is a 300 dpi laser printer, Windows automatically converts it to pixels.
2. device coordinates
Windows maps the logical coordinates specified in the GDI function to the device coordinates. In all the device coordinate systems, the unit is subject to the pixel, and the horizontal value increases from left to right, the vertical value increases from top to bottom.
Windows includes the following three device coordinates to meet different needs:
(1) Customer Region coordinates, including the customer region of the application. The upper left corner of the customer region 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-subwindows) and the following Windows functions: createwindow and movewindow (both for non-subwindow ports), getmessage, getcursorpos, getwindowrect, windowfrompoint, and setbrushorg. You can use the clienttoscreen and screentoclient functions to convert the client region to the screen region or vice versa.
(3) window coordinates, including the entire window of a program, including the title bar, menu, scroll bar, and window box. The upper left corner of the window is (0, 0 ). You can use the getwindowdc window device environment to convert the logical unit into window coordinates.
3. Conversion between logical coordinates and device coordinates
The ing method defines how Windows maps the logical coordinates specified in the GDI function to the device coordinates. To continue with the discussion on the ing method, we will introduce some terms related to the ing mode in Windows: we refer to the coordinate system where the logical coordinates are located as "window" and the coordinate system where the device coordinates are located as "viewport ".
The "window" depends on logical coordinates. It can be a pixel, millimeter, or other scales that the programmer wants.
The "viewport" depends on the device coordinates (pixels ). Generally, the viewport is the same as the customer region. However, if a programmer uses getwindowdc or createdc to obtain a device environment, the view can also refer to the full window coordinates or screen coordinates. Point (0, 0) is the upper left corner of the customer area. The value of X increases to the right, and the value of Y increases upwards.
For all ing modes, Windows uses the following two formulas to convert the window coordinates into the visual interface coordinates:
Xviewport = (XWindow-xwinorg) * (xviewext/xwinext) + xvieworg
Yviewport = (ywindow-ywinorg) * (yviewext/ywinext) + yvieworg
(XWindow, ywindows) is the logic point to be converted, (xviewport, yviewport) is the device point after conversion. If the device coordinates are client Region coordinates or full window coordinates, windows must convert these coordinates into screen coordinates before drawing an object.
The two formulas use the points that specify the source of the window and the view respectively: (xwinorg, ywinorg) is the source of the window of the logical coordinate; (xvieworg, yvieworg) is the source of the view of the device coordinate. In the default device environment, both vertices are set to (0, 0), but they can be changed. This formula means that the logical points (xwinorg, ywinorg) are always mapped to the device points (xvieworg, yvieworg ).
Windows can also convert the coordinates of the view (device) to the window (logical) coordinates:
XWindow = (xviewport-xvieworg) * (xwinext/xviewext) + xwinorg
Ywindow = (yviewport-yvieworg) * (ywinext/yviewext) + ywinorg
You can use the dptolp and lptodp functions provided by windows to convert the device coordinates and logical coordinates.
4. Types of ing Modes
Windows defines eight ing methods listed in Table 1.
The above ing mode can be divided into the following three categories:
Mmmmmmmmmmmmmmmmmmmmmm( mm_lometric 0. 1mm right-top 0.1 mm_himetric 0. 01mm upper right 0.01 mm_loenglish 0. 254mm upper right 0.254 mm_hienglish 0. 0254mm on the right 0.0254 mm_twips 0.0176mm on the right 0.0176 mm_isotropic (x = y) Optional mm_anisotropic
Ren Yi (X! = Y) Optional
1. ing mode in Windows
1. the purpose of defining the ing mode in Windows
After my synthesis, Windows defines the ing mode for the following purposes: 1. Use habits of different people. People in different countries, regions, and people prefer to use different measurement units. Some people prefer to use inches, while others prefer to use centimeters and millimeters in the metric system. Others prefer other units. 2. Separate the software from the hardware. Allows the software to be developed to the maximum extent unrelated to the hardware. 3. provides a logical and physical conversion. It is equivalent to the bank's interest rate.
2. Default ing mode
The default ing mode is mm_text, which is in pixels. The X axis is positive to the left, and the Y axis is downward. The default coordinate origin is in the upper left corner.
3. fixed proportion ing mode
Fixed proportion ing modes include mm_lometric, mm_himetric, mm_loenglish, mm_hienglish, and mm_twips. Their default coordinate origins are all in the upper left corner. The difference is that the physical size of each logical unit is different. The logical units used are 0.1mm, 0.01mm, 0.01 inch, 0.001 inch, 1/1440 inch (0.0007 inch ).
4. Variable Ratio ing mode
For the ing mode with variable proportions, you can define the size of a logical unit, which can be any size. It can also change the size with the environment change. There are two ing modes: mm_isotropic and mm_anisotropic. The size of the logical unit is equal to the ratio of the window range and the window range. The difference between the two lies in that the measurement units of the X and Y axes must be the same, while the latter does not.
Ii. Coordinate Systems in Windows
1. screen coordinates
Screen coordinates describe a coordinate system of physical devices (monitors, printers, etc.). The coordinate origin is in the upper left corner of the screen. The X axis is right, and the Y axis is downward. The measurement unit is pixel. The Origin, axis direction, and measurement unit cannot be changed.
2. device coordinates (also known as physical coordinates)
Device coordinates are a coordinate system that describes the forms displayed or printed on the screen and printer. The default coordinate origin is in the upper left corner of the customer zone. The X axis is positive to the right, and the Y axis is downward. The measurement unit is pixel. The source and axis direction can be changed, but the measurement unit cannot be changed.
3. Logical coordinates
Logical coordinates are the coordinate system used to control the display and print in the program. The coordinate system is closely related to the defined ing mode. The default ing mode is mm_text. We can change the default behavior of the coordinate system by setting different ing modes.
Iii. Conversion between logical coordinates and device coordinates
The following code is available:
Void cmapmodeview: onpaint ()
{
Cpaintdc DC (this );
// Obtain the device class settings
Cpoint ptorgview, ptorgwindow;
Csize sizeview, sizewindow;
Cstring strmsg;
Ptorgview = Dc. getviewportorg (); // get the origin of the View
Ptorgwindow = Dc. get1_worg (); // obtain the window Origin
Sizeview = Dc. getviewportext (); // get the view range
Sizewindow = Dc. getjavaswext (); // obtain the window range
Strmsg. format (_ T ("viewport extent :( % d, % d),/tviewport org :( % d, % d)/twindow extent :( % d, % d) /twindow ORG (% d, % d )"),
Sizeview. CX, sizeview. Cy, ptorgview. X, ptorgview. y,
Sizewindow. CX, sizewindow. Cy, ptorgwindow. X, ptorgwindow. y );
Trace ("% s/n", strmsg );
// Set the ing mode and Origin
DC. setmapmode (mm_text); // you can specify the ing mode.
DC. set1_worg (100,100); // you can specify the coordinates of the window.
DC. setviewportorg (200,200); // you can specify the coordinates of the source.
DC. setwindowext (5, 10); // This statement is only valid for the variable ratio ing mode
DC. setviewportext (); // same as above
Ptorgview = Dc. getviewportorg ();
Ptorgwindow = Dc. get1_worg ();
Sizeview = Dc. getviewportext ();
Sizewindow = Dc. getw.wext ();
Strmsg. format (_ T ("viewport extent :( % d, % d),/tviewport org :( % d, % d)/twindow extent :( % d, % d) /twindow ORG (% d, % d )"),
Sizeview. CX, sizeview. Cy, ptorgview. X, ptorgview. y,
Sizewindow. CX, sizewindow. Cy, ptorgwindow. X, ptorgwindow. y );
Trace ("% s/n", strmsg );
// Map a vertex (300,400) from the logical coordinate system to the device coordinate system.
Cpoint ptmap;
Ptmap = cpoint (300,400 );
DC. lptodp (& ptmap );
Strmsg. Format (_ T ("the orginal point (in LP): cpoint (300,400), convert to DP is: cpoint (% d, % d )"),
Ptmap. X, ptmap. y );
Trace ("% s/n", strmsg );
// Map the point (300,400) from the device coordinate system to the logical coordinate system
Ptmap = cpoint (300,400 );
DC. dptolp (& ptmap );
Strmsg. Format (_ T ("the orginal point (In DP): cpoint (300,400), convert to LP is: cpoint (% d, % d )"),
Ptmap. X, ptmap. y );
Trace ("% s/n", strmsg );
}
The final debugging result of the above Code is:
Viewport extent :( 1, 1), viewport org :( 0, 0) window extent :( 1, 1) window ORG (0, 0)
Viewport extent :( 200,200), viewport org :( 100,100) window extent :() window ORG)
The orginal point (in LP): cpoint (300,400), convert to DP is: cpoint (400,500)
The orginal point (In DP): cpoint (300,400), convert to LP is: cpoint (200,300)
According to msdn, The setworg (x, y) function sets the point (x, y) under the device coordinate to correspond to the origin of the logical coordinate. Setvieportorg (x, y) sets the origin of the logical coordinate corresponding to the point (x, y) under the logical coordinate. In fact, if both the logical coordinates and the device coordinate origin are set, the above statements are incorrect.
In the default mming mode mm_text, a logical unit corresponds to a pixel under the device coordinate. Shows the coordinate system after the default origin point is changed:
(0, 0) dx, lx (0, 0)
(100,100) lx
(200,200) dx
. (300,400)
Dy, Ly ly DY
In VC, the coordinate system transformation is different from the mathematical transformation in mathematics. Here, distance is used as the standard. First, let's take a look at how to convert a point (300,400) from a device to a logical coordinate.
In the device coordinate system, the distance between the point (300,400) and the Y axis is 100 logical units. The corresponding logical coordinates must be 100 units away from the y-axis of the logical coordinates. Another logical unit corresponds to one pixel. Therefore, the X value of the corresponding device coordinate is 100 + 100 = 200. Similarly, the Y value of the corresponding logical coordinate is 300.
In the same way, we can convert the point (300,400) under the logical coordinate to the device coordinate. The distance between the point (300,400) and the y-axis of the logical coordinate is 200. In the device coordinate system, the distance between the device coordinate and the device coordinate Y axis is also 200. Another logical unit corresponds to one pixel, so the X value of the corresponding device coordinate is 200 + 200 = 400. In the same way, we can find that the corresponding device coordinate Y is 500.
Here, because logical units correspond to device units one by one, we can also regard this issue as a very simple coordinate translation problem. The result is obvious.
I also found another article:
I. Basic knowledge about ing Modes
When a Windows application draws a graph in its customer zone, it must provide the location in the customer zone. The location is represented by the X and Y coordinates, the X represents the X coordinate, and the Y represents the Y coordinate. Among all the GDI plot functions, these coordinates use a "logical unit ". When the GDI function sends the output to a physical device, Windows converts the logical coordinates to the device coordinates (such as the pixels of the screen or printer ). The conversion between logical coordinates and device coordinates is determined by the ing mode. The ing mode is stored in the device environment. The getmapmode function is used to obtain the current ing mode from the device environment. The setmapmode function is used to set the ing mode of the device environment.
1. Logical coordinates
The logical coordinate is independent of the device. It is independent of the device point size. Using logical units is the basis for achieving "WYSIWYG. When a programmer calls a line-drawn GDI function lineto to draw a line with a length of 25.4 (1 inch), he does not need to consider the device to output. If the device is a VGA display, Windows automatically converts it to 96 pixels. If the device is a 300 dpi laser printer, Windows automatically converts it to pixels.
2. device coordinates
Windows maps the logical coordinates specified in the GDI function to the device coordinates. In all the device coordinate systems, the unit is subject to the pixel, and the horizontal value increases from left to right, the vertical value increases from top to bottom.
Windows includes the following three device coordinates to meet different needs:
(1) Customer Region coordinates, including the customer region of the application. The upper left corner of the customer region 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-subwindows) and the following Windows functions: createwindow and movewindow (both for non-subwindow ports), getmessage, getcursorpos, getwindowrect, windowfrompoint, and setbrushorg. You can use the clienttoscreen and screentoclient functions to convert the client region to the screen region or vice versa.
(3) window coordinates, including the entire window of a program, including the title bar, menu, scroll bar, and window box. The upper left corner of the window is (0, 0 ). You can use the getwindowdc window device environment to convert the logical unit into window coordinates.
3. Conversion between logical coordinates and device coordinates
The ing method defines how Windows maps the logical coordinates specified in the GDI function to the device coordinates. To continue with the discussion on the ing method, we will introduce some terms related to the ing mode in Windows: we refer to the coordinate system where the logical coordinates are located as "window" and the coordinate system where the device coordinates are located as "viewport ".
The "window" depends on logical coordinates. It can be a pixel, millimeter, or other scales that the programmer wants.
The "viewport" depends on the device coordinates (pixels ). Generally, the viewport is the same as the customer region. However, if a programmer uses getwindowdc or createdc to obtain a device environment, the view can also refer to the full window coordinates or screen coordinates. Point (0, 0) is the upper left corner of the customer area. The value of X increases to the right, and the value of Y increases upwards.
For all ing modes, Windows uses the following two formulas to convert the window coordinates into the visual interface coordinates:
Xviewport = (XWindow-xwinorg) * (xviewext/xwinext) + xvieworg
Yviewport = (ywindow-ywinorg) * (yviewext/ywinext) + yvieworg
(XWindow, ywindows) is the logic point to be converted, (xviewport, yviewport) is the device point after conversion. If the device coordinates are client Region coordinates or full window coordinates, windows must convert these coordinates into screen coordinates before drawing an object.
The two formulas use the points that specify the source of the window and the view respectively: (xwinorg, ywinorg) is the source of the window of the logical coordinate; (xvieworg, yvieworg) is the source of the view of the device coordinate. In the default device environment, both vertices are set to (0, 0), but they can be changed. This formula means that the logical points (xwinorg, ywinorg) are always mapped to the device points (xvieworg, yvieworg ).
Windows can also convert the coordinates of the view (device) to the window (logical) coordinates:
XWindow = (xviewport-xvieworg) * (xwinext/xviewext) + xwinorg
Ywindow = (yviewport-yvieworg) * (ywinext/yviewext) + ywinorg
You can use the dptolp and lptodp functions provided by windows to convert the device coordinates and logical coordinates.
4. Types of ing Modes
Windows defines eight ing methods listed in Table 1.
The above ing mode can be divided into the following three categories:
Mmmmmmmmmmmmmmmmmmmmmm( mm_lometric 0. 1mm right-top 0.1 mm_himetric 0. 01mm upper right 0.01 mm_loenglish 0. 254mm upper right 0.254 mm_hienglish 0. 0254mm on the right 0.0254 mm_twips 0.0176mm on the right 0.0176 mm_isotropic (x = y) Optional mm_anisotropic
Ren Yi (X! = Y) Optional