The MASM Forum

General => The Campus => Topic started by: hfheatherfox07 on August 18, 2012, 04:38:20 AM

Title: Draw Text
Post by: hfheatherfox07 on August 18, 2012, 04:38:20 AM
Hi,
I was wondering is the re a way to center Multilines with DrawText Vertically?
It seems that DT_VCENTER only works with single lines :(

szText          db 'Text Line1',13,10
     db 'Text Line2',13,10
             db 'Text Line2', 0

This wont work
invoke  DrawText,        ps.hdc, addr szText,-1, addr rcClient,
                                 DT_VCENTER or DT_CENTER or DT_NOPREFIX
Title: Re: Draw Text
Post by: jj2007 on August 18, 2012, 04:58:37 AM
No. You need two invokes, the first with DT_CALCRECT.
Title: Re: Draw Text
Post by: hfheatherfox07 on August 18, 2012, 05:05:59 AM
@ jj2007
I don't understand what you mean ?

Have different data values ?
Like


szText          db 'Text Line1',13,10
szText 1     db 'Text Line2',13,10
szText 2       db 'Text Line2', 0
Title: Re: Draw Text
Post by: hfheatherfox07 on August 18, 2012, 05:09:37 AM
I have tried this ...does not seem right?

invoke  DrawText,        ps.hdc, addr szHello,-1, addr rcClient,
                                DT_CALCRECT or  DT_VCENTER
                               
invoke  DrawText,        ps.hdc, addr szHello,-1, addr rcClient,
                            DT_CENTER
Title: Re: Draw Text
Post by: jj2007 on August 18, 2012, 05:59:13 AM
"If the function succeeds, the return value is the height of the text."

- invoke DrawText, ... DT_CALCRECT
- mov edx, heightofbox
- sub edx, eax
- sar edx, 1
- add rc.top, edx
- invoke DrawText, ... DT_whatever
Title: Re: Draw Text
Post by: hfheatherfox07 on August 18, 2012, 06:14:09 AM
@jj2007 
Nice!!!  :t

That worked Great ..... The " heightofbox" is actually pixels from the top to go down

I will add a little Demo in case some one else runs into this
Title: Re: Draw Text
Post by: hfheatherfox07 on August 18, 2012, 06:37:48 AM
Thank You Again jj2007 !  :t

Here is that example in case some one else runs into this  :biggrin: