简体   繁体   中英

Getting current URL of Internet Explorer 8 programatically

I'm developing a simple Internet Explorer add-on and I'm trying to get the current URL of the Address Bar of the IE 8 using the series of (example) HWND handle = FindWindowEx(parent_handle,0,"AddressDisplay Control",NULL);

in the following order:

1- IEFrame
2- WorkerW
3- ReBarWindow32
4- Address Band Root
5- Edit 
5- (alternatively) AddressDisplay Control

I've determined this series of controls using the winspy++ 1.6

The code I'm trying to get the current URL is:

TCHAR currentURL[255];
::GetWindowText(handle_to_the_Edit_or_AddressDisplay_control, currentURL, 255);

However it sets nothing into the currentURL array.

This method, with the names and series of controls slightly changed, used to work in earlier versions ıf IE, I could easliy get the current URL, but for IE 8 I've unable to get it.

What should I do? Thanks

Note: I've searched many pages and posts. No luck.

After applying @Remy Lebeau's suggestion char *p = _com_util::ConvertBSTRToString(bstrURL); , ::SendMessage(hMyEditControl,WM_SETTEXT,0,(long)p); started to display correctly.

And this explains why the IE 7 way of getting the URL from the UI controls doesn't work on IE 8:

Because that is not the right way to do it, even in IE7. 
Just because it could be done that way does not mean it should be done that way.
There is a reason why a BHO has direct access to the underlying WebBrowser object,
the BHO should not rely on any particular UI representation of the WebBrowser object.

So that's the accepted answer.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM