程式語言 - High Level Assembly (HLA) - Win32 API (HLA v1.x) - Painting - Draw Line



參考網站:
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

線的起始點位置是位於(x=0, y=0),使用者可以呼叫MoveToEx()設定新的起始點,而使用LineTo()就可以畫出一條直線,新的起始點則是線的結束位置

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[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[0]);
        w.CreatePen(w.PS_SOLID, 3, $ff00);
        mov(eax, pen[4]);
        w.CreatePen(w.PS_SOLID, 3, $ff0000);
        mov(eax, pen[8]);

        w.SelectObject(hdc, pen[0]);
        w.MoveToEx(hdc, 10, 100, NULL);
        w.LineTo(hdc, 250, 100);
   
        w.SelectObject(hdc, pen[4]);
        w.MoveToEx(hdc, 10, 150, NULL);
        w.LineTo(hdc, 250, 150);
        
        w.SelectObject(hdc, pen[8]);
        w.MoveToEx(hdc, 10, 200, NULL);
        w.LineTo(hdc, 250, 200);
        
        w.EndPaint(hWnd, ps);
        w.DeleteObject(pen[0]);
        w.DeleteObject(pen[4]);
        w.DeleteObject(pen[8]);
        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 28~45:產生三支Pen並且畫出三條直線,需要注意的是,同一時間只能選擇一支Pen

完成