Any ideas where to find/how to implement GetLogFont (http://msdn.microsoft.com/en-us/library/zhcs623h(v=vs.80).aspx) in Masm32?
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
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
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
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
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
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.
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.
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
Hi Dave
esp+8 =hwnd is correct?
Why make you by GetDC esp+4?
this Parameter must a hWnd
INVOKE GetDC,[esp+8]
Greets,
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