Desenha um retângulo na área do cliente

main.html
#include <windows.h>

LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wP, LPARAM lP) {
    PAINTSTRUCT ps;
    HBRUSH hBrush;
    HDC hdc;
    RECT rect;
    
    switch(msg) {
        case WM_PAINT:
            BeginPaint(hwnd, &ps);
            hdc = GetDC(hwnd);
            GetClientRect(hwnd, &rect);
            hBrush = CreateSolidBrush(RGB(0, 77, 77));
            hBrush = (HBRUSH) SelectObject(hdc, hBrush);
            Rectangle(hdc, 80,80,rect.right,rect.bottom);
            DeleteObject(SelectObject(hdc, hBrush));
            EndPaint(hwnd, &ps);
            break;
        case WM_DESTROY: {
            PostQuitMessage(0);
            break;
        }
        default:
            return DefWindowProc(hwnd, msg, wP, lP);
    }
    return 0;
}

int WINAPI WinMain(HINSTANCE hI, HINSTANCE hPI, LPSTR szCL, int iCS) {
    WNDCLASSEX wc; /* A properties struct of our window */
    HWND hwnd;
    MSG msg; /* A temporary location for all messages */

    /* zero out the struct and set the stuff we want to modify */
    memset(&wc,0,sizeof(wc));
    wc.cbSize      = sizeof(WNDCLASSEX);
    wc.lpfnWndProc = WndProc;
    wc.hInstance   = hI;
    wc.hCursor     = LoadCursor(NULL, IDC_ARROW);
    wc.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
    wc.lpszClassName = "WindowClass";
    wc.hIcon         = LoadIcon(NULL, IDI_APPLICATION);
    wc.hIconSm       = LoadIcon(NULL, IDI_APPLICATION);

    if(!RegisterClassEx(&wc)) {
        MessageBox(
            NULL,
            "Window Registration Failed!",
            "Error!",
            MB_ICONEXCLAMATION | MB_OK
        );
        return 0;
    }

    hwnd = CreateWindowEx(
        WS_EX_CLIENTEDGE,
        "WindowClass",
        "Desenha um retângulo",
        WS_VISIBLE | WS_OVERLAPPEDWINDOW,
        200, /* x */
        40, /* y */
        360, /* width */
        360, /* height */
        NULL,
        NULL,
        hI,
        NULL
    );

    if(hwnd == NULL) {
        MessageBox(
            NULL,
            "Window Creation Failed!",
            "Error!",
            MB_ICONEXCLAMATION|MB_OK
        );
        return 0;
    }

    while(GetMessage(&msg, NULL, 0, 0) > 0) { /* If no error is received... */
        TranslateMessage(&msg); /* Translate key codes to chars if present */
        DispatchMessage(&msg); /* Send it to WndProc */
    }
    return msg.wParam;
}

Comentários