windows 如何从不同应用程序窗口上的控件读取数据?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5078025/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How can I read data from controls on window in a different application?
提问by soupdiver
I have to write an application that observes another application and extracts information from the window. What is the best way to access windows from other applications and get data from their controls?
我必须编写一个应用程序来观察另一个应用程序并从窗口中提取信息。从其他应用程序访问窗口并从其控件获取数据的最佳方式是什么?
回答by Cody Gray
You'll need to P/Invoke the FindWindow
and FindWindowEx
functions to retrieve a handle to the other application's parent window and child controls.
您需要 P/InvokeFindWindow
和FindWindowEx
函数来检索其他应用程序的父窗口和子控件的句柄。
Then you will need to use something like GetWindowText
to access the text for a particular control.
然后你需要使用类似的东西GetWindowText
来访问特定控件的文本。
Visit pinvoke.netfor the definitions you'll need to call these functions from C#.
访问pinvoke.net以获得从 C# 调用这些函数所需的定义。
Be warned that this is not a completely straightforward pursuit. You should stop to consider whether you really have a good reason for wanting to do this, and if your goal couldn't be achieved in a simpler way.
请注意,这不是一个完全简单的追求。您应该停下来考虑一下您是否真的有充分的理由想要这样做,以及您的目标是否无法以更简单的方式实现。