回答編集履歴
1
C#版の追加
answer
CHANGED
@@ -93,4 +93,89 @@
|
|
93
93
|
}
|
94
94
|
|
95
95
|
|
96
|
+
```
|
97
|
+
|
98
|
+
---
|
99
|
+
C#版を追加しました。
|
100
|
+
参照の追加からCOMを選んでUIAUtomationClientをチェックしてください。
|
101
|
+

|
102
|
+
|
103
|
+
|
104
|
+
``` C#
|
105
|
+
using System;
|
106
|
+
using UIAutomationClient;
|
107
|
+
|
108
|
+
namespace ConsoleApp1
|
109
|
+
{
|
110
|
+
class Program
|
111
|
+
{
|
112
|
+
[STAThread]
|
113
|
+
static void Main(string[] args)
|
114
|
+
{
|
115
|
+
string CLSID_CUIAutomation = "ff48dba4-60ef-4201-aa87-54103eef594e";
|
116
|
+
Type type = Type.GetTypeFromCLSID(Guid.Parse(CLSID_CUIAutomation));
|
117
|
+
IUIAutomation automation = Activator.CreateInstance(type) as IUIAutomation;
|
118
|
+
|
119
|
+
IUIAutomationElement root = automation.GetRootElement();
|
120
|
+
IUIAutomationTreeWalker walker = automation.RawViewWalker;
|
121
|
+
|
122
|
+
IUIAutomationElement edge = null;
|
123
|
+
edge = walker.GetFirstChildElement(root);
|
124
|
+
while (edge != null)
|
125
|
+
{
|
126
|
+
string name = edge.CurrentName;
|
127
|
+
if(!string.IsNullOrEmpty(name) && name .EndsWith(" - Microsoft Edge"))
|
128
|
+
{
|
129
|
+
break;
|
130
|
+
}
|
131
|
+
IUIAutomationElement next= walker.GetNextSiblingElement(edge);
|
132
|
+
edge = next;
|
133
|
+
}
|
134
|
+
if (edge == null)
|
135
|
+
{
|
136
|
+
return;
|
137
|
+
}
|
138
|
+
|
139
|
+
//Edge配下のタイトルが取得できそうなエレメントを取得
|
140
|
+
IUIAutomationElement m_tabContentDCompVisualElement = null;
|
141
|
+
{
|
142
|
+
const int UIA_AutomationIdPropertyId = 30011;
|
143
|
+
var cond = automation.CreatePropertyCondition(UIA_AutomationIdPropertyId,
|
144
|
+
"m_tabContentDCompVisualElement");
|
145
|
+
m_tabContentDCompVisualElement = edge.FindFirst(TreeScope.TreeScope_Subtree, cond);
|
146
|
+
}
|
147
|
+
|
148
|
+
if (m_tabContentDCompVisualElement == null)
|
149
|
+
{
|
150
|
+
return;
|
151
|
+
}
|
152
|
+
|
153
|
+
//タイトル
|
154
|
+
string title = m_tabContentDCompVisualElement.CurrentName;
|
155
|
+
|
156
|
+
//Edge配下のURLが取得できそうなエレメントを取得
|
157
|
+
IUIAutomationElement ie_server;
|
158
|
+
{
|
159
|
+
const int UIA_ClassNamePropertyId = 30012;
|
160
|
+
var cond = automation.CreatePropertyCondition(UIA_ClassNamePropertyId, "Internet Explorer_Server");
|
161
|
+
ie_server = edge.FindFirst(TreeScope.TreeScope_Subtree, cond);
|
162
|
+
|
163
|
+
}
|
164
|
+
|
165
|
+
if (ie_server == null)
|
166
|
+
{
|
167
|
+
return;
|
168
|
+
}
|
169
|
+
|
170
|
+
//URL
|
171
|
+
string url = ie_server.CurrentName;
|
172
|
+
|
173
|
+
Console.WriteLine(title);
|
174
|
+
Console.WriteLine(url);
|
175
|
+
Console.ReadKey();
|
176
|
+
}
|
177
|
+
|
178
|
+
}
|
179
|
+
}
|
180
|
+
|
96
181
|
```
|