Steward
分享是一種喜悅、更是一種幸福
程式語言 - Netwide Assembler (NASM) - Win32 API - Painting - Draw Line
參考資訊:
https://masm32.com/board/index.php
https://www.nasm.us/xdoc/2.13rc9/html/nasmdoc0.html
線的起始點位置是位於(x=0, y=0),使用者可以呼叫MoveToEx()設定新的起始點,而使用LineTo()就可以畫出一條直線,新的起始點則是線的結束位置
main.asm
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 | % 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 CreateMyPen 3, 0ffh mov [hPen + 0], eax CreateMyPen 3, 0ff00h mov [hPen + 4], eax CreateMyPen 3, 0ff0000h mov [hPen + 8], eax DrawMyLine dword [hDC], dword [hPen + 0], 10, 100, 250, 100 DrawMyLine dword [hDC], dword [hPen + 4], 10, 150, 250, 150 DrawMyLine dword [hDC], dword [hPen + 8], 10, 200, 250, 200 push ps push dword [ ebp + ARG1 ] call EndPaint push dword [hPen + 0] call DeleteObject push dword [hPen + 4] call DeleteObject push dword [hPen + 8] 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~31:產生三支Pen並且畫出三條直線,需要注意的是,同一時間只能選擇一支Pen
完成