Home > Software engineering >  Enumerate Windows 11 desktops and windows appearing in each desktop
Enumerate Windows 11 desktops and windows appearing in each desktop

Time:03-26

I am using Windows 11 and with WinKey TAB I create several desktops. They have the very nifty feature that ALT TAB only shows the windows present on a given desktop, thus hugely reducing visual clutter. It is also able to show selected windows on all desktops. I think that these virtual desktops were available before Windows 11 as well.

However, when I enumerate desktops with a Win32 console application doing a simple combination of GetProcessWindowStation() followed by a call to EnumDesktops() I get back always the same answer, regardless of how many desktops I have created. I get two desktops named: DummyDesktopForInstantResume and Default

So it seems that the WinKey Tab 'desktops' are not the same as the EnumDesktops() 'desktops'.

I did some additional digging with Spy and it shows only one root desktop with all the windows belonging to that desktop. No matter on which desktop Spy "appears" in it always shows the same window list. And no matter on which desktops an application appears, it always has the same window handle (as expected).

Anyone knows how do we enumerate the virtual desktops created by WinKey TAB in Windows 11? Thanks

CodePudding user response:

So it seems that the WinKey Tab 'desktops' are not the same as the EnumDesktops() 'desktops'.

No, they are not. They are "virtual" desktops running inside of the user's current Win32 desktop. Virtual desktops are merely a window management system, a means of letting the user group multiple windows together and then hide/show those groups as a whole. Raymond Chen blogged about this:

Virtual desktops are an end-user window management feature, not a programmatic one

Virtual desktops are a window management feature, not a security feature or a performance feature. Furthermore, they are for end users to organize their windows, not for other programs to organize the windows.

Anyone knows how do we enumerate the virtual desktops created by WinKey TAB in Windows 11?

Unfortunately, there is no public API available to enumerate these virtual desktops (but there is an undocumented internal API that can). The public IVirtualDesktopManager interface is very limited, it allows you to only query whether a given window belongs to the currently active virtual desktop, and to move a window to a specific virtual desktop. Nothing more.

  • Related