0

Could someone guide me in the direction of how I would determine IE's current URL programmatically without a BHO?

The only way I have been able to think of accomplishing this sort of functionality is by looking at the title for the window rather then the URL but this seems hacky.

On the other hand I assume that the textbox that stores the URL would have a handle which I attach to and read the text. Am I correct in this assumption?

Any guidance would be appreciated.

PS: Bonus points if you can provide an example/guidance that will work with Firefox also.

EDIT: OK so further research is starting to uncover that what I need to look at is GetWindowText and the message WM_GETTEXT. If I get this all worked out will post answer.

Maxim Gershkovich
  • 45,951
  • 44
  • 147
  • 243
  • "Bonus points if you can provide an example/guidance that will work with Firefox also." - pretty much impossible to do that without writing specific code for each browser. Additionally it might be hard for firefox as it uses custom controls (afaik) which might not even have windows handles. – ThiefMaster Mar 10 '11 at 07:20
  • 1
    @ThiefMaster: There is always the Accessibility way ( MSAA or others ) that all browsers implement, the search patch for the component will be different but the basis are the same, and it may not change as often as HWNDs – Julien Roncaglia Mar 10 '11 at 09:22

1 Answers1

0

So this is a REALLLLLY old post, but I stumbled upon it so figured I would attempt to answer it since I just learned this :)

You can do it using the Windows Shell. You can iterate through the open windows and look for any "HTTPDocumentClass" object (these are Internet Explorer windows) and then you can access the .LocationUrl member to find out the URL.

I don't know how to write an example in C#, but here's how you do it in VB.
NOTE: You need to add references to Microsoft Shell Controls and Automation and Microsoft Internet Controls.

Imports Shell32
Imports SHDocVw

Public Function GetIExplorerURL() As String()
    Dim exShell As New Shell32.Shell
    Dim URLs As New List(Of String)
    For Each window As SHDocVw.ShellBrowserWindow In DirectCast(exShell.Windows, SHDocVw.IShellWindows)
        If TypeName(window.Document) = "HTMLDocumentClass" Then
            URLs.Add(window.LocationURL)
        End If
    Next

    Return URLs.ToArray
End Function
CBRF23
  • 1,340
  • 1
  • 16
  • 44