【问题标题】:Getting current URL of Internet Explorer 8 programatically以编程方式获取 Internet Explorer 8 的当前 URL
【发布时间】:2019-05-15 16:45:18
【问题描述】:

我正在开发一个简单的 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);

但是它在 currentURL 数组中没有设置任何内容。

这个方法,名称和控件系列略有改变,以前在早期版本中可以使用,如果 IE,我可以轻松获取当前 URL,但对于 IE 8,我无法获取它。

我该怎么办?谢谢

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

【问题讨论】:

  • 我闻到了恶意软件的味道。希望您在开发过程中安装了 AV 解决方案。 :P
  • 该问题与任何安全问题无关。这只是一个编程练习。
  • 究竟是什么样的插件?如果它是一个 BHO(浏览器帮助对象),那么它可以直接访问浏览器的 IWebBrowser2 接口,并且可以简单地查询它的当前 URL,而不必求助于访问 UI 控件。
  • @Romario 因为这不是正确的方法,即使在 IE7 中也是如此。仅仅因为它可以那样做并不意味着它应该那样做。 BHO 可以直接访问底层 WebBrowser 对象是有原因的,BHO 不应依赖于 WebBrowser 对象的任何特定 UI 表示。

标签: c++ winapi visual-c++ mfc internet-explorer-8


【解决方案1】:

应用@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.

所以这是公认的答案。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-03-05
    • 2011-03-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多