获取计算器输入框内容的代码:
IntPtr hwnd = FindWindow(null, "计算器"); if (hwnd != IntPtr.Zero) { IntPtr hwnd1 = FindWindowEx(hwnd, 0, "CalcFrame", ""); //获取 的句柄 if (hwnd1 != IntPtr.Zero) { IntPtr hwnd12 = FindWindowEx(hwnd1, 0, "#32770", ""); //获取 的句柄 if (hwnd12 != IntPtr.Zero) { IntPtr hwnd123 = FindWindowEx(hwnd12, 0x100a88, "Static", null); //获取 的句柄 if (hwnd123 != IntPtr.Zero) { StringBuilder strB = new StringBuilder(100); SendMessage(hwnd123, WM_GETTEXT, new IntPtr(255), strB); string a = strB.ToString().Trim(); MessageBox.Show(a); } } } }
参考资料:
如何获取其他程序窗体中Label的内容-.NET技术/C#
FindWindow用法
FindWindowEx用法
自动化测试中FindWindow与FindWindowEx的使用示例
spy++使用方法