---
title: "Windows"
url: https://recursiveai.org/oneplatform/docs/windows-shell/
description: "What the Win32 backend does as a desktop-app backend, and what it leaves to the app."
version: "1.0.0"
source: https://github.com/recursive-ai-oss/oneplatform-csharp/blob/37f5a73c449624ea8671f8612d61000e2d57aa5e/docs/windows-shell.md
---

# Windows

What the Win32 backend does as a desktop-app backend, and what it leaves to the app.

## Windows

| Feature | How |
|---|---|
| Ordinary window | Decorated, movable, resizable, with the system frame and per-monitor v2 DPI (`WM_DPICHANGED` applies the rectangle Windows suggests, so a window dragged between monitors keeps its physical size). |
| Size limits | `MinWidth`..`MaxHeight` and `Window.SetSizeLimits` answer `WM_GETMINMAXINFO`; the limits are client sizes and the frame is added. |
| Dialog | `WindowOptions.Parent` makes an owned window: it stays above its parent, is centred over it when no placement is given, minimizes and closes with it, and has no taskbar button. |
| Overlay | `WindowOptions.Overlay` makes a topmost tool window placed from its anchors and margins on the primary work area. `OverlayKeyboard.None` also sets `WS_EX_NOACTIVATE`, so clicking it never steals the focus. |
| Popup | `PlatformApp.CreatePopup` makes a borderless owned window placed against the anchor rectangle, flipped when it would leave the work area. With `Grab`, the application losing the foreground (`WM_ACTIVATEAPP`) posts `PopupDismissed` and closes it. |
| Frameless | `Decorations = None` is a popup-style window that keeps its resize edges (`WM_NCCALCSIZE` gives the client the whole window); `StartMove`/`StartResize` hand a drag to the system (`SC_MOVE`/`SC_SIZE`). |
| Keep above | `SetKeepAbove` uses `HWND_TOPMOST` without activating or moving the window. |
| Activation | `Window.Activate` restores a minimized window and takes the foreground. Windows only allows that to a process that has the foreground, was started by the foreground process or was granted it, so the call falls back to briefly joining the foreground thread's input queue. |
| `FillSolid` | Paints the client area with a GDI brush, also on `WM_PAINT`, for tests and placeholders. |
| Pointer capture and input method | The window captures the mouse while a button is down; `WM_IME_*` composition and candidate messages become text-input events. |

A window belongs to the thread that created it: create it, pump it and call its members on one thread. An `await` that resumes on another thread cannot pump the window's messages.

## Second launch

`LocalSingleInstance` works on Windows over a Unix-domain socket in the per-user temp folder (the same transport as on macOS). The running copy sends its process id first; the second launch, which the user just started and so may give the foreground away, calls `WindowActivation.AllowForeground(pid)` and then sends its arguments. The running copy then calls `Window.Activate`.

## Desktop services: `OnePlatform.Shell.WindowsDesktop`

The counterpart of `MacDesktop` for Windows, over the Win32 Shell APIs, with the same models (`TrayMenuItem`, `NativeMenu`, `FileChooserOptions`/`FileChooserResult`, `DesktopNotification`, `GlobalShortcut`, `ShellUnavailableException`). Create it after the Win32 `PlatformApp`, on the thread that pumps it, with a `post` delegate that runs actions on that thread. Events (a menu item, a click on the icon or a notification, a hotkey) go through `post`.

In a menu label or menu bar title a single `&` marks the mnemonic letter (`&File` opens with Alt+F) and `&&` is a literal ampersand.

