views:

405

answers:

4

Hello,

I am trying to figure out how can I send a running application do a new Windows desktop created with CreateDesktop.

I can create a new Desktop, and then launch an application in it, bug I can't find the way to do it with a running application. All functions related to Desktop management (i.ec, SetThreadDesktop) always apply only to current thread

Any hints ?

A: 

I have not implemented any code, but just thinking aloud... Quoting from the following MSDN Link

A process automatically establishes a connection to a window station and desktop when it first calls a USER32 or GDI32 function. If the process did not call SetProcessWindowStation, it connects to the window station inherited from the parent process

This implies that the 'running application' already has the value of "lpDesktop member of the STARTUPINFO structure" set to the current window station. I think you may need to change this value to send the application to another desktop. As this link mentions SetProcessWindowStation Function, this could be done using

BOOL WINAPI SetProcessWindowStation( __in HWINSTA hWinSta );

Also, as SetThreadDesktop Function mentions

Assigns the specified desktop to the calling thread.

So I guess, for this to work, you 'running application' will need to call SetThreadDesktop. It will be helpful if you could post in some code...

Codex
A: 

Hello,

Thank you for your answer.

Well, in fact, what I need to do is moving applications not developed by me (i.e, notepad.exe)

If look at Virtual Desktop Manager from Powertoys (http://www.microsoft.com/windowsxp/downloads/powertoys/xppowertoys.mspx), it creates several virtual desktops in the same WindowStation. I know there are similar applications that can move running apps (notepad.exe, calc.exe..) from one virtual desktop to another, without the need of closing it and reopening it again (and then passing the new desktop handle [HDESK] on the call to CreateProcess), but even after reading all the related msdn documentation, I still can not figure how to do it :|

I thought on SetProcessWindowStation too, but as far as I now, all new virtual desktops created with CreateDesktop function are on the same WindowStation, so...

Maybe I missed something ?

A: 

Window resources (such as HWNDs) are specific to a desktop. If you create a window in one desktop, I can't see how you would be able to move it to another desktop. For example, the HWNDs used by your application might already be in use in the other desktop.

Virtual Desktop Managers don't have to use Windows Desktops -- they can create the same effect by manipulating the windows. Take a look at VirtuaWin, an open source Virtual Desktop Manager.

jdigital
A: 

Just try Vista/XP Virtual Desktop Manager from http://vdm.codeplex.com/

JKS