News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests
NB: Posting URL's See here: Posted URL Change

Main Menu

""Real"" length of a string

Started by clamicun, August 19, 2019, 04:03:51 AM

Previous topic - Next topic

clamicun

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"

jj2007


clamicun


clamicun

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 ?

sinsi

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.

clamicun

sinsi,
yes, makes sense.
Thanks.
How is the dobermann doing ?

sinsi

>How is the dobermann doing
Leading a quiet life...she died in 1998  :biggrin:

jj2007

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.

clamicun

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.

clamicun

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 ?

jj2007

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).

clamicun

sinsi,
sorry about that.
Whenever one my dogs died I was a bit down for a while.
Hope you have a new friend.