feng8848 2023-02-01 04:07 采纳率: 0%
浏览 8

Visual Basic6.0

Visual Basic6.0如何读取当前 Chrome浏览器网址

  • 写回答

1条回答 默认 最新

  • m0_54204465 2023-02-01 08:12
    关注

    在 Visual Basic 6.0 中读取当前 Chrome 浏览器网址可以使用 Windows API。可以使用 FindWindow 函数找到 Chrome 浏览器的窗口,然后使用 GetWindowText 函数获取标题栏的文本,最后通过 Split 函数从标题栏中提取网址。

    Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
    Private Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hWnd As Long, ByVal lpString As String, ByVal cch As Long) As Long
    Private Declare Function GetWindowTextLength Lib "user32" Alias "GetWindowTextLengthA" (ByVal hWnd As Long) As Long
    
    Function GetChromeURL() As String
    Dim hWnd As Long
    Dim sText As String
    Dim aText() As String
    hWnd = FindWindow("Chrome_WidgetWin_1", vbNullString)
    If hWnd Then
        sText = Space$(GetWindowTextLength(hWnd) + 1)
        If GetWindowText(hWnd, sText, Len(sText)) Then
            aText = Split(sText, Chr$(0))
            GetChromeURL = aText(0)
        End If
    End If
    End Function
    

    代码在Windows 系统中适用,在其他系统中不能使用。此外,也不支持所有版本的 Chrome 浏览器,在试用之前确保。

    评论

报告相同问题?

问题事件

  • 创建了问题 2月1日