The gettextmetrics function can get a font text measurement and put it into a data structure of textmetric type. The structure is as follows:
Typedef struct tagtextmetric {// TM
Long tmheight; // character height
Long tmascent; // upper height of the character (baseline or above)
Long tmdescent; // lower part of the character height (below baseline)
Long tminternalleading; // number of spaces at the top of the string height defined by tmheight
Long tmexternalleading; // number of spaces added between two rows
Long tmavecharwidth; // average character width
Long tmmaxcharwidth; // The width of the widest character
Long tmweight; // The font width and weight
Long tmoverhang; // Add the additional height on some spliced Fonts
Long tmdigitizedaspectx; // The horizontal resolution of 96 DPI devices for the font design
Long tmdigitizedaspecty; // The vertical resolution of 96 DPI devices for the font design
Bchar tmfirstchar; // the first character defined for the font
Bchar tmlastchar; // The last character defined for the font
Bchar tmdefaultchar; // a replacement character that does not exist in the font
Bchar tmbreakchar; // character used for word splitting
Byte tmitalic; // non-zero when the font is Italic
Byte tmunderlined; // when the font is underline, It is not zero.
Byte tmstruckout; // non-zero when the font is deleted
Byte tmpitchandfamily; // font spacing (4 low bits) and Family (4 high bits)
Byte tmcharset; // Character Set of the font
} Textmetric;
Calculate the actual region occupied by characters in the cricheditctrl control:
1. Calculate the line height of each row by a single factor: line height lineheight
2. calculate the maximum font size of each line. charheight = font size * 96/72 PX character format font size = yheight/20. For mm_text ing, you can use the following formula to determine the height of a font that specifies the dot size: nheight =-muldiv (pointsize, getdevicecaps (HDC, logpixelsy), 72)
4. Calculate the baseline position of each row. Baseline = charheight * (tmdescent)/(tmheight) + (lineheight-charheight)/2. The baseline position is determined by the font height of the row, the largest font.
5. Calculate the upper-left coordinate getcharpos (char) of the area occupied by each line of characters. The position of the character is at the position of tmdescent/(tmheight) of the Character Font. So far, you can accurately determine the character height.
The specific calculation is quite easy and will not be repeated here.