WindowManagementApi 1.0.0
There is a newer version of this package available.
See the version list below for details.
See the version list below for details.
dotnet add package WindowManagementApi --version 1.0.0
NuGet\Install-Package WindowManagementApi -Version 1.0.0
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="WindowManagementApi" Version="1.0.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="WindowManagementApi" Version="1.0.0" />
<PackageReference Include="WindowManagementApi" />
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add WindowManagementApi --version 1.0.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: WindowManagementApi, 1.0.0"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package WindowManagementApi@1.0.0
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=WindowManagementApi&version=1.0.0
#tool nuget:?package=WindowManagementApi&version=1.0.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
Window Management API
A general-purpose .NET 10 library for programmatic Windows window management with first-class multi-monitor, mixed-DPI support.
Prerequisites
- Windows 10 or 11
- .NET 10.0 or later
- Process must be configured for per-monitor v2 DPI awareness
Quick Start
Standalone usage
using WindowManagement;
await using var manager = WindowManagementFactory.Create();
// List all Alt+Tab windows
var windows = manager.GetAll();
foreach (var w in windows)
Console.WriteLine($"{w.ProcessName}: {w.Title} ({w.Bounds})");
// Snap the foreground window to the left half of the primary monitor
var foreground = manager.GetForeground();
if (foreground != null)
await manager.SnapAsync(foreground, manager.Monitors.Primary, SnapPosition.Left);
With dependency injection
using WindowManagement.DependencyInjection;
services.AddWindowManagement();
With Autofac
using WindowManagement.DependencyInjection;
builder.RegisterModule(new WindowManagementModule());
Then inject IWindowManager:
public class MyService(IWindowManager windowManager)
{
public async Task SnapToLeft()
{
var foreground = windowManager.GetForeground();
if (foreground != null)
await windowManager.SnapAsync(foreground, windowManager.Monitors.Primary, SnapPosition.Left);
}
}
Window Filtering
// Default: Alt+Tab window set
var windows = manager.GetAll();
// Filter by process
var windows = manager.GetAll(f => f.WithProcess("notepad"));
// Filter by title with wildcards
var windows = manager.GetAll(f => f.WithTitle("*.txt*"));
// Exclude minimized windows
var windows = manager.GetAll(f => f.ExcludeMinimized());
// Raw enumeration (no Alt+Tab filtering)
var windows = manager.GetAll(f => f.Unfiltered());
// Custom predicate
var windows = manager.GetAll(f => f.Where(w => w.Bounds.Width > 500));
Window Events (R3)
manager.Created.Subscribe(e => Console.WriteLine($"Created: {e.Title}"));
manager.Moved.Subscribe(e => Console.WriteLine($"Moved: {e.Title} -> {e.NewBounds}"));
manager.Monitors.Connected.Subscribe(e => Console.WriteLine($"Monitor connected: {e.DeviceName}"));
Error Handling
The library throws WindowManagementException when Win32 operations fail (e.g., SetWindowPos, GetWindowRect). WindowNotFoundException (a subclass) is thrown when a window handle becomes invalid.
try
{
await manager.SnapAsync(window, monitor, SnapPosition.Left);
}
catch (WindowNotFoundException)
{
// Window was closed
}
catch (WindowManagementException ex)
{
// Win32 operation failed
Console.WriteLine(ex.Message);
}
WindowRect enforces non-negative Width and Height:
var rect = new WindowRect(0, 0, 800, 600); // OK
var bad = new WindowRect(0, 0, -1, 600); // throws ArgumentOutOfRangeException
var also = rect with { Width = -1 }; // throws ArgumentOutOfRangeException
Low-Level API
For advanced consumers who need direct Win32 access with correct DPI math:
// Inject or resolve
IWindowApi windowApi = ...;
IDisplayApi displayApi = ...;
var handles = windowApi.Enumerate(altTabOnly: true);
var bounds = windowApi.GetBounds(handle);
windowApi.SetBounds(handle, new WindowRect(0, 0, 800, 600));
var monitors = displayApi.GetAll();
var logical = displayApi.PhysicalToLogical(bounds, monitor.Handle);
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net10.0-windows7.0 is compatible. |
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
-
net10.0-windows7.0
- Autofac (>= 8.4.0)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 10.0.5)
- Microsoft.Extensions.Logging.Abstractions (>= 10.0.5)
- Microsoft.Extensions.Options (>= 10.0.5)
- Microsoft.Win32.SystemEvents (>= 9.0.14)
- R3 (>= 1.3.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.