String length in pixels

Hello All,

Does C++ have a function that returns the length in pixels of a given string ?

Thanks in advance.
This function should be situated in the library which you use.

Standard includes don't have it.
No. A string is merely a series of symbolic characters. It has nothing to do with the graphical representation of said characters. In order to do what you're saying, you'd need to tell the computer what a "pixel" is, and how to represent the characters using these "pixels".
In Windows, you can measure the string. However, the function that does this require the string, the font to use, a width or width + height of the rectangle to use, and a device context as reference. Do you have all that? If so, use GetTextExtentPoint32() (http://msdn.microsoft.com/en-us/library/dd144938%28VS.85%29.aspx).
Topic archived. No new replies allowed.