Function : Calculates the height and width of the specified body string.
Function prototype : Bool gettextextentpoint32 (HDC, lptstr lpstring, int cbstring, lpsize );
Parameter : HDC: Device environment handle.
Lpstring: pointer to the body string. This string does not end with \ 0 because cbstring specifies the length of the string.
Cbstring: the number of characters in the string.
Lpsize: pointer to the size structure. The size of the string in this structure is returned.
Return Value : If the function is successfully called, the returned value is a non-zero value. If the function fails to be called, the returned value is 0.
Windows NT: To obtain more error information, call the getlasterror function.
Secondary note : Gettextextentpoint32 uses the selected font to calculate the string size. The height and width calculated by logical unit do not consider cropping.
Because some devices compress characters, the sum of character ranges in a string may not be equal to the string range.
The calculated character width takes into account the character interval of the settextcharacterextra device.
Gettextextentpoint32 (HDC, sztext, lstrlen (sztext), & size );
Specifically, size. CX and size. Cy are the length and height of the. String (in pixels). In Windows CE, gettextextentpoint32 is the same as gettextextentpoint.
One step is required, that is, to obtain the font of the main window, then set the font of the DC, and then calculate it. This is correct. refer to the following Code
Cstatic * temp = (cstatic *) getdlgitem (idc_static1 );
Crect rect;
Csize size (0, 0 );
Temp-> getwindowrect (rect );
Screentoclient (& rect );
Cclientdc DC (temp );
Cfont * poldfont = Dc. SelectObject (this-> getfont ());
Cstring STR;
Temp-> getwindowtext (STR );
If (: gettextextentpoint32 (HDC) DC, STR, str. getlength (), & size ))
{
Rect. Right = rect. Left + size. CX;
Rect. Bottom = rect. Top + size. Cy;
}
Else
{
Temp-> setwindowtext ("gettextextentpoint32 fail to get the size of text! ");
}
Temp-> movewindow (rect );
DC. SelectObject (poldfont );