The MASM Forum Archive 2004 to 2012

General Forums => The Campus => Topic started by: zemtex on January 19, 2011, 12:52:42 AM

Title: Changing font size
Post by: zemtex on January 19, 2011, 12:52:42 AM
Howdy.

I have been peeking a little bit in the API docs, but can't find a perticular function for changing the font size in the current DC that I am writing text to ( "TextOut" function )

Does anyone know how to change font size (And font name for that matter) in an easy way?
Title: Re: Changing font size
Post by: dedndave on January 19, 2011, 01:28:57 AM
well - there are many "directions" to approach from
if you know the font name, you can use EnumFontFamiliesEx to make a list of available sizes

fonts are not easy to play with - lol

http://www.masm32.com/board/index.php?topic=15747.msg130057#msg130057

that example is for monospace fonts
it is a little different for true-type fonts, but you get the idea
Title: Re: Changing font size
Post by: Gunner on January 19, 2011, 01:43:47 AM
Here is what I do to change the font to use in TextOut:
Create the font with the attributes you want with CreateFontIndirect, save the handle to the created font...

Then just do:
invoke   SelectObject, hDC, hFontBold ; <-- where hFontBold is the handle to the font I created with CreateFontIndirect, and hDC is the handle to the DC you want to use with TextOut

Don't forget to delete the font in WM_CLOSE
invoke   DeleteObject, hFontBold
Title: Re: Changing font size
Post by: MichaelW on January 19, 2011, 02:05:22 AM
\masm32\examples\exampl07\butntest\lib\makefont.asm contains a simplified procedure for creating a font.

And this is a modification of it:

;------------------------------------------------------------------
; This is a modification of the MakeFont procedure from the MASM32
; examples, with the height and width specifications replaced with
; a point size specification.
;------------------------------------------------------------------

MakeFont proc pointSize:dword,weight:dword,italic:dword,lpFontName:dword

    invoke GetDC, 0
    invoke GetDeviceCaps, eax, LOGPIXELSY
    mul   pointSize
    xor   edx, edx
    mov   ecx, 72
    div   ecx

    invoke CreateFont,eax,0,NULL,NULL,weight,italic,NULL,NULL,
                      DEFAULT_CHARSET,OUT_TT_PRECIS,CLIP_DEFAULT_PRECIS,
                      PROOF_QUALITY,DEFAULT_PITCH or FF_DONTCARE,
                      lpFontName
    ret

MakeFont endp

Title: Re: Changing font size
Post by: dedndave on January 19, 2011, 02:30:25 AM
now you see what i meant about all the different directions   :bg
it depends on what you have to start with, and what you want to end up with
Title: Re: Changing font size
Post by: jj2007 on January 19, 2011, 07:50:13 AM
QuoteMakeFont
[/b]   MakeFont hHandFont, Height:40, Underline:TRUE, "Lucida Handwriting"
   MakeFont hVertFont, Height:32, Escapement:900
Rem[/color]   - in order to facilitate creating font variants, MakeFont keeps settings between calls
   - place in WM_CREATE handler
[/b]

For the lazy ones, an excerpt from the MasmBasic help file ;-)