A lightweight Windows 11 desktop utility that allows users to set multiple application windows as "Always on Top" with customizable priority rankings.
- β Multi-Window Selection: Select multiple windows simultaneously to apply always-on-top behavior
- β Priority Ranking System: Assign explicit priority numbers (1 = highest) to control window stacking order
- β Dynamic Z-Order Management: Automatically maintains window order even when windows gain/lose focus
- β Real-time Monitoring: Background service ensures windows stay in correct order (500ms polling)
- β Clean UI: Modern WPF interface with visual feedback
- β Low Resource Usage: Minimal CPU and memory footprint
- β Portable Executable: Single self-contained .exe file
-
Primary APIs Used:
EnumWindows- Enumerate all top-level windowsSetWindowPos- Modify window Z-order and topmost flagGetWindowLong/SetWindowLong- Read/modify window styles (WS_EX_TOPMOST)IsWindowVisible- Filter visible windowsDwmGetWindowAttribute- Detect cloaked windows (virtual desktops)
-
Key Constants:
HWND_TOPMOST (-1)- Places window above all non-topmost windowsHWND_NOTOPMOST (-2)- Removes topmost statusWS_EX_TOPMOST (0x0008)- Extended window style flag for topmostSWP_NOACTIVATE (0x0010)- Prevents window activation when repositioning
- Maintains a list of managed windows with priority assignments
- Background timer (500ms interval) monitors and corrects Z-order violations
- Priority algorithm:
- Sort managed windows by priority (ascending)
- Apply
WS_EX_TOPMOSTflag to all managed windows - Stack windows from lowest to highest priority using
SetWindowPos - Re-order if any window loses topmost status
- Filters out:
- Invisible windows
- Desktop/shell windows
- Windows without titles
- Cloaked windows (different virtual desktops)
- The manager's own window
- System background processes
- Modern Material Design-inspired interface
- ListView with checkboxes for multi-select
- Editable priority text boxes (numeric only)
- Real-time window count and selection statistics
- Color-coded buttons with hover effects
Priority 1 (Highest) β Window A
Priority 2 β Window B
Priority 3 (Lowest) β Window C
Z-Order (top to bottom):
βββββββββββββββ
β Window A β β Priority 1 (Always on top)
βββββββββββββββ€
β Window B β β Priority 2 (Below A, above C)
βββββββββββββββ€
β Window C β β Priority 3 (Below B)
βββββββββββββββ
-
Initial Setup: When "Apply Always On Top" is clicked:
- Set
WS_EX_TOPMOSTflag on all selected windows - Position windows using
SetWindowPoswithHWND_TOPMOST
- Set
-
Continuous Monitoring: Timer checks every 500ms:
- Verify all managed windows still have
WS_EX_TOPMOSTflag - If any window lost topmost status β re-run full enforcement
- Remove destroyed windows from managed list
- Verify all managed windows still have
-
Z-Order Correction:
// Step 1: Ensure topmost flag foreach (window in sortedWindows) SetWindowTopmost(window, true) // Step 2: Stack from bottom to top for (i = lowest_priority; i >= highest_priority; i--) SetWindowPos(window[i], HWND_TOPMOST, ...) // Step 3: Final ordering pass foreach (window in priority_order) SetWindowPos(window, HWND_TOP, ...)
- Issue: Fullscreen apps may force themselves to the top
- Solution: Background monitor detects and re-applies topmost status
- Note: Some games with exclusive fullscreen may override temporarily
- Issue: Minimized windows can't be "on top"
- Detection:
IsIconic()API check - Behavior: Topmost flag remains applied, takes effect when restored
- Issue: When user clicks a non-managed window, it may come to front
- Solution: Managed windows remain topmost due to
WS_EX_TOPMOSTflag - Result: Normal windows always stay behind topmost windows
- Issue: Windows on other virtual desktops appear in EnumWindows
- Solution: Use
DwmGetWindowAttribute(DWMWA_CLOAKED)to detect and filter - Result: Only shows windows on current virtual desktop
- Issue: Multiple windows with same priority number
- Solution: UI warns user; relative order between duplicates is undefined
- Recommendation: Assign unique priorities
- Issue: Managed window is closed by user
- Detection:
IsWindow()returns false - Action: Automatically removed from managed list in next monitor cycle
- Issue: Managed window's process terminates unexpectedly
- Detection: Window handle becomes invalid
- Action: Gracefully removed from management
- .NET 8.0 SDK or later (Download)
- Windows 10/11 (64-bit)
- Visual Studio 2022 (optional, for development)
# Navigate to project directory
cd G:\always-on-top
# Restore dependencies
dotnet restore
# Build Release configuration (single-file exe)
dotnet publish -c Release -r win-x64 --self-contained true -p:PublishSingleFile=true
# Output location:
# bin\Release\net8.0-windows\win-x64\publish\AlwaysOnTop.exe- Open
AlwaysOnTop.csprojin Visual Studio 2022 - Set build configuration to Release
- Right-click project β Publish
- Choose Folder profile
- Configure:
- Target Runtime:
win-x64 - Deployment Mode:
Self-contained - Produce Single File:
True
- Target Runtime:
- Click Publish
The .csproj file is configured for optimal deployment:
<PublishSingleFile>true</PublishSingleFile> <!-- Single .exe -->
<SelfContained>true</SelfContained> <!-- Includes .NET runtime -->
<RuntimeIdentifier>win-x64</RuntimeIdentifier> <!-- Windows 64-bit -->
<PublishReadyToRun>true</PublishReadyToRun> <!-- AOT compilation -->
<PublishTrimmed>false</PublishTrimmed> <!-- Keep full framework (WPF needs it) -->- Self-Contained: No .NET installation required on target machine
- Single-File: All dependencies bundled into one .exe (~70-90 MB)
- ReadyToRun: Ahead-of-time compilation for faster startup
- No Trimming: Required for WPF compatibility
# Navigate to output directory
cd bin\Release\net8.0-windows\win-x64\publish
# Run the executable
.\AlwaysOnTop.exe-
Launch Application: Run
AlwaysOnTop.exe -
Refresh Window List: Click "π Refresh Windows" to detect all open windows
-
Select Windows: Check the boxes next to windows you want to keep on top
-
Assign Priorities:
- Enter priority numbers in the "Priority" column
- Lower numbers = higher priority (1 is highest)
- Example: Priority 1 stays above Priority 2
-
Apply: Click "β Apply Always On Top"
-
Manage:
- Remove Selected: Uncheck windows and click to remove topmost behavior
- Clear All: Remove all managed windows at once
-
Background Operation: The app continues monitoring in the background. Minimize it or leave it running.
- Memory: ~30-50 MB (typical)
- CPU: <1% (idle), ~2-3% (during Z-order enforcement)
- Disk: ~75 MB (single-file executable)
- OS: Windows 10 version 1809+ / Windows 11
- Architecture: x64 only
- .NET: Self-contained (no installation required)
- user32.dll: Core window management
- dwmapi.dll: Desktop Window Manager (virtual desktop support)
-
Exclusive Fullscreen Games: May temporarily override topmost behavior
- Workaround: Use borderless windowed mode
-
UAC/Admin Windows: Cannot manage windows running with higher privileges
- Solution: Run Always On Top Manager as administrator
-
Protected System Windows: Some system dialogs (e.g., UAC prompts) always override
-
Performance: With 50+ managed windows, monitoring may slow down
- Recommendation: Manage only essential windows
- No Network Access: Application is completely offline
- No Data Collection: No telemetry or analytics
- No Registry Modifications: All settings stored in memory
- Open Source: Code is fully auditable
- Cause: Window's application may be resetting its own Z-order
- Solution: Increase monitoring frequency or restart the application
- Cause: Window is minimized, on another virtual desktop, or has no title
- Solution: Restore window, switch virtual desktop, or ensure it has a title bar
- Cause: Too many managed windows or very fast-changing window states
- Solution: Reduce number of managed windows or increase timer interval
AlwaysOnTop/
βββ AlwaysOnTop.csproj # Project configuration
βββ App.xaml / App.xaml.cs # Application entry point
βββ MainWindow.xaml # UI layout (WPF)
βββ MainWindow.xaml.cs # UI logic and event handlers
βββ Models/
β βββ WindowInfo.cs # Window data model with INotifyPropertyChanged
βββ Services/
β βββ WindowEnumerator.cs # Window discovery and filtering
β βββ WindowManager.cs # Priority enforcement and monitoring
βββ Native/
βββ WindowsApi.cs # P/Invoke declarations for Win32 APIs
Example: Custom Hotkeys
- Add hotkey registration in
MainWindow.xaml.cs - Use
RegisterHotKeyfromuser32.dll - Handle
WM_HOTKEYmessages inWndProcoverride
Example: Persistent Settings
- Add JSON serialization for window priorities
- Save to
AppData\Local\AlwaysOnTop\settings.json - Load on application startup
This is a demonstration project. Modify and distribute as needed.
Built with:
- C# / .NET 8.0
- Windows Presentation Foundation (WPF)
- Win32 API (user32.dll, dwmapi.dll)
Version: 1.0.0
Last Updated: January 2026
Platform: Windows 11 (compatible with Windows 10 1809+)