Search code examples
cwinapigdi

Draw text and make it fit inside a rectangle in GDI?


Is there's a function that can draw text and fit it inside a rectangle (the function will make the size of the text smaller as appropriate to make it fit or something).

I checked the parameters for DrawText() but I don't think it supports such a feature.


Solution

  • Maybe you can use GetTextMetrics to check if the text fits inside the rectangle, and if it doesn't, reduce the current font size and repeat the measurement.

    GetTextMetrics:

    http://msdn.microsoft.com/en-us/library/windows/desktop/dd144941%28v=vs.85%29.aspx