News:

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

Enumerate all fonts installed

Started by starzboy, December 17, 2008, 10:45:58 AM

Previous topic - Next topic

dedndave

it probably means that you ran out of registers by using ADDR
show me the invoke line   :bg

dedndave

i see another little issue
you are filling the list during WM_CREATE, then sending strings to it
the window hasn't been created, yet

not sure, but i think that thing will enumerate fonts all day long
it will list each font, size, pitch/family until it goes through all of them   :P

dedndave

;assemble as a GUI app

        include \masm32\include\masm32rt.inc

        .data

lf      LOGFONT <>
cf      CHOOSEFONT <>

        .code

start:  mov     cf.lStructSize,sizeof CHOOSEFONT
        mov     cf.rgbColors,NULL
        mov     cf.hwndOwner,NULL
        mov     cf.lpLogFont,offset lf
        mov     cf.Flags,CF_SCREENFONTS or CF_EFFECTS
        INVOKE  ChooseFont,offset cf
        exit

        end     start


:P

xandaz

    Oh yeah.... that might be the issue. Thanks
invoke Line:
mov eax,dword ptr [esi].elfLogFont.lfFaceName
invoke DrawText,[edi].hdc,eax,-1,[edi].rcItem,DT_LEFT

dedndave

also - you want an address in EAX
change this
mov eax,dword ptr [esi].elfLogFont.lfFaceName
to this
lea eax,[esi].elfLogFont.lfFaceName

and - [edi].rcItem - it wants a pointer to a RECT struc

dedndave

i have enumerated sizes of a single font
it is much simpler than enumerting all the fonts
in the callback, i just put the info i wanted into a buffer, then display it all after enumeration is done

here is the invoke
        INVOKE  GetDC,NULL
        mov     hDc,eax

        mov dword ptr LogFnt.lfFaceName,6D726554h            ;'Term'
        mov dword ptr LogFnt.lfFaceName+4,6C616E69h          ;'inal'
        mov byte ptr LogFnt.lfFaceName+8,0
        mov byte ptr LogFnt.lfCharSet,OEM_CHARSET            ;EQU 255
        mov byte ptr LogFnt.lfPitchAndFamily,0
        INVOKE  EnumFontFamiliesEx,hDc,offset LogFnt,EnumFntCB,0,0

and i store the pointer into the buffer in lstPtr...
        OPTION  PROLOGUE:None
        OPTION  EPILOGUE:None

EnumFntCB PROC  lpLogFont:DWORD,lpMetric:DWORD,fType:DWORD,lParam:DWORD

        mov     edx,[esp+4]
        mov     eax,lstPtr
        movzx   ecx,byte ptr[edx]
        mov     ch,[edx+4]
        mov     [eax],ecx
        add     eax,4
        mov     lstPtr,eax
        ret     16

EnumFntCB ENDP

        OPTION  PROLOGUE:PrologueDef
        OPTION  EPILOGUE:EpilogueDef

after it is done, the buffer contains a list of dwords, one for each size of that font
lstPtr tells me how many are in the list

xandaz

   Thanks but i feel kinda defeated. Moving on to something else.

xandaz

   btw. If im trying to execute code that must be done once outside WM_CREATE like in this case what should i do? Should i send a WM_USER or something. i tried to process WM_CREATE for the listbox but don't know why it doesnt seem to send the message.

dedndave

easy enough
you can put it in WinMain at the appropriate place
you can create the list in a buffer before the window is created
just make sure you don't over-run your buffer - you are enumerating a lot of stuff   :bg
you could put a failsafe in the enumeration callback that skips entries if the buffer is full
then - let WM_PAINT show the text from the buffer

xandaz

   Well.... i guess that all i can say is thanks and i'm looking into it tho it seems kinda hard. I've managed some other hard things before ( for my semi-initiate level ) so i guess i can  handle it. latters and thanks

dedndave

not that bad - i may play with it later if i make good progress on my project

xandaz

   yeah, please do. I kinda tried lots of things and came up with this accoording with your advice. It's kinda clean but the pointers are bad. The font is always the same and lfFaceName too. Thanks

xandaz

   ooops. forgot to attach

Gunner

I don't use assume myself, but you do:
assume  edi:PTR DRAWITEMSTRUCT
assume  esi:PTR LOGFONT


once you are done casting the regs, you are supposed to "un assume" them

assume esi:nothing
assume edi:nothing

or bugs will def creep in...
~Rob (Gunner)
- IE Zone Editor
- Gunners File Type Editor
http://www.gunnerinc.com

xandaz

   really? i've seen that before but didn't realise what it was about. Could that be important? i'm not using esi/edi on anything else inside WndProc. Thanks Gunner