程式語言 - Wine - C/C++ - Draw Polygon



參考資訊:
http://www.winprog.org/tutorial/
http://winapi.freetechsecrets.com/win32/
https://github.com/gammasoft71/Examples_Win32
http://masm32.com/board/index.php?topic=3584.0
https://learn.microsoft.com/en-us/windows/win32/winmsg/window-styles

Polygon()可以用來繪製多邊形,需要傳入的資訊是一個座標點陣列,用來描述有哪些點需要被連接

main.c

#include <windows.h>
 
static HWND hWin = NULL;
static WNDPROC defWndProc = NULL;
 
static LRESULT CALLBACK WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
    HDC hdc = NULL;
    HPEN pen = NULL;
    HBRUSH brush = NULL;
    PAINTSTRUCT ps = { 0 };
    POINT pt[3] = { {150, 10}, {50, 200}, {250, 200} };
 
    switch (uMsg) {
    case WM_CLOSE:
        DestroyWindow(hWnd);
        return 0;
    case WM_DESTROY:
        PostQuitMessage(0);
        return 0;
    case WM_PAINT:
        hdc = BeginPaint(hWnd, &ps);
        pen = CreatePen(PS_SOLID, 3, RGB(0xff, 0x00, 0x00));
        brush = CreateSolidBrush(RGB(0x00, 0xff, 0x00));
        SelectObject(hdc, pen);
        SelectObject(hdc, brush);
        Polygon(hdc, pt, 3);
        EndPaint(hWnd, &ps);
        DeleteObject(pen);
        DeleteObject(brush);
        break;
    }

    return CallWindowProc(defWndProc, hWnd, uMsg, wParam, lParam);
}
 
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
    hWin = CreateWindow(WC_DIALOG, "main", WS_OVERLAPPEDWINDOW | WS_VISIBLE, 0, 0, 320, 240, NULL, NULL, NULL, NULL);
    defWndProc = (WNDPROC)SetWindowLongPtr(hWin, GWLP_WNDPROC, (long int)WndProc);
 
    MSG msg = { 0 };
    while (GetMessage(&msg, NULL, 0, 0)) {
        DispatchMessage(&msg);
    }

    return 0;
}

編譯、執行

$ winegcc main.c -o main -lgdi32
$ wine main.exe.so