Results 1 to 2 of 2

Thread: Reading MS IE Address

  1. #1
    LeitonOllie
    Guest

    Question

    I am trying to find a way to read the Address bar from an open instance of Internet explorer into my program. I am not bothered as to how it is done. Can someone help please?

    [email protected]

  2. #2
    Serge's Avatar
    Join Date
    Feb 1999
    Location
    Scottsdale, Arizona, USA
    Posts
    2,744
    Try this:
    Code:
    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 Any) As Long
    Private Declare Function SendMessageStr Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As String) As Long
    Private Declare Function GetWindowTextLength Lib "user32" Alias "GetWindowTextLengthA" (ByVal hwnd As Long) As Long
    Private Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String, ByVal cch As Long) As Long
    Private Const WM_GETTEXTLENGTH = &HE
    Private Const WM_GETTEXT = &HD
    
    
    
    Private Sub Command1_Click()
        Dim lngIE As Long
        Dim lngWrkArea As Long
        Dim lngEditBox As Long
        Dim strEditText As String
        Dim lngEditLen As Long
        Dim lngCaptionLen As Long
        Dim strCaption As String
        
        lngIE = FindWindowEx(0, 0, "IEFrame", vbNullString)
        lngWrkArea = FindWindowEx(lngIE, 0, "WorkerW", vbNullString)
        lngWrkArea = FindWindowEx(lngWrkArea, 0, "ReBarWindow32", vbNullString)
        lngWrkArea = FindWindowEx(lngWrkArea, 0, "ComboBoxEx32", vbNullString)
        lngWrkArea = FindWindowEx(lngWrkArea, 0, "ComboBox", vbNullString)
        lngEditBox = FindWindowEx(lngWrkArea, 0, "Edit", vbNullString)
        
        lngEditLen = SendMessage(lngEditBox, WM_GETTEXTLENGTH, 0, 0)
        strEditText = Space(lngEditLen + 1)
        If SendMessageStr(lngEditBox, WM_GETTEXT, lngEditLen, ByVal strEditText) Then
            strEditText = Left(strEditText, InStr(strEditText, vbNullChar) - 1)
        End If
        
        lngCaptionLen = GetWindowTextLength(lngIE)
        strCaption = Space(lngCaptionLen + 1)
        If GetWindowText(lngIE, strCaption, lngCaptionLen + 1) Then
            strCaption = Left(strCaption, InStr(strCaption, "- Microsoft Internet Explorer") - 1)
        End If
        
        MsgBox "The current URL: " & strEditText & vbCrLf & _
                "Page Title: " & strCaption
    End Sub

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