News:

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

GetLogFont

Started by jj2007, April 20, 2012, 03:48:38 PM

Previous topic - Next topic

jj2007

Any ideas where to find/how to implement GetLogFont in Masm32?

dedndave

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

dedndave

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

dedndave

#3
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

dedndave

#4
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

jj2007

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

baltoro

JOCHEN,   
I assume that you don't want to implement the MFC (Microsoft Foundation Classes) version of: CreateFont. The key is the LOGFONT structure.
Baltoro

jj2007

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.

dedndave

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

ragdog

Hi Dave

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

INVOKE  GetDC,[esp+8]


Greets,

dedndave

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