What is the ing mode? To clarify this concept, we will first introduce two terms: "window" and "viewport ".
The view is based on the device coordinates. For a display, it is pixel, that is, what you see. The window is based on logical coordinates, virtual, and used when you write a program.It is also related to the device description table you have obtained. Generally, the client zone is obtained through beginpaint, while the window obtained through getdc is in the general sense: customer zone + menu bar + toolbar + title bar, etc.
The coordinate ing between the window and the view is the ing mode. Expressed:
Window-to-View:
Xviewport = (XWindow-xwinorg) * xviewext/xwinext + xvieworg
Yviewport = (ywindow-ywinorg) * yviewext/ywinext + yvieworg
Xviewext indicates the abscissa range of the window, and xwinext indicates the abscissa range of the window. What we usually care about is not their specific values, but their proportions.
Windows provides eight ing Modes
Ing method |
Logical unit |
Added Value |
X value |
Y value |
Mm_text |
Theme |
Right |
Lower |
Mm_lometric |
0.1 |
Right |
Upper |
Mm_himetric |
0.01 |
Right |
Upper |
Mm_loenglish |
0.01 in. |
Right |
Upper |
Mm_hienglish |
0.001 in. |
Right |
Upper |
Mm_twips |
1/1440 in. |
Right |
Upper |
Mm_isotropic |
Arbitrary (x = y) |
Optional |
Optional |
Mm_anisotropic |
Arbitrary (X! = Y) |
Optional |
Optional |
These eight modes are generally divided into three categories: mm_text, "measurement" ing mode, and "self-claimed" ing mode. Next we will introduce them one by one:
Mm_text
Mm_text is called because this method is the same as reading by default: the origin is in the upper left corner, from left to right, from top to bottom.
For mm_text ing, the origin and range are as follows:
Window origin: (0, 0) can be changed
The source of the port: (0, 0) can be changed.
Window range: (1, 1) unchangeable
View range: (1, 1) unchangeable
This means that there is no proportional transformation between the window coordinate and the logical coordinate, and only the translation transformation caused by the origin setting. Therefore, it is also called the ing method of "Full constraint. If you are + 1 in the window position, move a pixel on the screen.
You can use setviewportorgex and setjavasworgex to change the source of the view and window. However, we can achieve satisfactory results only by changing one, and at the same time, two changes are prone to confusion.
Getviewportorgex and getdomainworgex are used to obtain the origin of the current view port and window.
For example, if we want to draw a sine curve, we can: (the complete program can be seen in:Windows Programming (6): Basic Drawing
Http://blog.csdn.net/thefutureisour/article/details/7576712)
Case wm_paint: HDC = beginpaint (hwnd, & PS); // draw a straight line movetoex (HDC, 0, cyclient/2, null); lineto (HDC, cxclient, cyclient/2); // draw the sine curve for (INT I = 0; I <num; I ++) {// divide the X axis into 1000 apt [I]. X = I * cxclient/num; Apt [I]. y = (INT) (cyclient/2 * (1-sin (twopi * I/num); lineto (HDC, APT [I]. x, APT [I]. y); // sleep (10);} endpaint (hwnd, & PS); Return 0;
We can change the source of the View:
Case wm_paint: HDC = beginpaint (hwnd, & PS); // you can specify the setviewportorgex (HDC, cxclient/2, cyclient/2, null) for the origin of a view ); // draw a straight line movetoex (HDC, 0, cyclient/2, null); lineto (HDC, cxclient, cyclient/2 ); // draw the sine curve for (INT I = 0; I <num; I ++) {// divide the X axis into 1000 apt [I]. X = I * cxclient/num; Apt [I]. y = (INT) (cyclient/2 * (1-sin (twopi * I/num); lineto (HDC, APT [I]. x, APT [I]. y); // sleep (10);} endpaint (hwnd, & PS); Return 0;
It is foreseeable that the source point of the view is set to the center of the customer area. When I draw a picture, the first line is drawn from the range of the half customer area under the source, so the straight line cannot be seen. The sine curve can only be seen in half.
Another important application of modifying the source of the viewport is to make the subtitle "scroll:
Other parts of the program can be found in:Windows Programming (6): Basic Drawing
Http://blog.csdn.net/thefutureisour/article/details/7568955
Lresult callback wndproc (hwnd, uint message, wparam, lparam) {// character width, uppercase letter width, character height static int cxchar, cxcaps, cychar, ibegin; // window size static int cxclient, cyclient; // the scroll bar Position static int ivertpos, ihorzpos, ipaintbeg, ipaintend; HDC; // This variable is used to index sysmets. each element of the struct array sysmetrics [] defined in H int I; // The Position of the output text int X, Y; // Drawing Structure paintstruct pS; // string tchar szbuffer [10]; // font information structure textmetric TM; Switch (Message) {Case Wm _ Create: settimer (hwnd, id_timer, 20, null); HDC = getdc (hwnd); // get the text size of the system font, which is stored in the TM gettextmetrics (HDC, & TM); // average character width cxchar = TM. tmavecharwidth; // average width of uppercase letters cxcaps = (TM. tmpitchandfamily & 1? 3: 2) * cxchar/2; // total character height: height + row spacing cychar = TM. tmheight + TM. tmexternalleading; releasedc (hwnd, HDC); Return 0; Case wm_timer: ibegin ++; invalidaterect (hwnd, null, true); Case wm_size: cxclient = loword (lparam ); cyclient = hiword (lparam); Return 0; Case wm_paint: HDC = beginpaint (hwnd, & PS); // continuously change the origin set1_worgex (HDC, 0, ibegin, null ); for (I = 0; I <numlines; I ++) {textout (HDC, 0, cychar * I, sysmetrics [I]. szlabel, lstrlen (sysmetrics [I]. szlabel); textout (HDC, 22 * cxchar, cychar * I, sysmetrics [I]. szdesc, lstrlen (sysmetrics [I]. szdesc); settextalign (HDC, ta_right | ta_top); textout (HDC, 22 * cxcaps + 40 * cxchar, cychar * I, szbuffer, wsprintf (szbuffer, text ("% 5d"), getsystemmetrics (sysmetrics [I]. index); settextalign (HDC, ta_left | ta_top);} endpaint (hwnd, & PS); Return 0; Case wm_destroy: postquitmessage (0); Return 0 ;} return defwindowproc (hwnd, message, wparam, lparam );}
"Metric" ing method
There are five types:
Image Method |
Logical unit |
Inch |
Millimeters |
Mm_loenglish |
0.01 in. |
0.01 |
0.254 |
Mm_lometric |
0.1mm. |
0.00394 |
0.1 |
Mm_hienglish |
0.001 in. |
0.001 |
0.0254 |
Mm_twips |
1/1400 in. |
0.000694 |
0.0176 |
Mm_himetric |
0.01mm. |
0.000394 |
0.01 |
They become "measurements" because they use actual dimensions.
Usually we are interested in the conversion factor of the window and the view.
In mm_lometric mode, xviewext/xwinext indicates the number of workers per 0.01 inch in each horizontal direction, which is a value of the system. In Windows 7, the control panel-> display-> set the custom text size. When the value is 100%, 96 pixels per inch. So the proportion is: 96/100. We can see that the conversion factor remains unchanged.
Note that the coordinates of these modes are equivalent to moving the origin of the Cartesian coordinate system to the upper left corner, which means that all the Y axes you see are negative. For example:
SetMapMode (hdc, MM_LOENGLISH) ; TextOut (hdc, 100, -100, "Hello", 5)
The text is displayed on the left of the distance display area and 1 inch on the top.
Self-claimed ing method
The remaining ing modes are mm_isotropic and mm_anisotropic. They can change the conversion factor from the viewport to the window.
Mm_isotropic indicates the same direction, indicating that the conversion factors in the horizontal and vertical directions are the same. This means that if you draw a rectangle in the customer area, the rectangle will become larger and smaller as the customer area grows, and the aspect ratio of the rectangle will remain unchanged.
Mm_anisotropic indicates the opposite sex, indicating that the conversion factors in the horizontal and vertical directions are different. We will discuss the two methods below:
Mm_isotropic
When you first set the image mode to mm_isotropic, Windows uses the same window and view port range as mm_lometric. (Note that the Y axis is negative)
You can use the logical size of the expected logical window as the parameter of setw.wextex, and use the actual width and height of the customer area as the parameter of setviewportextex. When Windows adjusts these ranges, it must adapt the logical window to the actual window, which may cause a segment of the customer area to fall out of the logical window. Therefore, you must call setjavaswextex before setviewportextex.
Mm_anisotropic
When you set the window and view port range in the mm_isotropic image mode, Windows adjusts the range so that the logical units on the two axes have the same actual scale. In the mm_anisotropic ing mode, Windows does not adjust the value you set, which means that mm_anisotropic does not need to maintain the correct aspect ratio.
Here is an example:
# Define logwide 4000
# Define loghigh 3000
Case wm_paint: HDC = beginpaint (hwnd, & PS); // sets the ing mode setmapmode (HDC, mm_anisotropic); // setwindowextex (HDC, 1, 1, null ); // setviewportextex (HDC, 1,-1, null); setjavaswextex (HDC, logwide, loghigh, null); setviewportextex (HDC, cxclient,-cyclient, null ); setviewportorgex (HDC, 0, cyclient/2, null); // draw a straight line movetoex (HDC, 0, 0, null); lineto (HDC, logwide, 0); movetoex (HDC, 0, 0, null); // draw the sine curve // For (INT I = 0; I <num; I ++) for (I = 0; I <logwide; I ++) {// divide the X axis into 1000 copies // apt [I]. X = I * cxclient/num; Apt [I]. X = I; // apt [I]. y = (INT) (cyclient/2 * (sin (twopi * I/num); Apt [I]. y = (INT) (loghigh/2 * sin (twopi * I/logwide); lineto (HDC, APT [I]. x, APT [I]. y); // sleep (10);} endpaint (hwnd, & PS); Return 0;
The window range is (4000, 3000), while the window range is (). What does this mean? We can understand from two aspects:
1. Proportional Relationship: 4000: the size of the customer zone (for example, 800) means that every five logical units are mapped to one pixel.
2. select a range (width * Height) under the logical coordinate, And a range (width * Height of the customer area) under the device coordinate ), the things in the window range are mapped to the view strictly in proportion. This understanding method is also commonly used.
I think the window designed by Microsoft is very useful. For example, stock market software. We can save the information of each day, and when we need to analyze the time period, we can select a window range, the data in this range is what we need, and then display it. In this case, I don't want to consider how the window is displayed. The system will automatically convert the content of the window to the display in the window through the ing mode.