获取 IE 当前 URL 的代码源码精华教程
精选公文范文管理资料
获取 IE 当前 URL 的代
码源码精华教程
获取 IE 当前 URL 的代码,上有许多类似
代码,但在WINDOWSXP 下不能运行。查
了一些资料,发现由于Win2000,WINXP 是
基于Unicode代码的操作系统,所以没有
WorkerA类,而以WorkerW类取而代之
(XXXXA should be used on not unicode compliant windows oses likes Windows 95,98 etc and on unicode enabled oses replace A with W. Remember WorkerA or WorkerW doesn?t have something related to IE version. To obtain all of the opened IEs URL use EnumWindows callback function and cheers. )。
Option Explicit
Private Declare Function FindWindow Lib “user32” Alias “FindWindowA” (ByVal lpClassName As String, ByVal
lpWindowName As String) As
[键入文字] [键入文字] [键入文字]
精选公文范文管理资料
Long ?Findwindow函数的功能是找到当
前运行的IE窗口的url地址的句柄
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 „FindwindowEx函数的功能是找到子窗体的
句柄
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_GETTEXT = HD
Private Sub Command1_Click()
getcurrenturl
End Sub
Sub getcurrenturl(Optional ByRef URL As String)
Dim hwnd As Long „设定一个长整形
[键入文字] [键入文字] [键入文字]
精选公文范文管理资料
变量用来接收函数返回值
hwnd = 0 „初始化
hwnd = FindWindowEx(hwnd, 0, “IEFrame”, vbNullString) „IE窗口句柄
hwnd = FindWindowEx(hwnd, 0, “Workerw”, vbNullString) „IE窗口的工作区
句柄
hwnd = FindWindowEx(hwnd, 0, “ReBarWindow32”, vbNullString) „IE窗口的
菜单栏句柄
hwnd = FindWindowEx(hwnd, 0, “ComboBoxEx32”, vbNullString) „IE窗口下
拉菜单句柄
hwnd = FindWindowEx(hwnd, 0, “ComboBox”, vbNullString) „IE窗口下拉菜
单当前项句柄
hwnd = FindWindowEx(hwnd, 0, “Edit”, vbNullString) „„IE窗口下拉菜单编辑
框句柄
URL = String(1024, Chr(0)) „初始化
字符串
SendMessageByString hwnd, [键入文字] [键入文字] [键入文字]
精选公文范文管理资料
WM_GETTEXT, 1025, URL „向系统发送获得IE窗体地址栏中的字符串命令
URL = Split(URL, Chr(0))(0) „根据 URL 长度得到 URL 值
MsgBox URL „显示IE当前址
End Sub
(出处:
[键入文字] [键入文字] [键入文字]