|
-
Feb 24th, 2000, 03:13 AM
#1
Thread Starter
Lively Member
Hello,
------
How can I send a message to Internet Explorer to go to a different URL?
Thanks in advance!
-
Feb 24th, 2000, 03:41 AM
#2
Try this code I wrote a while back:
Code:
'In a Module..
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 EnumChildWindows Lib "user32" (ByVal hWndParent As Long, ByVal lpEnumFunc As Long, ByVal lParam As Long) As Long
Private Declare Function GetClassName Lib "user32" Alias "GetClassNameA" (ByVal hwnd As Long, ByVal lpClassName As String, ByVal nMaxCount As Long) As Long
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Private Declare Function SetForegroundWindow Lib "user32" (ByVal hwnd As Long) As Long
Private Const WM_SETTEXT = &HC
Private Const WM_KEYDOWN = &H100
Private lEditHwnd As Long
Private Function EnumProc(ByVal hwnd As Long, ByVal lParam As Long) As Boolean
Dim sClass As String * 255
Call GetClassName(hwnd, sClass, 255)
If Left(sClass, 4) = "Edit" Then lEditHwnd = hwnd
EnumProc = hwnd
End Function
Public Function NavigateIE(ByVal sString As String) As Boolean
Dim lIEWnd As Long
lIEWnd = FindWindowEx(0&, 0&, "IEFrame", vbNullString)
If lIEWnd Then
Call EnumChildWindows(lIEWnd, AddressOf EnumProc, 0&)
Call SendMessage(lEditHwnd, WM_SETTEXT, 0&, ByVal sString)
Call SendMessage(lEditHwnd, WM_KEYDOWN, vbKeyReturn, 0&)
Call SetForegroundWindow(lIEWnd)
NavigateIE = True
End If
End Function
Usage: bSuccess = NavigateIE(sNewURL)
-
Feb 24th, 2000, 03:53 AM
#3
Or you can instantiate an IE object like this (Add a reference to Microsoft Internet Controls):
Code:
Private Sub Command1_Click()
Dim IE As New SHDocVw.InternetExplorer
IE.Navigate "www.vb-world.net"
IE.Visible = True
End Sub
-
Feb 24th, 2000, 04:13 AM
#4
Serge has a good point, although it will instanciate a New copy of the IE Browser, whereas I thought you wanted to change the URL in the Current Browser, appologies if I misunderstood.
-
Feb 24th, 2000, 04:19 AM
#5
Or simply use the ShellExecute API function
Code:
Private Declare Function ShellExecute _
Lib "shell32.dll" Alias "ShellExecuteA" ( _
ByVal hwnd As Long, _
ByVal lpOperation As String, _
ByVal lpFile As String, _
ByVal lpParameters As String, _
ByVal lpDirectory As String, _
ByVal nShowCmd As Long) As Long
Private Sub Command1_Click()
ShellExecute Me.hwnd, "Open", _
"http://www.vb-world.net", "", "", "", _
vbNormalFocus
End Sub
Good luck!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|