其他窗口的访问控制 [英] access controls on other windows
本文介绍了其他窗口的访问控制的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何访问另一个应用程序窗口上的控件?
我需要更改该控件的值(如文本框)或单击它们(如按钮).
我想我应该使用 API 函数吗?但是如何?
How can I access to the controls on another application's window?
I need to change the value of that controls (like textboxes) or click on them (like buttons).
I think I Should use API functions? But how?
推荐答案
请参阅 SendKeys 类 并阅读这篇文章,这是文章中的一个例子:
See the SendKeys class and read this article, here is an example from the article:
// Get a handle to an application window.
[DllImport("USER32.DLL", CharSet = CharSet.Unicode)]
public static extern IntPtr FindWindow(string lpClassName,
string lpWindowName);
// Activate an application window.
[DllImport("USER32.DLL")]
public static extern bool SetForegroundWindow(IntPtr hWnd);
// Send a series of key presses to the Calculator application.
private void button1_Click(object sender, EventArgs e)
{
// Get a handle to the Calculator application. The window class
// and window name were obtained using the Spy++ tool.
IntPtr calculatorHandle = FindWindow("CalcFrame","Calculator");
// Verify that Calculator is a running process.
if (calculatorHandle == IntPtr.Zero)
{
MessageBox.Show("Calculator is not running.");
return;
}
// Make Calculator the foreground application and send it
// a set of calculations.
SetForegroundWindow(calculatorHandle);
SendKeys.SendWait("111");
SendKeys.SendWait("*");
SendKeys.SendWait("11");
SendKeys.SendWait("=");
}
这篇关于其他窗口的访问控制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文