views:

35

answers:

1

I have this old Fortran executable that can only be accessed through its GUI, and is too complicated to rewrite. I need to integrate it into a tool we are building, so I wrote a GUI wrapper in C# using the White library (certainly not ideal, but I couldn't think of a better approach). This works ok, but when my program runs, the GUI pops up, and certain actions (such as listbox selections) force a mouse movement. I'd like the interaction with the Fortran tool to be transparent to the user.

I've read a couple posts here about a CreateDesktop function in the user32 dll that may allow me to execute the wrapper on another desktop window not seen by the user. Will I still be able to automate GUI interaction on such a desktop? I've searched around, haven't found any examples of how to use a desktop created this way. Does anyone have a good reference for this?

Alternatively, is there a better way to go about this process?

+1  A: 

Desktops are probably a good way to achieve what you want.

Desktops can be non-visible, which allows for automation peers to manipulate the UI without the risk of input focus or pop-over behavior.

Desktops represent a logical screen layout with zero or more Windows on it. There are several API methods available to manipulate and interact with desktops in Win32, including (among them) CreateDesktop().

Each desktop has a name (e.g. "Default" "WinLogon" "MyOwnName") and exists as items within a Window Station, resulting in full names such as "WinSta0\Default". Desktops were introduced in NT 3.10. Window handles, window messages, "WindowHooks" etc. all live within a single desktop and cannot cross that boundary. However, it is possible to perform peer-automation (such as the kind you describe with the White library) on a different desktop than the one your app runs in.

Unlike Sessions and Window Stations, each thread in a process may be connected to a different Desktop within the WinStation of its process, and this association can be changed on the fly in any thread which does not have any windows (not even hidden ones). Security-wise, each Desktop has its own security descriptor. You can get a handle to the Desktop of your own process by calling GetThreadDesktop(), for other tasks, OpenDesktop() and OpenInputDesktop() and CreateDesktop() are interesting APIs.

LBushkin