Welcome to MSDN Blogs Sign in | Join | Help

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 http://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);

Published Wednesday, July 05, 2006 10:42 by abhinaba

Comment Notification

If you would like to receive an email when updates are made to this post, please register here

Subscribe to this post's comments using RSS

Comments

# re: Multiple desktop support in Windows

Wednesday, July 05, 2006 1:25 by leppie
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?

# re: Multiple desktop support in Windows

Wednesday, July 05, 2006 1:27 by Gabe
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.

# re: Multiple desktop support in Windows

Wednesday, July 05, 2006 5:00 by Adam
I too am used to having multiple desktops on UNIX, and tried moving to them on Windows. There were just way too many bugs though.

Visual Studio just doesn't like it. For some reason it seems to put two items in the alt-tab window cycler when I had multiple desktops turned on. Also, if I was debugging a program and was stepping through code, then attempting to switch desktops (say, to look up something on google related to the code I was stepping through) would pretty much hang everything. ctrl+alt+del could bring up the task manager, but trying to kill a task was awkward and didn't always work.

Word seemed to decide to change which desktop it was on every now and then, which was a pain.

The taskbar desktop switcher just _had_ to have the desktop thumbnails in a single row, insead of being able to put them on two rows if you have a double-height taskbar, taking up too much horiz space.

Umm, there were other things as well, but I'm back to a single desktop on Windows. As much as I hate and feel constrained by it, I prefer it to the alternative.

# re: Multiple desktop support in Windows

Monday, November 20, 2006 10:38 by daniel

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.

# re: Multiple desktop support in Windows

Saturday, March 31, 2007 5:39 PM by iqbal

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 priced

# Monkey see, monkey build - The mumblings of Clint Rutkas » Need more space? Add virtual desktops!

# Need more space? Add virtual desktops!

Monday, October 29, 2007 3:22 PM by Coding4Fun

Having multiple monitors makes life easier in my opinion but even with my current work setup, I need

# How to implement Virtual Desktop « vincenthome’s Software Development

# re: Multiple desktop support in Windows

Saturday, December 08, 2007 4:01 PM by joe

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?

# re: Multiple desktop support in Windows

Wednesday, January 02, 2008 9:24 by veerkumar patil(India)

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 Desktop

# re: Multiple desktop support in Windows

Wednesday, January 02, 2008 9:32 by Veerkumar

I forgot to send my E-mail ID

veer1109@rediffmail.com

# re: Multiple desktop support in Windows

Thursday, June 26, 2008 5:03 by Yossi

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 ?

Leave a Comment

(required) 
required 
(required) 
 
Page view tracker