首页 > 代码库 > 【Win32】Windows

【Win32】Windows

#include <windows.h>

LRESULT CALLBACK WindowProc(
    HWND hwnd,
    UINT uMsg,
    WPARAM wParam,
    LPARAM lParam)
{
    switch (uMsg)
    {
    case WM_DESTROY:
        PostQuitMessage(0);
        return 0;
    }
    return DefWindowProc(hwnd, uMsg, wParam, lParam);
}

int CALLBACK WinMain(
    HINSTANCE hInstance,
    HINSTANCE hPrevInstance,
    LPSTR lpCmdLine,
    int nCmdShow)
{
    static TCHAR lpClassName[] = TEXT("Susake");

    HWND hwnd;
    MSG msg;
    WNDCLASSEX wincl;

    wincl.cbSize = sizeof(WNDCLASSEX);
    wincl.style = NULL;
    wincl.lpfnWndProc = WindowProc;
    wincl.cbClsExtra = 0;
    wincl.cbWndExtra = 0;
    wincl.hInstance = hInstance;
    wincl.hIcon = NULL;
    wincl.hCursor = NULL;
    wincl.hbrBackground = NULL;
    wincl.lpszMenuName = NULL;
    wincl.lpszClassName = lpClassName;
    wincl.hIconSm = NULL;

    RegisterClassEx(&wincl);

    hwnd = CreateWindowEx(0,
        lpClassName,
        TEXT("Susake"),
        WS_OVERLAPPEDWINDOW,
        0, 0,
        800, 600,
        HWND_DESKTOP,
        NULL,
        hInstance,
        NULL);

    ShowWindow(hwnd, nCmdShow);

    UpdateWindow(hwnd);

    while (GetMessage(&msg, NULL, 0, 0))
    {
        TranslateMessage(&msg);
        DispatchMessage(&msg);
    }

    UnregisterClass(lpClassName, wincl.hInstance);
    return msg.wParam;
}