--------------------------------------------------------------------------------

When using this with the DrawText API, I make the rectangle that the text is contained in the width of the return value of GetTextExtentPoint32


I know I am using the right parameters, but sometimes the rectangle is way too big (over 15 pixels wider than the actual width of the text) and sometimes the rectangle is too small.

It seems that this API is a little.. screwed up perhaps? If I input "WWWWWWWWWWWW" for example, the rectangle containing the text is around 20 pixels too big but if I input "iiiiiiiiiiii", the rectangle is around 20 pixels too small.

I tried using SetTextCharacterExtra, but that just screwed things up even more. I'm looking for a more accurate and precise way to set the rectangle's width via the width of the text. Btw, there will never be any spaces, numbers, or symbols as the text. The width of the text will only ever contain the 26 lowercase letters and 26 uppercase letters.

Thanks for any help. :)

How about this little rider in the manual page?

Because some devices kern characters, the sum of the extents of the characters in a string does not always equal to the extent of the string.

> I'm looking for a more accurate and precise way to set the
> rectangle's width via the width of the text.
You call DrawText() but you use the DT_CALCRECT flag to indicate that you just want the clip to be calculated. It doesn't draw anything.

This article has been dead for over six months. Start a new discussion instead.