怎么用vb修改IE地址?
想做这样一个程序:
1、用FindWindow、FindWindowEx……找到IE的地址栏
2、用SendMessage将地址栏内的内容修改为百度的网址(左边text中的内容)
3,将原来谷歌的网址写到右边text中
------------------------------------
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByValwParam As Long, lParam As Any) As Long
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Sub Command1_Click()
Dim winHwnd As Long
Dim lngRetVal As Long
winHwnd = FindWindow("IEFrame", vbNullString)
Debug.Print winHwnd
If winHwnd <> 0 Then
RetVal = SendMessage()
Else
MsgBox "IE没有运行。"
End If
End Sub
-----------------------------------------
本人菜鸟,目前只能找到IE,可里面的地址栏怎么找呢?,
SendMessage有如何发送呢?
请高手们帮忙啊…… --------------------编程问答-------------------- 一。把下面代码复制到一个模块中
Option Explicit
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByValwParam As Long, lParam As Any) As Long
Private Declare Function SendMessageByNum Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal 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 EM_LINELENGTH = &HC1
Private Const EM_REPLACESEL = &HC2
Private Const EM_SETSEL = &HB1
'模拟向文本输入框发送文本
Public Sub SendWinText(Hwd As Long, SendString As String, Optional OverWrite As Boolean = True)
Dim K As Long, aClass As String
If Hwd = 0 Then Exit Sub
If OverWrite = True Then
K = SendMessage(Hwd, EM_LINELENGTH, 1, 0) '取得文本宽度
SendMessageByNum Hwd, EM_SETSEL, 0, K '选中文本
End If
SendMessageByString Hwd, EM_REPLACESEL, 1, SendString '传递文本
End Sub
二。假设IE地址栏的句柄为459690,那么通过下面调用就可以修改IE地址:
SendWinText 459690,"www.baidu.com" --------------------编程问答--------------------
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 SendMessageByString& Lib "user32" Alias "SendMessageA" (ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As String)
Private Const WM_SELECTALL = &HB1 '全选
Private Const WM_CLEAR = &H303 '清除
Private Const WM_GETTEXT = &HD '取得字串
Private Const WM_SETTEXT = &HC '送出字串
Sub Main()
Dim iEdit As Long, iTmp(4) As Long
Dim oStr As String '原始字串纪录
iTmp(0) = FindWindowEx(0&, 0&, "IEFrame", vbNullString) '一路向下搜寻
iTmp(1) = FindWindowEx(iTmp(0), 0&, "WorkerW", vbNullString)
iTmp(2) = FindWindowEx(iTmp(1), 0&, "ReBarWindow32", vbNullString)
iTmp(3) = FindWindowEx(iTmp(2), 0&, "ComboBoxEx32", vbNullString)
iTmp(4) = FindWindowEx(iTmp(3), 0&, "ComboBox", vbNullString)
iEdit = FindWindowEx(iTmp(4), 0&, "Edit", vbNullString)
oStr = Space(255) '要多少字的Buffer自己决定
SendMessageByString iEdit, WM_SELECTALL, ByVal 0&, ByVal 0& '全选edit内字串
SendMessageByString iEdit, WM_GETTEXT, Len(oStr), ByVal oStr '取得edit内字串(随便你要贴那儿)
SendMessageByString iEdit, WM_CLEAR, ByVal 0&, ByVal 0& '清除edit内字串
SendMessageByString iEdit, WM_SETTEXT, ByVal 0&, ByVal "ABCDR1234" '发送字串至edit(随便你要送什麽字串)
End Sub
补充:VB , API