The MASM Forum Archive 2004 to 2012

General Forums => The Workshop => Topic started by: jj2007 on April 20, 2012, 03:48:38 PM

Title: GetLogFont
Post by: jj2007 on April 20, 2012, 03:48:38 PM
Any ideas where to find/how to implement GetLogFont (http://msdn.microsoft.com/en-us/library/zhcs623h(v=vs.80).aspx) in Masm32?
Title: Re: GetLogFont
Post by: dedndave on April 20, 2012, 03:59:50 PM
i guess you have to start off by getting the hDC for the window (GetDC,hWnd)
then...
        INVOKE  GetCurrentObject,hDC,OBJ_FONT
to get a handle to the font
then use GetFontData
Title: Re: GetLogFont
Post by: dedndave on April 20, 2012, 04:16:53 PM
my mistake
instead of GetFontData, use GetObject

so, it's...

GetDC
GetCurrentObject
GetObject

....
and when you are done

ReleaseDC

yoy probably don't want to delete the object handle
Title: Re: GetLogFont
Post by: dedndave on April 20, 2012, 04:34:20 PM
GetLogfont PROTO :HWND,:LPVOID

GetLogfont PROC hWnd:HWND,lpLogfont:LPVOID

        INVOKE  GetDC,hWnd
        push    eax
        INVOKE  GetCurrentObject,eax,OBJ_FONT
        INVOKE  GetObject,eax,sizeof LOGFONT,lpLogfont
        push    hWnd
        CALL    ReleaseDC
        ret

GetLogfont ENDP
Title: Re: GetLogFont
Post by: dedndave on April 20, 2012, 04:39:59 PM
or, if you prefer....
GetLogfont PROTO :HWND,:LPVOID

;----------------------------------------------------------

        OPTION  PROLOGUE:None
        OPTION  EPILOGUE:None

GetLogfont PROC hWnd:HWND,lpLogfont:LPVOID

        INVOKE  GetDC,[esp+4]
        push    eax
        INVOKE  GetCurrentObject,eax,OBJ_FONT
        INVOKE  GetObject,eax,sizeof LOGFONT,[esp+12]
        push    [esp+8]
        CALL    ReleaseDC
        ret     8

GetLogfont ENDP

        OPTION  PROLOGUE:PrologueDef
        OPTION  EPILOGUE:EpilogueDef

;----------------------------------------------------------


saves 2 bytes  :bg
Title: Re: GetLogFont
Post by: jj2007 on April 20, 2012, 05:29:54 PM
Dave,

You are the champion :U

http://www.google.com/search?q=OBJ_FONT+getlogfont

Hit #2:

GetLogFont
www.masm32.com/board/index.php?PHPSESSID...board=2;...
5 posts - 2 authors - 43 minutes ago
Title: Re: GetLogFont
Post by: baltoro on April 20, 2012, 05:56:38 PM
JOCHEN,   
I assume that you don't want to implement the MFC (Microsoft Foundation Classes) version of: CreateFont (http://msdn.microsoft.com/en-us/library/dd183499(v=vs.85).aspx). The key is the LOGFONT (http://msdn.microsoft.com/en-us/library/dd145037(v=vs.85).aspx) structure.
Title: Re: GetLogFont
Post by: jj2007 on April 20, 2012, 06:32:26 PM
See my post #1 above. I was looking for an elegant way to create a modified version of an existing font, via CreateFontIndirect. Dave's approach looks ok.
Title: Re: GetLogFont
Post by: dedndave on April 21, 2012, 04:20:34 AM
ok - i made a big mistake, this time

the ReleaseDC function has 2 parameters - it's not enough to specify the hDC   ::)
        INVOKE  ReleaseDC,hWnd,hDC

the LEAVE instruction in the epilogue hid the problem in the first code example

i modified my posts above to reflect the change
Title: Re: GetLogFont
Post by: ragdog on April 21, 2012, 05:14:22 AM
Hi Dave

esp+8 =hwnd is correct?
Why make you by  GetDC esp+4?
this Parameter must a hWnd

INVOKE  GetDC,[esp+8]


Greets,
Title: Re: GetLogFont
Post by: dedndave on April 21, 2012, 05:41:00 AM
GetLogfont PROC hWnd:HWND,lpLogfont:LPVOID

        INVOKE  GetDC,[esp+4]              ;at this time, [ESP] is the return address
        push    eax                        ;now, [ESP+4] is the return address
        INVOKE  GetCurrentObject,eax,OBJ_FONT
        INVOKE  GetObject,eax,sizeof LOGFONT,[esp+12]
        push    [esp+8]
        CALL    ReleaseDC
        ret     8


i might add....
there is no real advantage in using that form - it was only a prod for Jochen   :P
the first one is the better way to go, actually
GetLogfont PROTO :HWND,:LPVOID

GetLogfont PROC hWnd:HWND,lpLogfont:LPVOID

        INVOKE  GetDC,hWnd
        push    eax
        INVOKE  GetCurrentObject,eax,OBJ_FONT
        INVOKE  GetObject,eax,sizeof LOGFONT,lpLogfont
        push    hWnd
        CALL    ReleaseDC
        ret

GetLogfont ENDP

you could create a local for the hDC
or POP it into EAX, then INVOKE ReleaseDC,hWnd,eax

i often look at the disassembly of my code
it bugs me when i POP a value from the stack, only to PUSH it back on there - lol

i am not real big on locals, either
i sometimes use them to help newbies understand the code, though
if i were going to create a local in this case, it would be to store the result from the GetObject call to return it
GetLogfont PROTO :HWND,:LPVOID

GetLogfont PROC hWnd:HWND,lpLogfont:LPVOID

        LOCAL   dwResult:DWORD

        INVOKE  GetDC,hWnd
        push    eax
        INVOKE  GetCurrentObject,eax,OBJ_FONT
        INVOKE  GetObject,eax,sizeof LOGFONT,lpLogfont
        mov     dwResult,eax
        push    hWnd
        CALL    ReleaseDC
        mov     eax,dwResult
        ret

GetLogfont ENDP

but - there is always a more efficient alternative to locals...
GetLogfont PROTO :HWND,:LPVOID

GetLogfont PROC USES EDI hWnd:HWND,lpLogfont:LPVOID

        INVOKE  GetDC,hWnd
        push    eax
        INVOKE  GetCurrentObject,eax,OBJ_FONT
        INVOKE  GetObject,eax,sizeof LOGFONT,lpLogfont
        xchg    eax,edi
        push    hWnd
        CALL    ReleaseDC
        xchg    eax,edi
        ret

GetLogfont ENDP