""Real"" length of a string

Write your question here.

My program shows the string, which is edited in the statusbar (path + filename).
The function strlen() returns the amount of characters.

Here 80 - string fits into statusbar.
C:\Users\michael\Documents\80_iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii.txt

Here 80 too - String is too long for the statusbar.
C:\Users\michael\Documents\80_AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA.txt

Here 80 too - String fits.
D:\Arquivo\Win_Tricks10\Schwierige_PreinstalledApps\PSTools\80_Gert_und_Hans.txt

Here 90 - String fits.
C:\Users\michael\Documents\90_IiiiiiIiiiiiiIiiiiiiBCIiIIIiiiiAAAiiiiBBBBiiiiiiiiiiiii).doc

Is there a possibility to know the ""real"" (whatever that means) length of that string ?
The length (number of characters) is the same. How the text is rendered to the screen depends on the font used to render the text to the window.
Yes, thanks a lot,
"This function returns the number of characters from a specified string that fit within a specified space" ,
good advice
Furry Guy,
"The length (number of characters) is the same" ... same as what ?
Of course it is dependant of the font.

That doesn't help. Changing the font of the statusbar depending on the string to show, is a bit strange
The point is that in order to determine the number of pixels wide a certain string will be, you need information about the font used to render that string. I'm pretty sure that's all Furry Guy was saying.

-Albatross
Albatross,
yes, but that means to change the font (font size) of the status bar.
No, I onlyy want to know, if the string fits.
If not I shorten the string like this:

C:\Users\michael\Documents\.....\"Filename doesn't fit in statusbar"

And as I said ... Just to know the number of characters doesn't help
Last edited on
yes, but that means to change the font (font size) of the status bar.


No, it doesn't.
but that means to change the font (font size) of the status bar.

More than a few applications I have used truncate the displayed text, displaying "..." as the final 3 characters, if the number of characters exceeded the space allotted on the status bar. The apps "pop up" a tooltip that displays the entire string if the user hovers their pointer over the text.

Or find some other area of the app's window to display the information, such as the title bar. That isn't as common as displaying a tooltip.
Thanks a lot guys,
it is solved.
Use the function: GetTextExtentPoint32
Topic archived. No new replies allowed.