Skip to content

About

Wrapper for API to Virtual Desktop on Windows 10.

Resources

Stars

0 stars

Watchers

1 watching

Forks

 
 

Repository files navigation

VirtualDesktop

VirtualDesktop wraps the Windows shell's virtual desktop API for desktop apps. Microsoft's IVirtualDesktopManager reference

Features

  • Look up the desktop for a top-level window and check whether it is on the current desktop.
  • Move a window owned by the calling process to a known desktop.
  • Observe changes to the current desktop.

Installation

Install NuGet package(s).

PM> Install-Package VirtualDesktop

How to use

Preparation:

<!-- Please create application manifest file and run without debugging. -->
<compatibility xmlns="urn:schemas-microsoft-com:compatibility.v1">
    <application>
	    <!-- Windows 10 -->
	    <supportedOS Id="{8e0f7a12-bfb3-4fe8-b9a5-48fd50a15a9a}" />
    </application>
</compatibility>
using WindowsDesktop;

Query a window's desktop

var desktop = VirtualDesktop.FromHwnd(hwnd);
var isCurrent = VirtualDesktop.IsWindowOnCurrentVirtualDesktop(hwnd);

Callers migrating from TryGetIdFromHwnd can use IdFromHwnd to get a nullable GUID. During an Explorer restart, both queries can return null. The Boolean IsCurrentVirtualDesktop helper returns false in that case. If Windows has no registered virtual desktop manager, IsPresent returns false and queries for a window throw NotSupportedException. Other shell failures propagate as managed exceptions.

CurrentID returns Guid.Empty until the library identifies a desktop. Subscribe to CurrentChanged and then read CurrentID to cover both startup and later changes. The first observation has a null OldDesktop. UI subscribers receive events on their subscribing synchronization context. Subscribers without a context receive them on the listener thread.

for WPF window

// Need to install 'VirtualDesktop.WPF' package

// Check whether a window is on the current desktop.
var isCurrent = window.IsCurrentVirtualDesktop();

// Get Virtual Desktop for WPF window
var desktop = window.GetCurrentDesktop();

// Move window to specific Virtual Desktop
window.MoveToDesktop(desktop);

See also:

License

This library is under the MIT License.

About

Wrapper for API to Virtual Desktop on Windows 10.

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages