The MASM Forum

General => The Workshop => Topic started by: clamicun on August 19, 2019, 04:03:51 AM

Title: ""Real"" length of a string
Post by: clamicun on August 19, 2019, 04:03:51 AM
My program shows the string, which is edited/deleted/rename/moved a.s.o  in the statusbar (path + filename).
mov eax,len(offset stringname) 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 check if the string fits into a determined space - 630 px statusbar ?

If it doesn't fit I'll do something like:
D:\Arquivo\Win_Tricks10\Schwierige_Prei\....\"Filename to long for statusbar"
Title: Re: ""Real"" length of a string
Post by: jj2007 on August 19, 2019, 04:17:45 AM
Check GetTextExtentPoint32
Title: Re: ""Real"" length of a string
Post by: clamicun on August 19, 2019, 05:25:37 AM
Thank you jj,
I check it out
Title: Re: ""Real"" length of a string
Post by: clamicun on August 20, 2019, 12:54:49 AM
I admit I'm a bit confused with GetTextExtentPoint32


I create the statustext.
I create a font, send a WM_SETFONT message to the statusbar
and send a WM_SETTEXT message to the statusbar.

Either the text fits or doesn't.

statusbar
sz SIZE<>
mov sz.cx,630
mov sz.cy,23

Now I invoke GetTextExtentPoint32,hdc(handle of statusbar),addr statustext,length of statustext,addr sz);
It returns not NULL that is ok.
And now ?
What does this tell me ?
Title: Re: ""Real"" length of a string
Post by: sinsi on August 20, 2019, 01:57:09 AM
The SIZE structure is filled in by GetTextExtentPoint32 with the string's length and height in logical units (pixels?).
You compare the returned values with your status bar size to see if it fits.
Title: Re: ""Real"" length of a string
Post by: clamicun on August 20, 2019, 02:07:59 AM
sinsi,
yes, makes sense.
Thanks.
How is the dobermann doing ?
Title: Re: ""Real"" length of a string
Post by: sinsi on August 20, 2019, 08:52:33 AM
>How is the dobermann doing
Leading a quiet life...she died in 1998  :biggrin:
Title: Re: ""Real"" length of a string
Post by: jj2007 on August 20, 2019, 09:12:32 AM
Quote from: clamicun on August 20, 2019, 12:54:49 AMNow I invoke GetTextExtentPoint32,hdc(handle of statusbar),addr statustext,length of statustext,addr sz);

hdc(handle of statusbar) sounds a bit ambiguous. It's a DC.
Title: Re: ""Real"" length of a string
Post by: clamicun on August 20, 2019, 09:30:51 PM
jj,
"hdc(handle of statusbar) sounds a bit ambiguous. It's a DC."

https://docs.microsoft.com/en-us/windows/win32/api/wingdi/nf-wingdi-gettextextentpoint32a

Parameters GetTextExtentPoint32

hdc

A handle to the device context.
Title: Re: ""Real"" length of a string
Post by: clamicun on August 20, 2019, 09:35:26 PM
It works mainly, but not always.

A pointer to a SIZE structure that receives the dimensions of the string, in logical units.
Difference units pixels ?
Title: Re: ""Real"" length of a string
Post by: jj2007 on August 20, 2019, 09:48:29 PM
https://docs.microsoft.com/en-us/windows/win32/learnwin32/dpi-and-device-independent-pixels
Quotefonts are measured in logical units. A 72-point font is defined to be one logical inch tall. Logical inches are then converted to pixels. For many years, Windows used the following conversion: One logical inch equals 96 pixels. Using this scaling factor, a 72-point font is rendered as 96 pixels tall. A 12-point font is 16 pixels tall.

12 points = 12/72 logical inch = 1/6 logical inch = 96/6 pixels = 16 pixels
This scaling factor is described as 96 dots per inch (DPI).
Title: Re: ""Real"" length of a string
Post by: clamicun on August 21, 2019, 03:59:50 AM
sinsi,
sorry about that.
Whenever one my dogs died I was a bit down for a while.
Hope you have a new friend.