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



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

繪畫的顏色設定可以分成Brush、Pen兩種,Brush代表填充的顏色,Pen則是線條的顏色

main.hla

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
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;
    brush: dword;
    ps: w.PAINTSTRUCT;
  
begin WndProc;
    if (uMsg == w.WM_PAINT) then
        w.BeginPaint(hWnd, ps);
        mov(eax, hdc);
 
        w.CreateSolidBrush($ff);
        mov(eax, brush);
        w.FillRect(hdc, ps.rcPaint, brush);
  
        w.EndPaint(hWnd, ps);
        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 28~29:產生一個紅色的Brush
Line 30:將可視區域填入紅色
Line 33:釋放資源

完成