(Enable Javascript for nicer formatting. Will make this server-side in the future.)

Table of Contents

Entry Point

See: WinMain

#include <windows.h>

int CALLBACK WinMain(HINSTANCE instance, HINSTANCE prevInstance, LPSTR cmd, int show) {
  return 0;
}

Creating a Window

See: WindowProc, DefWindowProcA, RegisterClassA, CreateWindowA

LRESULT CALLBACK windowProc(HWND window, UINT message, WPARAM wParam, LPARAM lParam) {
  return DefWindowProcA(window, message, wParam, lParam);
}

WNDCLASSA wc = {0};
wc.lpfnWndProc = windowProc;
wc.hInstance = instance;
wc.lpszClassName = "MyWindowClassName";
if (!RegisterClassA(&wc))
  return -1;

HWND window = CreateWindowA(wc.lpszClassName, "Window", WS_OVERLAPPEDWINDOW|WS_VISIBLE, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, 0, 0, instance, 0);
if (window == 0)
  return -1;

Window Message Loop

See: MSG, PeekMessageA, TranslateMessage, DispatchMessage

while (1) {
  MSG message;
  while (PeekMessageA(&message, window, 0, 0, PM_REMOVE)) {
    TranslateMessage(&message);
    DispatchMessage(&message);
  }
}