在C#否则VB.Net,我怎么会用微软UI自动化检索包含文本的控件的文本?使用Microsoft UI Automation获取任何应用程序的标题栏标题?
我一直在研究MSDN文档,但我不明白。
Obtain Text Attributes Using UI Automation
然后,例如,用下面的代码,我试着给那个窗口的HWND检索窗口标题栏的文本,但我不知道exactlly如何遵循标题栏找到真正包含文本的子控件(标签?)。
Imports System.Windows.Automation
Imports System.Windows.Automation.Text
。
Dim hwnd As IntPtr = Process.GetProcessesByName("notepad").First.MainWindowHandle
Dim targetApp As AutomationElement = AutomationElement.FromHandle(hwnd)
' The control type we're looking for; in this case 'TitleBar'
Dim cond1 As New PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.TitleBar)
Dim targetTextElement As AutomationElement =
targetApp.FindFirst(TreeScope.Descendants, cond1)
Debug.WriteLine(targetTextElement Is Nothing)
在上面的例子中,我试着用标题栏,但是我想用任何其他包含文本的控件来做到这一点......就像一个标题栏。
PS:我知道P/Invoking GetWindowText
API。
你知道这是一个WPF的东西,对吗? – Plutonix
它也适用于WinForms以及任何C/C++ bin,使用UI自动化您可以监视/检查所有类型的可执行文件,不仅WPF,但我知道MSDN信息非常令人困惑。 – ElektroStudios
我只是想确定你知道它是什么。 – Plutonix