參考網站:
http://winapi.freetechsecrets.com/win32/
http://masm32.com/board/index.php?topic=3584.0
https://www.plantation-productions.com/Webster/
https://www.plantation-productions.com/Webster/Win32Asm/win32API.html
Polygon()可以用來繪製多邊形,需要傳入的資訊是一個座標點陣列,用來描述有哪些點需要被連接
main.hla
program main; #include("w.hhf") #include("args.hhf") #include("memory.hhf") #include("strings.hhf") static hWin: dword; hInstance: dword; CommandLine: string; defWndProc: dword; readonly szCaption: string:= "main"; procedure WndProc(hWnd:dword; uMsg:uns32; wParam:dword; lParam:dword); @stdcall; var hdc: dword; pen: dword; brush: dword; pt: w.POINT[3]; ps: w.PAINTSTRUCT; begin WndProc; if (uMsg == w.WM_PAINT) then w.BeginPaint(hWnd, ps); mov(eax, hdc); w.CreatePen(w.PS_SOLID, 3, $ff); mov(eax, pen); w.CreateSolidBrush($ff00); mov(eax, brush); w.SelectObject(hdc, pen); w.SelectObject(hdc, brush); mov(150, pt.x[@size(w.POINT) * 0]); mov(10, pt.y[@size(w.POINT) * 0]); mov(50, pt.x[@size(w.POINT) * 1]); mov(200, pt.y[@size(w.POINT) * 1]); mov(250, pt.x[@size(w.POINT) * 2]); mov(200, pt.y[@size(w.POINT) * 2]); w.Polygon(hdc, pt, 3); w.EndPaint(hWnd, ps); w.DeleteObject(pen); w.DeleteObject(brush); xor(eax, eax); elseif (uMsg == w.WM_CLOSE) then w.DestroyWindow(hWnd); xor(eax, eax); elseif (uMsg == w.WM_DESTROY) then w.PostQuitMessage(0); xor(eax, eax); else w.CallWindowProc(defWndProc, hWnd, uMsg, wParam, lParam); endif; end WndProc; procedure WinMain(hInst:dword; hPrevInst:dword; CmdLine:string; CmdShow:dword); var msg: w.MSG; begin WinMain; w.CreateWindowEx(w.WS_EX_LEFT, w.WC_DIALOG, szCaption, w.WS_OVERLAPPEDWINDOW | w.WS_VISIBLE, 0, 0, 300, 300, 0, 0, NULL, NULL); mov(eax, hWin); w.SetWindowLong(hWin, w.GWL_WNDPROC, &WndProc); mov(eax, defWndProc); forever w.GetMessage(msg, NULL, 0, 0); breakif(!eax); w.DispatchMessage(msg); endfor; mov(msg.wParam, eax); end WinMain; begin main; w.GetModuleHandle(NULL); mov(eax, hInstance); mov(arg.cmdLn(), CommandLine); WinMain(hInstance, NULL, CommandLine, w.SW_SHOWNORMAL); w.ExitProcess(eax); end main;
Line 38~44:使用三個座標點畫出一個三角形
完成