""Real"" length of a string

Aug 18, 2019 at 3:06pm
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 ?
Aug 18, 2019 at 3:12pm
Aug 18, 2019 at 3:31pm
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.
Aug 18, 2019 at 3:34pm
Yes, thanks a lot,
"This function returns the number of characters from a specified string that fit within a specified space" ,
good advice
Aug 18, 2019 at 5:03pm
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
Aug 18, 2019 at 5:05pm
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
Aug 18, 2019 at 5:13pm
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 Aug 18, 2019 at 5:14pm
Aug 18, 2019 at 6:22pm
yes, but that means to change the font (font size) of the status bar.


No, it doesn't.
Aug 18, 2019 at 10:17pm
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.
Aug 18, 2019 at 10:38pm
Aug 19, 2019 at 8:45am
Thanks a lot guys,
it is solved.
Use the function: GetTextExtentPoint32
Topic archived. No new replies allowed.