从编程中获取Internet Explorer 8的当前URL

Getting current URL of Internet Explorer 8 programatically

本文关键字:URL Explorer 编程 获取 Internet      更新时间:2023-10-16

我正在开发一个简单的Internet Explorer附加组件,我正在尝试使用一系列(示例(HWND handle = FindWindowEx(parent_handle,0,"AddressDisplay Control",NULL);

按以下顺序:

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

我已经确定了使用winspy 1.6

确定此系列对照

我正在尝试获取当前URL的代码是:

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

但是,它没有设置在Currenturl数组中。

这种方法,具有稍微更改的名称和一系列控件,用于较早版本ıfie,我可以easliy获取当前的URL,但是对于IE 8,我无法获得它。

我该怎么办?谢谢

注意:我已经搜索了许多页面和帖子。没有运气。

应用@Remy Lebeau的建议char *p = _com_util::ConvertBSTRToString(bstrURL);::SendMessage(hMyEditControl,WM_SETTEXT,0,(long)p);开始正确显示。

这说明了为什么从UI控件中获取URL的IE 7方法在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.

这就是接受的答案。