開発:Visual Studio 2015(64bit)
言語:VB.net
OS :windows7→windows10
web:IE11→Edge
GetElementById で指定のフォームに値の貼り付けを行うプログラムの改修を行っています。
IE11ではGetTopWindow、GetWindowThreadProcessId、GetWindowを駆使して、
対象のプロセスIDの取得が行えましたが、MS EDGEではプロセスIDの取得が行えず、
ハンドルの取得がで行えません。
VB.NETから起動したMS EDGEのProcessIDの取得方法を教えて頂けないでしょうか?
・MS EDGE起動部分ソース
Dim con As Object,
wUrl = "microsoft-edge:" & Url & ""
(※Urlに対象URLを設定)
Con = CreateObject("Shell.Application").ShellExecute(wUrl)
・ProcessIDの取得部分ソース
hWnd = GetTopWindow(0)
Do
If GetParent(hWnd) = 0 Then
'ウィンドウハンドルからプロセスIDを取得し、Edgeのウィンドウかどうかを判別する
GetWindowThreadProcessId(hWnd, pid)
items = con.ExecQuery("Select * From Win32_Process Where (ProcessId = '" & pid & "') And (Name = '" & ProcessName & "')")
(※ProcessNameに"MicrosoftEdge.exe"を設定)
If items.Count > 0 Then
'Edgeの子ウィンドウ列挙
EnumChildWindows(hWnd, New EnumWindowsDelegate(AddressOf EnumChildProcIES), 0)
If hIES <> 0 Then Exit Do
End If
End If
hWnd = GetNextWindow(hWnd, GW_HWNDNEXT)
Loop While hWnd <> 0
If hIES = 0 Then Exit Sub
'Edgeの子ウィンドウ列挙処理
Private Function EnumChildProcIES(ByVal hWnd As Long, ByVal lParam As Long) As Boolean
Dim buf As String = ""
Dim ClassName As String
GetClassName(hWnd, buf, Len(buf))
ClassName = Left(buf.ToString, InStr(buf.ToString, vbNullChar) - 1)
If ClassName = "Internet Explorer_Server" Then
hIES = hWnd
EnumChildProcIES = False
Exit Function
End If
EnumChildProcIES = True
End Function