A tiny Windows system-tray app that shows which virtual desktop you're on as a number in the notification area — and, unlike the alternatives, does not interfere with desktop switching.
Other tray indicators (e.g. dankrusi's Windows Virtual Desktop Helper) poll the undocumented virtual-desktop COM API on a tight loop — typically every 100 ms. That cross-process polling contends with explorer's switch animation, so holding Ctrl+Win+←/→ can glitch: the next desktop flashes, then snaps back; rapid switching lands on the wrong desktop. (See WindowsVirtualDesktopHelper issue #166.)
TrayNum never polls. It registers for desktop-change events and only redraws when the desktop actually changes, so it has nothing running during a switch to fight it. Switching stays smooth; idle CPU is ~0%.
- UI: ~200 lines of C# / WinForms (
NotifyIcon). The number is drawn as a vector glyph scaled to fill the tray tile. - Backend: Ciantic/VirtualDesktopAccessor (
VirtualDesktopAccessor.dll, MIT). ItsRegisterPostMessageHookposts a Windows message on every desktop change; TrayNum listens for it. All the fragile, per-Windows-build COM interop lives in that maintained DLL — TrayNum hardcodes no GUIDs.
- Desktop number in the tray, updated instantly on switch (1-based, matches Windows).
- Right-click menu:
- Box around number — draw a border around the digit (persisted).
- Start with Windows — toggle launch at login (HKCU
Run). - Exit.
- Windows 10 / 11 (built & tested on Windows 11 25H2, build 26200).
- .NET Framework 4.x runtime (ships with Windows). No SDK needed to build — uses the in-box
csc.exe.
.\build.ps1Produces TrayNum.exe next to VirtualDesktopAccessor.dll. Run it; the icon appears in the tray.
The x64
VirtualDesktopAccessor.dllmust sit next toTrayNum.exe. It is bundled in this repo; updates are at the VirtualDesktopAccessor releases. If a future Windows build breaks desktop detection, drop in a newer DLL.
You almost never need to touch this app. TrayNum.exe only calls stable exported function names, so it is unaffected by Windows updates. All the fragile, build-specific virtual-desktop COM interop lives in VirtualDesktopAccessor.dll.
- Monthly cumulative updates (build revision bumps): no effect.
- Annual feature updates (e.g. 24H2 → 25H2): usually no effect. Microsoft only occasionally reorders the internal virtual-desktop COM interface (24H2 was one such change).
- If detection ever breaks — the tray number stops changing, or the app fails to launch — download the latest
VirtualDesktopAccessor.dllfrom the Ciantic releases and drop it next toTrayNum.exe. No recompile needed.
Built and tested on Windows 11 25H2 (build 26200).
- Virtual-desktop interop: Ciantic/VirtualDesktopAccessor by Jari Pennanen (MIT). See THIRD-PARTY-NOTICES.md.
MIT.
