If GetTextMetrics does not return the proper width, which it does not for some fonts such as ALISON, then one should use the GetCharABCWidthsFloat function.
RECT ImageRect = {0};
// get the required height of the bitmap
TEXTMETRIC tm = {0};
GetTextMetrics(ImageDC, &tm);
ImageRect.bottom = tm.tmHeight;
// Calculate the required width of the bitmap. Some characters in some fonts
// have overhangs and/or underhangs so large that the second or even third
// character from either end of the text can affect the size of the bitmap
// needed to display the text.
ABCFLOAT ABCWidths = {0};
double left = 0.0;
double right = 0.0;
double pos = 0.0;
for (std::tstring::iterator it = ImageText.begin(); it != ImageText.end(); ++it)
{
if (GetCharABCWidthsFloat(ImageDC, \*(it), \*(it), &ABCWidths))
{
pos += ABCWidths.abcfA;
left = min(left, pos);
pos += ABCWidths.abcfB;
right = max(right, pos);
pos += ABCWidths.abcfC;
}
}
ImageRect.right = (long)((right - left) + 0.5);
You may be right I may be crazy -- Billy Joel -- Within you lies the power for good - Use it!