Results 1 to 5 of 5

Thread: Tell Internet Explorer to go to a different URL

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jul 2002
    Posts
    95

    Post

    Hello,
    ------

    How can I send a message to Internet Explorer to go to a different URL?

    Thanks in advance!

  2. #2
    Guru Aaron Young's Avatar
    Join Date
    Jun 1999
    Location
    Red Wing, MN, USA
    Posts
    2,177

    Post

    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)

  3. #3
    Serge's Avatar
    Join Date
    Feb 1999
    Location
    Scottsdale, Arizona, USA
    Posts
    2,744

    Post

    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

  4. #4
    Guru Aaron Young's Avatar
    Join Date
    Jun 1999
    Location
    Red Wing, MN, USA
    Posts
    2,177

    Post

    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.

  5. #5
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649

    Post

    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
  •  



Click Here to Expand Forum to Full Width