Multiple desktop support in Windows
In my previous job I worked in the development team of Adobe FrameMaker. This product shipped on Sun Solaris, Windows and Mac. I worked parallely on a Windows box, a Sun Blade system and a PowerMac G5. So I got used to the best of all of them.
Solaris (and many other window managers) supports multiple desktops for each user and easy swtiching between them. I got used to have 4 desktops and spread my applications across them. One had all the coding stuff like the editors and debuggers and the other had email-client and browser and so on. I always felt unhappy that Windows didn't support this. It was much later when I came across the multi-desktop Win32 API's. After playing around a bit with them I was really surprised that Windows (XP/2000/2003) didn't expose this feature directly. Later I found Microsoft Power Toys for XP which supported multi-desktops. I assumed that Vista Window Manager will have this directly. But unfortunately it does not (see the feature list here).
Using the Windows Desktop API's its extremely easy to create multiple desktops and switch between them. The following code creates a new desktop name MyDesk and launches Windows explorer on it and switches to the newly created desktop
IntPtr hDesk = Native.CreateDesktop("MyDesk", IntPtr.Zero, IntPtr.Zero, 0, AccessRights, IntPtr.Zero);
STARTUPINFO si = new STARTUPINFO();
si.cb = Marshal.SizeOf(si);
si.lpDesktop = "MyDesk" ;
PROCESS_INFORMATION pi = new PROCESS_INFORMATION();
bool result = Native.CreateProcess(null, @"C:\WINDOWS\explorer.exe",
IntPtr.Zero, IntPtr.Zero,
true, NORMAL_PRIORITY_CLASS,
IntPtr.Zero, null, ref si, ref pi);Native.SwitchDesktop(hDesk);
Check out https://www.pinvoke.net for the C# signatures for these Win32 api's. Similarly is easy to enumerate all the desktops
delegate bool EnumDesktopsDelegate(string desktop, IntPtr lParam);
private bool DesktopEnum(string desktop, IntPtr lParam)
{
Console.WriteLine(desktop);
return true;
}
Native.EnumDesktops(windowStation,
new EnumDesktopsDelegate(DesktopEnum),
IntPtr.Zero);
Comments
Anonymous
July 04, 2006
Thanks, will check it out!
The $100 million question is: can you use that new desktop as a VNC source, so it can be emitted to another laptop/pc as a 3rd (or more) monitor?Anonymous
July 04, 2006
As I understand it, the type of virtual desktop support you see on X systems like the Sun is actually just using a single desktop with more pixels than the screen, and moving the origin to whichever "desktop" you want to see. So a 1024x768 monitor with 4 virtual desktops might be 2048x1536 with the origin usually at (0,0). If you want to switch to another desktop, the window manager just sets the origin to (1024,0) or (0,768) or (1024,768); however, you could switch to the middle by setting the origin to (512,384). To move a window to another desktop, just drag it to where you want it.
This is the way virtual desktops work on X, and the way they've worked on Windows. In fact, I had a virtual window manager that worked this way back in 1992.
However, this is not how multiple desktops work. With multiple desktops, each window is confined to the desktop where it was created, and cannot communicate (send messages) with windows on other desktops. For example, the windows login dialog is on one desktop while the rest of your programs on on another desktop. This means that there's no way for a program you're running to capture keystrokes from the login dialog. This is probably not how you want your desktops to work, though.
I'm not sure why Windows doesn't ship with virtual desktop support, but I guess it would confuse most people ("where did my desktop go?"), and isn't really necessary. While I've used virtual window managers frequently on Unix, I haven't really found myself wanting them on Windows. I tried one many years ago, and never found it useful.Anonymous
July 04, 2006
The comment has been removedAnonymous
November 20, 2006
Anybody else have trouble with firefox using this method? I can't use firefox on more than one desktop because firefox can't start another instance if it sees that it's currently running, and it can't interact with the previous instance if it's on a different desktop.Anonymous
March 31, 2007
hi im looking for a solution whereby i can use 1 computer and split it to be used by children in a primary school in uganda. i want to have say 10 usrs all sharing the same desktop but using different keyboards and mouse. do you know of a free solution to this. or one which is resonably pricedAnonymous
October 29, 2007
PingBack from http://betterthaneveryone.com/?p=631Anonymous
October 29, 2007
Having multiple monitors makes life easier in my opinion but even with my current work setup, I needAnonymous
October 30, 2007
PingBack from http://vincenthomedev.wordpress.com/2007/10/30/how-to-implement-virtual-desktop/Anonymous
December 08, 2007
i have looked here and many other places. i have implemented the use of 4 desktops in my project and i can switch between them very easily, but i want to have a single app to switch them rather than having 4 instances of the same app. also i would like to have a screen shot of each desktop on the app... my major question is, would a windows service be able to communicate between these desktops?Anonymous
January 02, 2008
Hello Sir,I am last year Computer Engg Student I am working on the project of Remote Computer administration . I am trying to create Desktop in C# but i found that there is no any Desktop Supporting class I ve read ur article on multiple desktop creation Can u plz give me the idea regarding Creating DesktopAnonymous
January 02, 2008
I forgot to send my E-mail ID veer1109@rediffmail.comAnonymous
June 25, 2008
I am looking for Vista API for enabling multi monitor. I have laptop which is connected to external graphic device, I want an API to extend/set primary/de-extend my desktop to this graphic device monitor DO you know which API control weather specific monitor is extended or weather specific monitor is primary ?Anonymous
September 15, 2008
Hi, I'm trying to create an APP which creates a new desktop. Where can I find more info on how to control the new Desktop including: Running apps, Creating Icons, Closing the Desktop? Tnx, LeeozAnonymous
August 30, 2009
Hi, I see your site and use of your information, Thanks for this, I am programmer, and I am developing a program that should show some forms in different LCD, in the same time, I use NVidia to have multiple desktop and after show the form, I send it to another desktop then, set the window state and windowborderstyle to sake the form full screen from Main(first) form, but the form in the second desktop show in background of the first desktop, and it doesn't hide with refresh, just should change the desktop then comeback to first desktop. and I don't know what should I do? I will be glad if you help me. amin shahabAnonymous
January 29, 2014
Mark Roussinovich's desktops app gives you four desktops and easy way to switch between them: technet.microsoft.com/.../cc817881.aspx