Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Windows 10 IVirtualDesktopManager::MoveWindowToDesktop

I've been trying to use IVirtualDesktopManager::MoveWindowToDesktop to move windows between virtual desktops.

Using it on my own windows works great but unfortunately it fails with E_ACCESSDENIED when I try to use it on the window of another process.

Sadly "Launch as admin" is not good enough for it. Am I missing something that I don't know about COM interfaces or is it just badly designed ?

like image 432
Nopt Avatar asked Sep 18 '15 19:09

Nopt


People also ask

How do I use ivirtualdesktopmanager?

The IVirtualDesktopManager interface has these methods. Gets the identifier for the virtual desktop hosting the provided top-level window. Indicates whether the provided window is on the currently active virtual desktop. Moves a window to the specified virtual desktop. The user can group a collection of windows together to create a virtual desktop.

How to move windows between virtual desktops in Windows 10?

Luckily, Windows makes it easy to move windows between virtual desktops. Here’s how. Using your mouse or a touchscreen, you can easily drag windows between virtual desktops using the Task View sceen. To open “Task View,” click the “Task View” button on your taskbar or press Windows+Tab.

How do I make a window appear on all virtual desktops?

After that, the window will appear on the virtual desktop you selected. You can also make the window appear on all virtual desktops at once if you right click on its thumbnail in Task View and select “Show this window on all desktops.” Very handy!

What is a virtual desktop and how does it work?

The user can group a collection of windows together to create a virtual desktop. Every window is considered to be part of a virtual desktop. When one virtual desktop is hidden, all of the windows associated with it are also hidden. This enables the user to create multiple working environments and to be able to switch between them.


1 Answers

You can move a window not owned by the executing process, but it requires the use of additional, undocumented COM objects.

  1. Query ImmersiveShell for instances of IApplicationViewCollection and IVirtualDesktopManagerInternal.
  2. Get the hwnd of the window you want to move.
  3. It sounds like you already know the target desktop ID, but you can also use IVirtualDesktopManagerInternal methods GetAdjacentDesktop and GetDesktops to find more.
  4. Call IApplicationViewCollection::GetViewForHwnd to get the view.
  5. Call IVirtualDesktopManagerInternal::MoveViewToDesktop to move the view.

Code references:

  • VirtualDesktopAccessor wraps the relevant objects in C++ and builds a native DLL you can use.
  • VirtualDesktop wraps them in C# and provides a .NET DLL and GUI.
  • zVirtualDesktop documents different versions of the interfaces.
  • This forum topic shows how to work with the IVirtualDesktopManagerInternal to select a virtual desktop by index in AutoHotKey. I'm working on a version that also wraps IApplicationViewCollection to support moving any given window as described above.
like image 198
Shawn Hoover Avatar answered Sep 17 '22 17:09

Shawn Hoover