1

I want to know how to detect changing of a virtual desktop for a window in Windows? I am working in Windows API and C++. I tried to find out which messages are published by the Windows ( by using Spy++ tools from Microsoft Visual Studio ) but as you can see there is not any useful message there. It seems that WM_MOVE is also not published.

enter image description here

I could not find anything in the official documents.

Reza
  • 3,473
  • 4
  • 35
  • 54
  • 1
    Sounds like asking for a solution to a problem that doesn't exist. Spend some time with your preferred AI(s) to figure out what the *actual* problem is. – IInspectable Jun 13 '23 at 15:29
  • 1
    Sounds like an [XY problem](https://meta.stackexchange.com/questions/66377/what-is-the-xy-problem). What are you trying to solve in the first place, and why do you think detecting changes in virtual desktops is the solution? AFAIK, there are no APIs/notifications available to tell you when virtual desktop changes happen. You will likely have to use `IVirtualDesktopManager::GetWindowDesktopId()` in a timer/loop to detect the change manually. – Remy Lebeau Jun 13 '23 at 16:20
  • @RemyLebeau I save the desktop IDs of every window in a file and want to open all windows in their virtual desktop after restarting my app. As you said, I should either use a polling or save everything on closing of my app whiich both cases are not efficient. I was expecting a move message which seems not working. – Reza Jun 13 '23 at 16:30
  • 2
    This is not a feature supported by the virtual desktop API. The API is intentionally very limited because virtual desktops are an end-user feature, not an app feature. – Raymond Chen Jun 13 '23 at 16:48
  • 1
    @Reza "*I save the desktop IDs of every window*" - just your own windows, or other windows, too? "*[I] want to open all windows in their virtual desktop*" - `IVirtualDesktopManager::MoveWindowToDesktop()` exists for that purpose. I don't see the need to detect desktop changes in real time. Poll the current desktop IDs on app exit. Move the windows to their desktops on app restart. Done. If that does not suit your needs, then you need to [edit] your question to explain your situation in more detail. – Remy Lebeau Jun 13 '23 at 16:50
  • @RemyLebeau all windows of my app. I go with the solution that save the IDs on app exit. – Reza Jun 13 '23 at 16:58
  • 1
    @Reza you are treading very close to the edge of how virtual desktops are intended to be used. If your app is restarted, you really should just reopen your windows on the current desktop, and let the user move them to another desktop if they want. Unless you ask the user when exiting the app (or beforehand) whether the original desktops should be used on restart. Virtual desktops are meant to be managed by the user, not by apps – Remy Lebeau Jun 13 '23 at 17:50
  • 1
    The purpose of MoveWindowToDesktop is to bring a window to the same desktop as another window (because they are related to each other somehow). It's for moving windows closer, not for moving them apart. In retrospect, it should have been MoveWindowToSameDesktopAs where you pass two window handles. – Raymond Chen Jun 14 '23 at 05:11

0 Answers0