【问题标题】:Get the URLs of opened tabs in Chrome .Net获取 Chrome .Net 中打开的标签页的 URL
【发布时间】:2018-06-17 10:44:52
【问题描述】:

你好,可以帮忙看看这段代码

我尝试获取所有 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

【问题讨论】:

    标签: .net vb.net visual-studio-2012 visual-studio-2015


    【解决方案1】:

    你可以找到更简单的东西(在你的项目资源中使用 Autohotkey.exe)

    • 你可以使用ahk,获取你当前活动的Tab url,另外还有复制url功能
    • 制作计时器以粘贴从剪贴板复制的内容。

    我认为你可以做到的。很难获得兼容的 System.Windows.Automation

    【讨论】:

    • 但问题是我找不到可以帮助我获取和复制当前 google chrome url 的好 ahk。
    猜你喜欢
    • 2012-10-29
    • 2019-09-04
    • 1970-01-01
    • 2016-06-19
    • 1970-01-01
    • 2015-09-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多