5

我希望通过我的 C# 应用程序与其他 Windows 应用程序进行交互。这应该能够在后台完成,而用户继续做其他事情。目标应用程序不是我的,但我知道它们是什么,所以它们的 UI/等。是已知的。

我基本上是在尝试跨各种程序自动化各种任务的过程。

到目前为止,我能想到的唯一解决方案是让代码切换到相关窗口,并用鼠标执行任务。(用这里显示的方法控制鼠标

当然,这种方法的缺点是它不能在后台运行并阻止用户执行其他任务。

Of course if these target applications received 'fake' mouse clicks, while still running in the background, this solution would be great. So if that's possible, please do share! Otherwise, any solution for such a problem would be brilliant.

4

1 回答 1

6

I just want to say that what you are doing is going to be pretty tough to make reliable without cooperation from the developers of the other applications. However, you can use Windows Messages to accomplish what you're trying to do. This is a way to send information to a window without explicit communications being set up. You'll need to use native methods to do this, but it's pretty straightforward. Be careful, however, as implementing this is not as trivial as it looks - you can get into deadlocks if you accidentally send a message to a closed (or invisible) window, for example.

对于 Stack Overflow 帖子来说,这个话题太大了,但这里有一些相关功能可以帮助您入门:

PostMessageSendMessage是您可以用来向其他应用程序发送消息的主要函数。

这篇文章的答案有一些关于如何使用这些功能的基本示例。

最后,这里有一个 Windows 消息代码列表供参考。

于 2013-03-04T17:50:34.473 回答