# Direct Win32 API and Weird-Shaped Windows

Ivan Rogoz laments the state of modern Windows apps — Electron bloatware where Notepad takes 50MB — and shows that Win32 still lets you build software with a physical presence. The article walks through three techniques for non-rectangular windows, with working code.

## The message-driven model

Win32 doesn't give you an update loop. It gives you messages:

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

Windows sends events (WM_CREATE, WM_PAINT, WM_SIZE, WM_DESTROY), and your window procedure decides what they mean. You build behavior one message at a time. Once you understand this, weird-shaped windows stop feeling mysterious.

## Technique 1: Window regions

A normal window is rectangular, but Windows has region objects (HRGN). Assign one with `SetWindowRgn` and only that part counts as the actual window — visually and interactively.

```c
region = CreateEllipticRgn(0, 0, rc.right, rc.bottom);
SetWindowRgn(hwnd, region, TRUE);
```

That's enough for an oval window. Not a fake oval painted inside a rectangle, but an actual oval HWND.

The catch: once you remove the title bar, the system won't drag the window for you. So on WM_LBUTTONDOWN, you fake a title-bar drag by sending WM_NCLBUTTONDOWN with HTCAPTION. Making the shape is easy; replacing what the normal frame did for free is the real work.

## Technique 2: Bitmap-derived regions

Instead of mathematical shapes, derive the region from bitmap data. Load an image, scan pixels row by row, combine non-transparent runs into rectangles, merge into a final region.

```c
#define TRANSPARENT_COLOR RGB(255, 0, 255)
```

Magenta means empty space. Everything else becomes part of the window. The bitmap does two jobs: it's what you paint in WM_PAINT, and it's the shape of the window itself.

This is how old skinned apps worked. If the image looked like a dog, a spaceship, or a stereo, the window could be that shape. The frame stopped being a law of nature and became just another asset.

## Technique 3: Layered windows

Bitmap regions have hard edges — a pixel is either in or out. For soft edges, translucency, or animation, use layered windows.

Create a `WS_EX_LAYERED` popup and upload a 32-bit alpha image with `UpdateLayeredWindow`. The article demonstrates an animated desktop mascot using a sprite sheet, advancing frames on a timer, drawing with GDI+. You're not saying "my window is an ellipse" — you're saying "my window is whatever these pixels are right now."

Per-pixel alpha, cleaner edges, proper transparency, and freedom to change shape every frame.

## Why this disappeared

Custom windows mean doing everything yourself: dragging, resizing, close behavior, hit testing, keyboard handling, repaint correctness, DPI handling. Easy to prototype, expensive to polish.

Desktop UI culture shifted. The Windows XP era celebrated crazy skins — media players that looked like hardware, desktop mascots, utility panels shaped like alien control consoles. Then weird windows became associated with gimmicks, adware, and bloated utilities. The norm moved to "work reliably and get out of my way."

Most of the time, a normal rectangular window is the right answer. But it's a choice, not a law. Win32 doesn't try to talk you out of any of this. It gives you the messages, the handles, the drawing APIs, and enough rope to build something interesting.

## Connection to Win32 stability

This article complements [[win32-stable-abi]]. Win32's stability isn't just about binary compatibility — it's about a programming model that still works exactly as documented decades ago. The same region APIs from Windows 95 work today. The platform may be unfashionable, but it remains capable of things modern frameworks can't easily replicate.

Code: [github.com/IvRogoz/WierdApps](https://github.com/IvRogoz/WierdApps)