| Service | API | How, and limits |
|---|---|---|
| Tray icon | `ShowTrayIcon(tooltip, iconPath, menu)`, `SetTrayMenu`, `TrayActivated`, `GetTrayBounds` | `Shell_NotifyIcon` (version 4 callbacks) with a hidden message window. A right click shows the menu with `TrackPopupMenuEx`; separators, checkmarks, submenus, disabled items and shortcut text are drawn. The icon is an `.ico` or `.png` file, or the default application icon. One icon at a time. The icon comes back after the shell restarts. Windows 11 puts a new icon in the overflow flyout until it is promoted in the taskbar settings; `GetTrayBounds` then answers with the flyout button. |
| Notifications | `ShowAsync`, `CloseAsync`, `ActionInvoked` | A shell balloon (`NIF_INFO`), which Windows 10 and 11 draw as a toast, from the tray icon (or a temporary icon if none is shown). Title (63 characters), body (255), `DefaultAction` reported when the toast is clicked. **Buttons and reply fields are not possible this way**: they need a toast from an app with a package identity or a registered application id and a COM activator (the Windows App SDK's notification model), and a notification with `Buttons` throws `ShellUnavailableException`. Focus assist can hold a toast back without an error. When Windows has notifications switched off for a **packaged** app, `ShowAsync` fails with `NotificationsDisabledException` (a `ShellUnavailableException`) whose `Setting` is the toast notifier's `NotificationSetting`: `DisabledForApplication`, `DisabledForUser`, `DisabledByGroupPolicy` or `DisabledByManifest`. Windows exposes that setting only through the WinRT toast notifier, which needs a package identity, so an **unpackaged** app gets no answer: its balloon is sent and Windows may still drop it. Windows takes a change of the switch into the notification platform after a few seconds, so a call made just after the user turns notifications off can still be sent. |
| File and folder dialogs | `OpenFileAsync`, `OpenFolderAsync`, `SaveFileAsync` | The Common Item Dialog through source-generated COM (`GeneratedComInterface`), on its own single-threaded-apartment thread, so the app keeps pumping. Title, accept label, start folder, suggested name, multi-select, filters by glob (MIME types have no meaning and match everything), overwrite prompt, default extension from the first filter. Owner: `ParentWindow = "win32:<hex of Window.NativeHandle.Window>"`. |
| Global hotkeys | `BindAsync`, `Activated`, `Deactivated` | `RegisterHotKey` without auto-repeat. Windows reports presses only, so after each press the main key is polled every 15 ms with `GetAsyncKeyState` and `Deactivated` follows within about 15 ms of the release; modifiers are not watched. A key another program holds throws `ShellUnavailableException` ("another application already uses ..."), and keys bound earlier in the same call are given back. A trigger such as `CTRL+ALT+d` is required; Windows has no shortcut chooser. |
| Menu bar | `SetMenuBar(window, menus)`, `ClearMenuBar` | `SetMenu` on a decorated window, with each item's `Shortcut` shown at the right and, when enabled, handled as an accelerator whenever the window has the focus. The client area keeps its size. The bar is rebuilt, not live: call again to change a checkmark. Frameless, overlay and popup windows cannot carry one. |
| Screenshots | `CaptureWindow(window, clientAreaOnly)`, `CaptureRegionAsync()` | `CaptureWindow` reads only the app's own window with `PrintWindow`, so nothing of another program is in it even when windows overlap. `CaptureRegionAsync` shows a dimmed see-through layer, lets the user drag a rectangle and copies the pixels only after the button is released; Escape or a right click cancels. No pixel of the screen is read before the user chooses the area. Both return a `ScreenshotImage` (BGRA pixels, `ToPng()`). |

The tests in `tests/OnePlatform.Tests/WindowsDesktopTests.cs` use real input (`SendInput`) on a Windows desktop and drive the menu bar by mouse, by Alt and a mnemonic, and by accelerator; the tray icon and its menu; a notification and a click on its toast; the three dialogs owned by a window; a hotkey pressed while another window has the focus; and both screenshots. The notification setting's mapping to `NotificationsDisabledException` is tested on every OS; `tools/toast/proof.ps1` runs `tests/OnePlatform.ToastProof` as a packaged app with the setting off and on and keeps pictures of both.

## Not here

Third-party toasts with actions, jump lists, taskbar progress and overlay icons, a Windows-side single-instance service beyond `LocalSingleInstance`, and the UI Automation patterns listed in `accessibility.md` as missing. Overlays are placed on the primary monitor only. The tests do not cover a GPU, multiple monitors, high-DPI scaling or a real input-method editor.
