#include <windows.h>
HWND stringView;

LRESULT CALLBACK WndProc(HWND h, UINT msg, WPARAM w, LPARAM k)
{
    switch (msg)
    {
    case WM_LBUTTONDOWN:
        SetWindowText(stringView, "mouse down");
        break;
    case WM_KEYDOWN:
        SetWindowText(stringView, "key down");
        break;
    case WM_DESTROY:
        PostQuitMessage(0);
        break;
    default:
        return DefWindowProc(h, msg, w, k);
    }
    return 0;
}

int APIENTRY WinMain(HINSTANCE h, HINSTANCE, LPSTR, int cmdShow)
{
    // 初始化全局字符串
    LPCSTR clsName = "mywincls";
    WNDCLASSEX wc = { 0 };
    wc.cbSize = sizeof(WNDCLASSEX);
    wc.lpfnWndProc = WndProc;
    wc.hInstance = h;
    wc.lpszClassName = clsName;
    RegisterClassEx(&wc);

    // 初始化应用程序
    HWND hWnd = CreateWindow(
        clsName, "标题", WS_OVERLAPPEDWINDOW,
        20, 0, 300, 200,
        NULL, NULL, h, NULL);

    if (!hWnd) return 0;

    stringView = CreateWindow("static", "",
        WS_CHILD | WS_VISIBLE | SS_SIMPLE,
        10, 10, 150, 150,
        hWnd, NULL, h, NULL);

    ShowWindow(hWnd, cmdShow);

    MSG msg;
    // 主消息循环
    while (GetMessage(&msg, NULL, 0, 0)) {
        TranslateMessage(&msg);
        DispatchMessage(&msg);
    }

    UnregisterClass(clsName, h);
    return (int)msg.wParam;
}