| Get current URL from IE | ||||||||||||||||||||||||||
| How to locate the control in Internet Explorer that has the current URL. | ||||||||||||||||||||||||||
I often get asked questions like : "How do I get/retrieve the current URL / web document address from Internet Explorer?", "How do I hook to IE URL address bar?", "How to enumerate all IE windows and pick the web address?" and even "How do I intercept and change URL's in IE?"
This article presents one approach you can use to grab the URL from all opened IE windows using Delphi.
To be able to grab a text from an arbitrary window (and its child windowed controls) on the Windows Desktop, you'll need to play with Windows API calls and Windows Messages. First, or better to say last, when you find that combo box with the current URL in it, you can send a WM_GETTEXT message to that window and pick the text displayed inside. Second, or better to say first, you need to know the exact order of controls that are parents to that URL combo box. Then, you use the FindWindowEx API call in order to retrieve the handle (an integer number that uniquely identifies each control / window) of the child window. Ok, all seems easy, but again how do you know the structure of IEs controls and their parenthood?
Window information to the max Now you know how Delphi guru developers know everything about any application :)
![]() Locating IE windowsSo, now we know the internal structure of IE, and what that combo box (its class) carrying the URL is named (that is 'ComboBox'); and more importantly we know the names of its parents. Note that the main IE window is called "IEFrame" - this is like TApplication for any Delphi application.To retrieve the handle to the top-level window whose class name is provided (in our case: IEFrame), you can use the FindWindow API call. When you have the IE handle you then use the FindWindowEx API, to locate that ComboBox control with the URL. Finally, as already mentioned above, you send that ComboBox the WM_GETTEXT message to obtain the text from it. This seems easy. However, note that FindWindow API retrieves the handle to the top-level window. What this means is that if you have multiple instances of IE opened (as you probably have) the function will locate the last activated IE window. Uh, now what? Windows help! Callback! Conclusion on how to retrieve the URL from all opened IE windows:
I suppose you are more than eager to see the real code... Next page > The real CODE > Page 1, 2 |
||||||||||||||||||||||||||


