Title: Output (next to next) two lines of string in the user area in millimeters, how to solve?
If you print two lines of string, you need to keep (a certain) distance between the rows without overlapping or leading too large.
First question, how do you know the height of a font? According to the study of the text display, the height of the font is stored in the textmetric structure, by creating a DC to get this height, then the problem is that if you follow the default mapping mode, that is, the mm_text mode, you get the mapping mode of the logical units, in other words, if you do not change the mapping mode, The resulting height is 16 (pixels).
16 is the pixel, but now needs to be in millimeters, obviously this 16 does not meet the requirements, need to change the mapping mode to Mm_lometric, then get the logical units in 0.1mm units, and then to take the height of textmetric, get 56.
Calculation:
The same font, pixel units =16,0.1mm = 56, so 16 pixels =5.6mm.
It is calculated that in the Mm_lometric mapping mode, the font height is 56 (that is, 5.6 mm), the problem has been basically resolved.
In mm_lometric mapping mode, x to the right, y upward, if the first line of string start is: (100,-100), then the beginning of the second line string is (100,-100-56).
Similarly, if you convert to Mm_text mode and output in the same place, the first line of string is converted to (28,28) and can be overwritten with a slight error.
/*------------------------Intercept Code---------------------------*/ Static Charbuffer[ -]; HDC hdc; Paintstruct PS; StaticTextmetric TM; Switch(message) { CaseWM_CREATE:HDC=GETDC (HWND);//Create temporary DCSetmapmode (Hdc,mm_lometric);//conversion mapping mode is Mm_lometricGetTextMetrics (HDC,&TM);//Get font informationItoa (Tm.tmheight,buffer,Ten);//Gets the font height, stored in the temporary array buffer, and observes the height of the font in the Mm_lometric modeReleaseDC (HWND,HDC); return 0; CaseWM_PAINT:HDC=beginpaint (hwnd,&PS); Setmapmode (hdc,mm_lometric);//Set Mm_lometric modeTextOut (HDC, -,- -, Buffer,strlen (buffer));//output First line stringTextOut (HDC, -,- --tm.tmheight,buffer,strlen (buffer));//output Second line stringSetmapmode (Hdc,mm_text);//and convert it into Mm_text mode .TextOut (HDC, -, -,"Mm_text",7);//Output stringTextOut (HDC, -, -+ -,"Mm_text",7); EndPaint (hwnd,&PS); return 0
Two operations on the mapping mode:
Setmapmode (HDC hdc,int nmapmode); /* Mapping mode is actually a constant value */
int Getmapmode (HDC hdc);
Research on logical coordinates and device coordinates