以编程方式获取当前 URL 的 Internet Explorer 8

Getting current URL of Internet Explorer 8 programatically

我正在开发一个简单的 Internet Explorer 附加组件,我正在尝试使用(示例)HWND handle = FindWindowEx(parent_handle,0,"AddressDisplay Control",NULL); 系列获取 IE 8 地址栏的当前 URL

顺序如下:

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);

然而它没有设置当前URL数组。

此方法的名称和控件系列略有变化,以前在 IE 的早期版本中有效,我可以轻松获取当前的 URL,但对于 IE 8 我无法获取.

我该怎么办?谢谢

注意:我搜索了很多页面和帖子。运气不好。

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

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

这就是公认的答案。