Accessing Web Browse URL

I am wondering if there is a way to find out what the url of an independently open web browser is.  That is to say that my application needs to know what web page Netscape or IE or any other browser currently has loaded.  It is a functionality that i know can be accomplished, ICQ and AIM both have it.  I woudl like a VB solution, but if there is one in C++ I'd take that as well.  I want to be clear here...this is not a web browser control...this is a seperate independent web browser running concurrently.  

Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

The one way I've heard of doing it involves using FindWindow or EnumWindows
to search for a window with a class string of "IEFrame" for internet explorer, or something equivalent for netscape.  Then traverse the window hierarchy to find the URL textbox and read from that.  

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
musakaAuthor Commented:
Can you explain a little more how one traverses the windo hierarchy?  
I'm developing a little utility to help write code to do it, but it's still a little rough around the edges.  Here's some pointers about the WinAPI calls it uses...

Conceptually, you start at the top of the hierarchy, find the internet explorer window, then find the text box within that, then use GetWindowText to get its contents.

Search for any of the following:
Check article Q168829 in particular.

If you have MS Vis Studio, you can use the included program 'Spy++' to see the hierarchy and see what class names/window texts to look for.

I can give more details (or code) if needed.
Okay, I got it to work yesterday.  Please excuse any mistakes I make in API calls, I'm using a library that uses them indirectly and shrinks the URL finding code to one page.

To start off, I get a list of all the top-level windows (use one of getDesktopWindow&EnumChildWindows or GetWindow).  For each top level window whose class (getClassName) is "IEFrame", I assume it's an internet explorer window and search for the combo box under that.  For each top level window whose class starts with "Afx:", I assume it's a netscape window.

For all top level MS-IE windows, I find all sub windows (using EnumChildWindows or FindWindow or GetWindow) with a class name of "WorkerW", then under that a class name of "ReBarWindow32", then under that a class name of "ComboBoxEx32".  I then use SendMessage with a message of WM_GETTEXT to get the text from the combo box.

The NS windows seemed a bit confusing, their class names all started with "AFX:" and had a bunch of numbers after them.  So I resorted to recursively searching through all subwindows for a window whose class name is "ComboBox" and whose parent's class name starts with "#" (there's probably a better way of doing this).  I again used SendMessage(hwnd, WM_GETTEXT,...) on the combobox.

The problems with this approach are:
  - Only works for MSIE or NS
  - Probably only works for specific versions of MSIE or NS, but you could use these same methods on older versions, you'd just have to install them and use Spy++ to trace their window hierarchy.
  - I couldn't get the results to be in sorted order by z-order (using EnumChildWindows), that is, I didn't know which of the URLs the user had been at most recently.  I'm trying to solve this problem now.  (this could have several interesting uses... :)

If you're interested in the code, I'd be happy to post it along with the required library, but the library is still in the alpha version.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.