參考資訊:
https://masm32.com/board/index.php
https://www.nasm.us/xdoc/2.13rc9/html/nasmdoc0.html
在Windows視窗程式設計中,當需要文字輸出顯示在視窗上時,一般都會使用自定義的字型,因為系統預設的字型太小,而自定義的字型,除了可以是粗體或者斜體,還可以設定自定義的長寬尺寸,司徒使用一個簡單例子來說明如何建立自定義的字型
main.asm
%include "head.asm"
segment .text
WndProc:
push ebp
mov ebp, esp
cmp dword [ebp + ARG2], WM_PAINT
je .handle_paint
cmp dword [ebp + ARG2], WM_CLOSE
je .handle_close
cmp dword [ebp + ARG2], WM_DESTROY
je .handle_destroy
jmp .handle_default
.handle_paint:
push ps
push dword [ebp + ARG1]
call BeginPaint
mov [hDC], eax
push szFont
push DEFAULT_PITCH | FF_DONTCARE
push CLEARTYPE_QUALITY
push CLIP_DEFAULT_PRECIS
push OUT_OUTLINE_PRECIS
push 0
push false
push false
push false
push FW_BOLD
push 0
push 0
push 0
push 48
call CreateFont
mov [hFont], eax
push 0ffh
push dword [hDC]
call SetTextColor
push TRANSPARENT
push dword [hDC]
call SetBkMode
push dword [hFont]
push dword [hDC]
call SelectObject
push MsgLen
push szMsg
push 100
push 100
push dword [hDC]
call TextOut
push ps
push dword [ebp + ARG1]
call EndPaint
push dword [hFont]
call DeleteObject
xor eax, eax
jmp .finish
.handle_close:
push dword [ebp + ARG1]
call DestroyWindow
xor eax, eax
jmp .finish
.handle_destroy:
push 0
call PostQuitMessage
xor eax, eax
jmp .finish
.handle_default:
push dword [ebp + ARG4]
push dword [ebp + ARG3]
push dword [ebp + ARG2]
push dword [ebp + ARG1]
push dword [pDefWndProc]
call CallWindowProc
.finish:
leave
ret 16
WinMain:
push ebp
mov ebp, esp
push 0
push 0
push 0
push 0
push 300
push 300
push 0
push 0
push WS_OVERLAPPEDWINDOW | WS_VISIBLE
push szAppName
push WC_DIALOG
push WS_EX_LEFT
call CreateWindowEx
mov [hWin], eax
push WndProc
push GWL_WNDPROC
push dword [hWin]
call SetWindowLong
mov [pDefWndProc], eax
.loop:
push 0
push 0
push 0
push msg
call GetMessage
cmp eax, 0
je .exit
push msg
call DispatchMessage
jmp .loop
.exit:
mov eax, [msg + MSG.wParam]
leave
ret 16
_start:
push 0
call GetModuleHandle
mov [hInstance], eax
call GetCommandLine
mov [pCommand], eax
push SW_SHOWNORMAL
push dword [pCommand]
push 0
push dword [hInstance]
call WinMain
push eax
call ExitProcess
Line 22~37:創造一個大小48、粗體的Arial字型
完成