#include <windows.h>
HINSTANCE hInst;   // 当前实例
HWND stringView;

//  函数: WndProc(HWND, UINT, WPARAM, LPARAM)
//  目的:    处理主窗口的消息。
//  WM_DESTROY  - 发送退出消息并返回
LRESULT CALLBACK WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
    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(hWnd, msg, wParam, lParam);
    }
    return 0;
}

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

    // 初始化应用程序
    hInst = h;
    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, hInst, NULL);

    ShowWindow(hWnd, cmdShow);
    UpdateWindow(hWnd);

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

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