Author Topic: ""Real"" length of a string  (Read 308 times)

clamicun

  • Member
  • ***
  • Posts: 347
""Real"" length of a string
« 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"

jj2007

  • Member
  • *****
  • Posts: 9639
  • Assembler is fun ;-)
    • MasmBasic
Re: ""Real"" length of a string
« Reply #1 on: August 19, 2019, 04:17:45 AM »
Check GetTextExtentPoint32

clamicun

  • Member
  • ***
  • Posts: 347
Re: ""Real"" length of a string
« Reply #2 on: August 19, 2019, 05:25:37 AM »
Thank you jj,
I check it out

clamicun

  • Member
  • ***
  • Posts: 347
Re: ""Real"" length of a string
« Reply #3 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 ?

sinsi

  • Member
  • *****
  • Posts: 1176
Re: ""Real"" length of a string
« Reply #4 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.
I can walk on water but stagger on beer bourbon.

clamicun

  • Member
  • ***
  • Posts: 347
Re: ""Real"" length of a string
« Reply #5 on: August 20, 2019, 02:07:59 AM »
sinsi,
yes, makes sense.
Thanks.
How is the dobermann doing ?

sinsi

  • Member
  • *****
  • Posts: 1176
Re: ""Real"" length of a string
« Reply #6 on: August 20, 2019, 08:52:33 AM »
>How is the dobermann doing
Leading a quiet life...she died in 1998  :biggrin:
I can walk on water but stagger on beer bourbon.

jj2007

  • Member
  • *****
  • Posts: 9639
  • Assembler is fun ;-)
    • MasmBasic
Re: ""Real"" length of a string
« Reply #7 on: August 20, 2019, 09:12:32 AM »
Now 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

  • Member
  • ***
  • Posts: 347
Re: ""Real"" length of a string
« Reply #8 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.

clamicun

  • Member
  • ***
  • Posts: 347
Re: ""Real"" length of a string
« Reply #9 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 ?

jj2007

  • Member
  • *****
  • Posts: 9639
  • Assembler is fun ;-)
    • MasmBasic
Re: ""Real"" length of a string
« Reply #10 on: August 20, 2019, 09:48:29 PM »
https://docs.microsoft.com/en-us/windows/win32/learnwin32/dpi-and-device-independent-pixels
Quote
fonts 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

  • Member
  • ***
  • Posts: 347
Re: ""Real"" length of a string
« Reply #11 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.