我通过 Windows SDK 中部署的 Windows UI 自动化工具验证这些“图标”是 ControlType.Button 类型的控件
你是对的somewhat。从技术上讲,他们是不在 ToolbarWindow32 中,而是在 Shell_TrayWnd 中。我检查了该区域,发现这些按钮实际上位于一个ToolBar
,所以你需要寻找ControlType.ToolBar
。接下来你需要FindAll
它将返回满足以下条件的所有 AutomationElementsPropertyCondition
...
注意:第一个循环是获取用户升级通知区域。下一个有趣的循环是获取正在运行的应用程序按钮...(代码适用于 WIN7、WIN8 和 WIN10)
在下面的示例中,我追求Shell_TrayWnd
这将为我们提供我们需要的东西。然后我浏览并找到什么ToolBar
我们在后面,然后循环并FindAll
控制类型Button
...
Dim arrText As New List(Of String)
Dim tskBarClassName As String = "Shell_TrayWnd"
Dim tskBarHwnd As IntPtr = FindWindow(tskBarClassName, Nothing)
Dim window As AutomationElement = AutomationElement.FromHandle(tskBarHwnd)
Dim condition As New PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.ToolBar)
Dim elementCollection As AutomationElementCollection = window.FindAll(TreeScope.Descendants, condition)
'for fun get all we can...
For Each aE As AutomationElement In elementCollection
If aE.Current.Name.Equals("User Promoted Notification Area") Then
For Each ui As AutomationElement In aE.FindAll(TreeScope.Descendants, New PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.Button))
arrText.Add("Notification Area - " & Replace(ui.Current.HelpText, Chr(10), " "c)) 'removed line break as when shown it would show some on a new line in messagebox
Next
ElseIf aE.Current.Name.Equals("Running applications") Then
For Each ui As AutomationElement In aE.FindAll(TreeScope.Descendants, New PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.Button))
arrText.Add("Toolbar Area - " & Replace(ui.Current.Name, Chr(10), " "c)) 'removed line break as when shown it would show some on a new line in messagebox
Next
End If
Next
If arrText.Count > 0 Then
MessageBox.Show(String.Join(Environment.NewLine, arrText.ToArray))
End If
如果您有任何疑问,请告诉我。下图(出于安全原因我注释掉了一些内容)