參考資訊:
https://masm32.com/board/index.php
https://www.nasm.us/xdoc/2.13rc9/html/nasmdoc0.html
Polygon()可以用來繪製多邊形,需要傳入的資訊是一個座標點陣列,用來描述有哪些點需要被連接
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 0ffh
push 3
push PS_SOLID
call CreatePen
mov [hPen], eax
push 0ff00h
call CreateSolidBrush
mov [hBrush], eax
push dword [hPen]
push dword [hDC]
call SelectObject
push dword [hBrush]
push dword [hDC]
call SelectObject
mov dword [pt + (POINT.SIZE * 0) + POINT.x], 150
mov dword [pt + (POINT.SIZE * 0) + POINT.y], 10
mov dword [pt + (POINT.SIZE * 1) + POINT.x], 50
mov dword [pt + (POINT.SIZE * 1) + POINT.y], 200
mov dword [pt + (POINT.SIZE * 2) + POINT.x], 250
mov dword [pt + (POINT.SIZE * 2) + POINT.y], 200
push 3
push pt
push dword [hDC]
call Polygon
push ps
push dword [ebp + ARG1]
call EndPaint
push dword [hPen]
call DeleteObject
push dword [hBrush]
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 40~49:使用三個座標點畫出一個三角形
完成