Reputation: 38180
Let's say I have installed http://technet.microsoft.com/en-us/sysinternals/cc817881
I want to be able to sendmessage with win32 api but targeting the second virtual desktop while I will stay on first virtual desktop.
How to do that in c# ?
Update: for the context, what I'd like is to automate a manual task in background at periodic interval on an application which would reside in 2nd virtual desktop while I'm working on first desktop.
Upvotes: 1
Views: 1345
Reputation: 70369
The link you provide describes a tool which is based on the Windows built-in desktop-mechanism.
Basically this means that you have really distinct desktops (with separate Logon!) which do not interact - they can't even see the windows of each other, i.e.unlike other "virtual desktop utilities" you can't move a window or application from one desktop to another.
This is the reference on MSDN to the use Desktop API which among other things explains the permissions issues etc. involved in such an undertaking.
Only way you could achieve what you want in this situation is to build a Windows Service which in turn monitors desktop startup/shutdown.
In case of desktop startup you need to start a process inside that desktop.
This process must offer some sort of desktop-agnostic IPC mechanism like TCP/IP or global mutex + global shared memory or similar...
You communicate with that process and this process does whatever you need (SendMessage, SendKeys...) inside that desktop on your behalf.
Upvotes: 2
Reputation: 244722
SendKeys
and SendMessage
are very different things. It's entirely unclear which one you're using.
You can't "target" anything with SendKeys
. The only entity that can receive keyboard and mouse input in Windows is the window with the focus. Since something displayed on a virtual desktop will not have the focus, you can't do this.
You can however use the SendMessage
function to send window messages to any window you wish. The SendMessage
function accepts as its first parameter a handle to the window of interest (HWND
). It doesn't matter if that window is focused, active, displayed, on a virtual desktop, or whatever.
Upvotes: 3