Skip to content

Instantly share code, notes, and snippets.

@technoscavenger
Last active January 27, 2026 20:00
Show Gist options
  • Select an option

  • Save technoscavenger/56921adcfea8bb1a30ea44c2c4725851 to your computer and use it in GitHub Desktop.

Select an option

Save technoscavenger/56921adcfea8bb1a30ea44c2c4725851 to your computer and use it in GitHub Desktop.
Hello Window using Zig lang
pub const UNICODE = true;
const win32 = @import("win32").everything;
const L = win32.L;
const HWND = win32.HWND;
pub export fn wWinMain(
hInstance: win32.HINSTANCE,
_: ?win32.HINSTANCE,
pCmdLine: [*:0]u16,
nCmdShow: u32,
) callconv(.winapi) c_int {
_ = pCmdLine;
_ = nCmdShow;
const CLASS_NAME = L("Sample Window Class");
const wc = win32.WNDCLASSW{
.style = .{},
.lpfnWndProc = WindowProc,
.cbClsExtra = 0,
.cbWndExtra = 0,
.hInstance = hInstance,
.hIcon = null,
.hCursor = win32.LoadCursorW(null, win32.IDC_ARROW),
.hbrBackground = @ptrFromInt(@intFromEnum(win32.COLOR_WINDOW) + 1),
.lpszMenuName = L("Some Menu Name"),
.lpszClassName = CLASS_NAME,
};
if (0 == win32.RegisterClassW(&wc))
win32.panicWin32("RegisterClass", win32.GetLastError());
const hwnd = win32.CreateWindowExW(
.{},
CLASS_NAME,
L("Hello Windows"),
win32.WS_OVERLAPPEDWINDOW,
win32.CW_USEDEFAULT,
win32.CW_USEDEFAULT, // Position
400,
200, // Size
null, // Parent window
null, // Menu
hInstance, // Instance handle
null, // Additional application data
) orelse win32.panicWin32("CreateWindow", win32.GetLastError());
_ = win32.ShowWindow(hwnd, .{ .SHOWNORMAL = 1 });
var msg: win32.MSG = undefined;
while (win32.GetMessageW(&msg, null, 0, 0) != 0) {
_ = win32.TranslateMessage(&msg);
_ = win32.DispatchMessageW(&msg);
}
return @intCast(msg.wParam);
}
fn WindowProc(
hwnd: HWND,
uMsg: u32,
wParam: win32.WPARAM,
lParam: win32.LPARAM,
) callconv(.winapi) win32.LRESULT {
switch (uMsg) {
win32.WM_DESTROY => {
win32.PostQuitMessage(0);
return 0;
},
else => {},
}
return win32.DefWindowProcW(hwnd, uMsg, wParam, lParam);
}
pub export fn WinMain(
hInstance: win32.HINSTANCE,
hPrevInstance: ?win32.HINSTANCE,
pCmdLine: [*:0]u8,
nShowCmd: u32,
) callconv(.winapi) c_int {
_ = pCmdLine;
return wWinMain(
hInstance,
hPrevInstance,
win32.GetCommandLineW().?,
nShowCmd,
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment