访问其他窗口上的控件

如何访问另一个应用程序窗口上的控件?
我需要更改控件的值(如文本框)或单击它们(如按钮)。
我想我应该使用API​​函数? 但是怎么样?

请参阅SendKeys类并阅读本文 ,以下是文章中的示例:

// 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("="); } 

寻找“间谍++”: http : //msdn.microsoft.com/en-us/library/dd460756.aspx

您可以使用它访问其他窗口上的控件。

您应该使用EnumWindowFindWindow等Windows API,然后使用EnumChildWindows API查找目标窗口中的控件,如您要查找的文本框,然后使用API SetWindowText

看看这里有一些想法: 为什么EnumChildWindows会跳过孩子? 也可以在Stack Overflow中搜索这些API名称,你会发现很多例子……