您好可以帮助解决此代码
我尝试获取所有Chrome标签的Url并将其插入列表框
,项目已经运行,没有任何错误。
代码表1:
Imports System.Runtime.InteropServices
Imports NDde.Client
Public Class Form1
<DllImport("user32.dll", SetLastError:=True, CharSet:=CharSet.Auto)>
Private Shared Function FindWindow(
ByVal lpClassName As String,
ByVal lpWindowName As String) As IntPtr
End Function
<DllImport("user32.dll", SetLastError:=True, CharSet:=CharSet.Auto)>
Private Shared Function FindWindowEx(ByVal parentHandle As IntPtr,
ByVal childAfter As IntPtr,
ByVal lclassName As String,
ByVal windowTitle As String) As IntPtr
End Function
<DllImport("user32.dll", SetLastError:=True, CharSet:=CharSet.Auto)>
Private Shared Function SendMessage(ByVal hWnd As IntPtr, ByVal Msg As UInteger, ByVal wParam As IntPtr, ByVal lParam As IntPtr) As IntPtr
End Function
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim h As IntPtr
For Each p As Process In Process.GetProcessesByName("chrome")
h = FindWindow("Chrome_WidgetWin_1", p.MainWindowTitle)
Exit For
Next
Dim urlH As IntPtr
urlH = FindWindowEx(h, 0, "Chrome_OmniboxView", Nothing)
Dim urlHH As IntPtr = Marshal.AllocHGlobal(100)
Dim NumText As Integer = SendMessage(urlH, &HD, 50, urlHH)
Dim url As String = Marshal.PtrToStringUni(urlHH)
ListBox1.Items.Add(url)
End Sub
End Class
错误:Error Issue
答案 0 :(得分:1)
您可以找到更简单的方法(在项目资源中使用Autohotkey.exe)
我认为您能做到的一切。很难获得兼容的System.Windows.Automation