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



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

在Windows視窗程式設計中,當需要文字輸出顯示在視窗上時,一般都會使用自定義的字型,因為系統預設的字型太小,而自定義的字型,除了可以是粗體或者斜體,還可以設定自定義的長寬尺寸,司徒使用一個簡單例子來說明如何建立自定義的字型

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";
    szMsg:     string:= "Test";
    szFont:    string:= "Arial";
    OUT_OUTLINE_PRECIS:  dword:= 8;
    CLIP_DEFAULT_PRECIS: dword:= 0; 
    CLEARTYPE_QUALITY:   dword:= 5;

procedure WndProc(hWnd:dword; uMsg:uns32; wParam:dword; lParam:dword); @stdcall;
var
    hdc: dword;
    font: dword;
    ps: w.PAINTSTRUCT;
        
begin WndProc;
    if (uMsg == w.WM_PAINT) then
        w.BeginPaint(hWnd, ps);
        mov(eax, hdc);

        w.CreateFont(48, 0, 0, 0, w.FW_BOLD, 0, 0, 0, 0, 
            OUT_OUTLINE_PRECIS, CLIP_DEFAULT_PRECIS,
            CLEARTYPE_QUALITY, w.DEFAULT_PITCH | w.FF_DONTCARE, szFont);
        mov(eax, font);

        w.SetTextColor(hdc, $ff);
        w.SetBkMode(hdc, w.TRANSPARENT);
        w.SelectObject(hdc, font);
        w.TextOut(hdc, 100, 100, szMsg, str.length(szMsg));
     
        w.EndPaint(hWnd, ps);
        w.DeleteObject(font);
        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 33~36:創造一個大小48、粗體的Arial字型

完成