VB获取IE8/IE9地址栏URL

参考:答疑网 http://www.dayi.net
Option Explicit

Private Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" (ByVal hWnd1 As Long, ByVal hWnd2 As Long, ByVal lpsz1 As String, ByVal lpsz2 As String) As Long
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Long) As Long
Private Declare Function SendMessageByString Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As String) As Long
Private Const WM_GETTEXTLENGTH = &HE
Private Const WM_GETTEXT = &HD

Private Sub Command1_Click()

Dim hwnd As Long
Dim retLength As Long, retString As String

hwnd = FindWindowEx(0, 0, "IEFrame", vbNullString)
hwnd = FindWindowEx(hwnd, 0, "WorkerW", vbNullString)
hwnd = FindWindowEx(hwnd, 0, "ReBarWindow32", vbNullString)
hwnd = FindWindowEx(hwnd, 0, "Address Band Root", vbNullString)
hwnd = FindWindowEx(hwnd, 0, "Edit", vbNullString)

retLength = SendMessage(hwnd, WM_GETTEXTLENGTH, 0, 0)
retString = String(retLength, 0)
SendMessageByString hwnd, WM_GETTEXT, retLength + 1, retString

MsgBox retString

End Sub

你可能感兴趣的:(VB获取IE8/IE9地址栏URL)