// Minimal Win32 window — the irreducible message-pump sequence GLFW/SDL/winit wrap
// on Windows: RegisterClassExW -> CreateWindowExW -> ShowWindow -> GetMessage /
// DispatchMessage, with a WndProc handling WM_PAINT/WM_DESTROY. Uses druntime's
// built-in `core.sys.windows` bindings (the windows.h projection that ships with
// LDC/DMD) — no third-party. For full SDK coverage the windows-d package is the
// upgrade; see ../index.md (the Win32 OS-API survey).
//
// Bounded: paints once then PostQuitMessage so CI never blocks. Windows always has
// a window station (even on a headless CI runner), so no SKIP gate is needed.
module (module) appapp;
import (package) corecore.(package) core.syssys.(package) core.sys.windowswindows.(module) core.sys.windows.windowsWindows API header module
Translated from MinGW API for MS-Windows 4.0
Source
core/sys/windows/windows.d
windows;
import (package) corecore.(package) core.stdcstdc.(module) core.stdc.stdioD header file for C99 <stdio.h>
pubs.opengroup.org/onlinepubs/009695399/basedefs/stdio.h.html, stdio.h
Source
core/stdc/stdio.d
stdio : (alias) app.printf = int core.stdc.stdio.printf(scope const(char*) format, scope const ...) nothrow @nogcprintf;
extern (Windows) LRESULT app.wndProcwndProc(HWND (parameter) HWND hwndhwnd, UINT (parameter) UINT msgmsg, WPARAM wParam, LPARAM lParam) nothrow
{
switch (msg)
{
case WM_PAINT:
PAINTSTRUCT _error_ psps;
HDC _error_ hdchdc = BeginPaint(hwnd, &ps);
RECT _error_ rcrc;
GetClientRect(hwnd, &rc);
FillRect(hdc, &rc, cast(HBRUSH)(COLOR_WINDOW + 1));
EndPaint(hwnd, &ps);
PostQuitMessage(0); // bounded: exit after the first paint
return 0;
case WM_DESTROY:
PostQuitMessage(0);
return 0;
default:
return DefWindowProcW(hwnd, msg, wParam, lParam);
}
}
int int D main()main()
{
HINSTANCE (local variable) _error_ hInsthInst = GetModuleHandleW(null);
auto (local variable) wstring clsNameclsName = "SparklesWin32"w;
// 1. Register the window class (WndProc + class name).
WNDCLASSEXW (local variable) _error_ wcwc;
wc.cbSize = WNDCLASSEXW.sizeof;
wc.lpfnWndProc = &wndProc;
wc.hInstance = hInst;
wc.lpszClassName = clsName.ptr;
wc.hCursor = LoadCursorW(null, IDC_ARROW);
if (!RegisterClassExW(&wc))
{
int core.stdc.stdio.printf(scope const(char*) format, scope const ...) nothrow @nogcprintf("RegisterClassExW failed (%lu)\n", GetLastError());
return 1;
}
// 2. Create a standard overlapped (titled, resizable) top-level window.
HWND (local variable) _error_ hwndhwnd = CreateWindowExW(0, clsName.ptr, "Sparkles · Win32"w.ptr,
WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, 480, 320,
null, null, hInst, null);
if (hwnd is null)
{
int core.stdc.stdio.printf(scope const(char*) format, scope const ...) nothrow @nogcprintf("CreateWindowExW failed (%lu)\n", GetLastError());
return 1;
}
// 3. Show it and run the message pump until WM_QUIT.
ShowWindow(hwnd, SW_SHOW);
UpdateWindow(hwnd);
MSG (local variable) _error_ msgmsg;
while (GetMessageW(&msg, null, 0, 0) > 0)
{
TranslateMessage(&msg);
DispatchMessageW(&msg);
}
int core.stdc.stdio.printf(scope const(char*) format, scope const ...) nothrow @nogcprintf("ok: created a Win32 window and pumped messages to WM_QUIT\n");
return cast(int) msg.wParam;
}