News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

Changing font size

Started by zemtex, January 19, 2011, 12:52:42 AM

Previous topic - Next topic

zemtex

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?
I have been puzzling with lego bricks all my life. I know how to do this. When Peter, at age 6 is competing with me, I find it extremely neccessary to show him that I can puzzle bricks better than him, because he is so damn talented that all that is called rational has gone haywire.

dedndave

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

Gunner

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
~Rob (Gunner)
- IE Zone Editor
- Gunners File Type Editor
http://www.gunnerinc.com

MichaelW

\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

eschew obfuscation

dedndave

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

jj2007

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