程式語言 - Netwide Assembler (NASM) - Win32 API (NASMX) - Painting - Draw Polygon



參考資訊:
https://masm32.com/board/index.php
https://www.nasm.us/xdoc/2.13rc9/html/nasmdoc0.html

Polygon()可以用來繪製多邊形,需要傳入的資訊是一個座標點陣列,用來描述有哪些點需要被連接

main.asm

    %include "c:\\nasmx\\inc\\nasmx.inc"
    %include "c:\\nasmx\\inc\\win32\\msvcrt.inc"
    %include "c:\\nasmx\\inc\\win32\\windows.inc"
    %include "c:\\nasmx\\inc\\win32\\gdi32.inc"
    %include "c:\\nasmx\\inc\\win32\\user32.inc"
    %include "c:\\nasmx\\inc\\win32\\kernel32.inc"
          
    entry start
          
    section .data
hWin         dd 0
hInstance    dd 0
defWndProc   dd 0
CommandLine  dd 0
szCaption    declare(NASMX_TCHAR) NASMX_TEXT("main"),0
pt           times sizeof(POINT) * 3 db

NASMX_ISTRUC msg, MSG
NASMX_IENDSTRUC
      
NASMX_ISTRUC ps, PAINTSTRUCT
NASMX_IENDSTRUC
           
    section .text
proc WndProc, dword hWnd, uint_t uMsg, dword wParam, dword lParam
    locals
        local hdc, DWORD
        local pen, DWORD
        local brush, DWORD
    endlocals
        
    switch dword [argv(.uMsg)]
    case dword WM_PAINT
        invoke BeginPaint, [argv(.hWnd)], ps
        mov [var(.hdc)], eax
      
        invoke CreatePen, PS_SOLID, 3, 0ffh
        mov [var(.pen)], eax
        invoke CreateSolidBrush, 0ff00h
        mov [var(.brush)], eax
    
        invoke SelectObject, [var(.hdc)], [var(.pen)]
        invoke SelectObject, [var(.hdc)], [var(.brush)]

        mov dword [pt + (sizeof(POINT) * 0) + POINT.x], 150
        mov dword [pt + (sizeof(POINT) * 0) + POINT.y], 10
        mov dword [pt + (sizeof(POINT) * 1) + POINT.x], 50
        mov dword [pt + (sizeof(POINT) * 1) + POINT.y], 200
        mov dword [pt + (sizeof(POINT) * 2) + POINT.x], 250
        mov dword [pt + (sizeof(POINT) * 2) + POINT.y], 200
        invoke Polygon, [var(.hdc)], pt, 3
     
        invoke EndPaint, [argv(.hWnd)], ps
        invoke DeleteObject, [var(.pen)]
        invoke DeleteObject, [var(.brush)]
        break
    case dword WM_CLOSE
        invoke DestroyWindow, [argv(.hWnd)]
        break
    case dword WM_DESTROY
        invoke PostQuitMessage, 0
        break
    default
        invoke CallWindowProc, [defWndProc], [argv(.hWnd)], [argv(.uMsg)], [argv(.wParam)], [argv(.lParam)]
    endswitch
endproc
           
proc WinMain, dword hInst, dword hPrevInst, dword CmdLine, dword CmdShow
    locals none
            
    invoke CreateWindowEx, WS_EX_LEFT, WC_DIALOG, szCaption, \
        WS_OVERLAPPEDWINDOW | WS_VISIBLE, 0, 0, 300, 300, NULL, NULL, NULL, NULL
    mov [hWin], eax
           
    invoke SetWindowLong, [hWin], GWL_WNDPROC, WndProc
    mov [defWndProc], eax
       
    do
        invoke DispatchMessage, msg
        invoke GetMessage, msg, NULL, NULL, NULL
    while eax, !=, 0
            
    mov eax, dword [msg + MSG.wParam]
endproc
            
proc start, dword argc, dword argv
    locals none
            
    invoke GetModuleHandle, NULL
    mov [hInstance], eax
            
    invoke GetCommandLine, NULL
    mov [CommandLine], eax
            
    invoke WinMain, [hInstance], NULL, [CommandLine], SW_SHOWNORMAL
    invoke ExitProcess, NULL
endproc

Line 45~51:使用三個座標點畫出一個三角形

完成