![]() |
General Reading »
Hardware & System »
General
Intermediate
License: The Code Project Open License (CPOL)
Virtual Desktop: A Simple Desktop Management ToolBy Malli_SThis article gives you an overview of Windows Station, Windows Desktop and how to work with them. It also has a sample application (Virtual Desktop) demonstrating multiple desktop management. |
C++, Windows, Visual Studio, Dev
|
|
Advanced Search |
|
|
|
||||||||||||||||
A few months ago, one of my colleagues was using a tool that was managing multiple desktops. I was wondering how the tool could manage multiple desktops. I thought it would be just hiding-and-displaying the application windows for different desktops when a user switches between them. As a matter of curiosity, I started studying multiple desktops and ended up with this article.
As I went through the details, I found that I was wrong in thinking that the tool was just hiding-and-displaying the application windows for different desktops. Even the thought that the "Desktop" we see is just a directory was wrong. Let's see how it works.
Actually Windows uses Window Station and Desktop architecture to provide additional security. For the time being, we can refer to "Desktop" as a logical display surface, which contains User Interface Objects (GDI objects) and User Objects. A Window Station is a secure kernel object which contains a clipboard, an atom table, and one or more desktop objects. There exists a default window station "WinSta0", an interactive window station. "WinSta0" is the only interactive window station that can display a user interface or receive user input. All other window stations are non-interactive. By default, there exist three Desktops in an interactive window station : Default, WinLogon and ScreenSaver.
A Desktop is also a secure kernel object. When a new desktop is created, it is associated with the current window station of the calling process. There will always be only one desktop visible (Active) and ready to receive user inputs, provided the desktop is associated with an interactive window station i.e. WinSta0. This active desktop is called the Input Desktop.
As I specified, there exist three desktops in an interactive window station: Default, WinLogon and ScreenSaver. The screen prompting to press ALT + CTL + DEL to login is the WinLogon desktop. Whenever the user logs in, the Default desktop is created and made visible. This "Default" is the default active desktop for any logged in user. When you press ALT + CTL + DEL, you'll be switched back again to the WinLogon desktop. The ScreenSaver desktop will be made visible whenever the screen saver gets activated. As these desktop names are case-insensitive, there could be only one desktop of a specific name in a window station. But a desktop name can be repeated in different window stations. The purpose behind Window Station and Desktop objects is to provide top level isolation between processes.
The Virtual Desktop Tool helps you to create and switch between different desktops. It even gives you an illusion of switching the application from one desktop to another. But this isn't true as any running application cannot be moved from one desktop to other. As I said, it's just an illusion. The application will be closed in the current desktop and will be launched on the specified desktop. This may cause loss of any unsaved data of the application and may not persist the state as it will be restarted.
The application is using hooks to display "Move To" menu options in the applications Control Panel (System Menu). For more details about the hooks, I would refer this article. I will give you an overview of different APIs used and classes built in the application. Rest of the code in the application is self explanatory and (what I think is) well documented.
It retrieves the handle to the current Window Station of the calling process. The retrieved handle is used to enumerate all the desktops of the window station.
It creates a new Desktop with the specified name. This newly created desktop will be associated with the Window Station of the calling process and will be assigned to the calling thread.
It opens the specified Desktop. The handle returned by this function is used to switch between desktops.
It closes an open handle to Desktop.
This makes the specified Desktop visible and ready to receive user inputs (i.e. makes it Active).
It retrieves the handle to the Desktop associated with the specified thread.
It gives information about the Window Station and Desktop Objects.
The application has a class called CDesktopManager, in which all the desktop related activities are wrapped up. The application solution has a DLL Project, in which all the windows hook functionalities are wrapped up. This Event Hooker DLL is responsible for inserting menu options into the System Menu of the other applications.
When we create a new desktop and switch to it, it shows nothing. The desktop will be blank(with just a wallpaper visible) -- that's because no process is running on that desktop. So, to avoid that, I launch an Explorer shell whenever I create a new desktop. I think I could add a feature to launch a new process/application on a specified desktop. And so I did in the current update. I have a few more features in mind. I'll keep updating whenever I complete them.
If you find a bug in the application or any feature to be embeded, please let me know, so that I can work on it.
General
News
Question
Answer
Joke
Rant
Admin
|
PermaLink |
Privacy |
Terms of Use
Last Updated: 25 Jul 2008 Editor: Sean Ewington |
Copyright 2007 by
Malli_S
Everything else Copyright © CodeProject, 1999-2009 Web11 | Advertise on the Code Project |