Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

API for Windows 10 virtual desktops [duplicate]

I love that Windows 10 now has support for virtual desktops built in, but I have some features that I'd like to add/modify (e.g., force a window to appear on all desktops, launch the task view with a hotkey, have per-monitor desktops, etc.)

I have searched for applications and developer references to help me customize my desktops, but I have had no luck.

Where should I start? I am looking for Windows API functions (ideally, that are callable from a C# application) that will give me programmatic access to manipulate virtual desktops and the windows therein.

like image 952
Slicedbread Avatar asked Sep 05 '15 19:09

Slicedbread


People also ask

How do I create multiple virtual desktops in Windows 10?

To create multiple desktops: On the taskbar, select Task view > New desktop . Open the apps you want to use on that desktop. To switch to another desktop, select Task view again.

How do I open the same app on two desktops?

To open a second window of certain open apps, just hold Shift and click on the icon in your taskbar. For programs like Word, Notepad, File Explorer, and Chrome, this will open a second window with a blank document. You can work in that instance of the app separately from whatever else you already have open.

How do I get rid of duplicate desktops?

You can also close desktops with the keyboard shortcut Windows Key + Ctrl + F4.

What is DXGI desktop duplication?

Windows 8 introduces a DXGI-based API called Desktop Duplication API. This API provides access to the contents of the desktop by using bitmaps and associated metadata for optimizations. This API works with the Aero theme enabled, and is not dependent on the graphics API that applications use.


Video Answer


1 Answers

The Windows SDK Support Team Blog posted a C# demo to switch Desktops via IVirtualDesktopManager:

[ComImport, InterfaceType(ComInterfaceType.InterfaceIsIUnknown), Guid("a5cd92ff-29be-454c-8d04-d82879fb3f1b")] [System.Security.SuppressUnmanagedCodeSecurity] public interface IVirtualDesktopManager { [PreserveSig] int IsWindowOnCurrentVirtualDesktop(     [In] IntPtr TopLevelWindow,     [Out] out int OnCurrentDesktop     ); [PreserveSig] int GetWindowDesktopId(     [In] IntPtr TopLevelWindow,     [Out] out Guid CurrentDesktop     );  [PreserveSig] int MoveWindowToDesktop(     [In] IntPtr TopLevelWindow,     [MarshalAs(UnmanagedType.LPStruct)]     [In]Guid CurrentDesktop     ); }  [ComImport, Guid("aa509086-5ca9-4c25-8f95-589d3c07b48a")] public class CVirtualDesktopManager {  } public class VirtualDesktopManager {     public VirtualDesktopManager()     {         cmanager = new CVirtualDesktopManager();         manager = (IVirtualDesktopManager)cmanager;     }     ~VirtualDesktopManager()     {         manager = null;         cmanager = null;     }     private CVirtualDesktopManager cmanager = null;     private IVirtualDesktopManager manager;      public bool IsWindowOnCurrentVirtualDesktop(IntPtr TopLevelWindow)     {         int result;         int hr;         if ((hr = manager.IsWindowOnCurrentVirtualDesktop(TopLevelWindow, out result)) != 0)         {             Marshal.ThrowExceptionForHR(hr);         }         return result != 0;     }      public Guid GetWindowDesktopId(IntPtr TopLevelWindow)     {         Guid result;         int hr;         if ((hr = manager.GetWindowDesktopId(TopLevelWindow, out result)) != 0)         {             Marshal.ThrowExceptionForHR(hr);         }         return result;     }      public void MoveWindowToDesktop(IntPtr TopLevelWindow, Guid CurrentDesktop)     {         int hr;         if ((hr = manager.MoveWindowToDesktop(TopLevelWindow, CurrentDesktop)) != 0)         {             Marshal.ThrowExceptionForHR(hr);         }     } } 

it includes the API to detect on which desktop the Window is shown and it can switch and move a Windows the a Desktop.

like image 51
magicandre1981 Avatar answered Sep 23 '22 04:09

magicandre1981