日期:2014-05-17  浏览次数:20691 次

请问IWebBrowser2 ,的引用空间是什么?
为什么我下面这段代码会提示, IWebBrowser2 缺少引用空间?
  //计算元素位置的方法,其实最正规的是如下的策略(这个策略包括了iframe的计算):

  /// <summary>
  /// 得到node的所有父亲frames
  /// </summary>
  /// <param name="root"></param>
  /// <param name="elem"></param>
  /// <param name="frames"></param>
  /// <returns></returns>
  private static bool _getEleParentFrames(IHTMLDOMNode root, IHTMLDOMNode node, List<IHTMLDOMNode> frames)
  {
  if (root == node)
  return true;

  bool isFrame = false;
  string tag = root.nodeName.ToLower();
  if (tag == "frame" || tag == "iframe")
  isFrame = true;

  IHTMLDOMChildrenCollection cs = null;
  if (isFrame)
  {
  IWebBrowser2 pwb = root as IWebBrowser2;
  if (pwb != null)
  {
  IHTMLDocument2 pdoc2 = pwb.Document as IHTMLDocument2;
  if (pdoc2 != null)
  {
  IHTMLDOMNode htmlElem = pdoc2.body.parentElement as IHTMLDOMNode;
  cs = htmlElem.childNodes as IHTMLDOMChildrenCollection;
  }
  }
  }
  if (cs == null)
  {
  cs = root.childNodes as IHTMLDOMChildrenCollection;
  }

  if (cs == null)
  return false;
  for (int idx = 0; idx < cs.length; idx++)
  {
  IHTMLDOMNode c = cs.item(idx) as IHTMLDOMNode;
  if (_getEleParentFrames(c, node, frames))
  {
  if (isFrame)
  frames.Add(root);
  return true;
  }
  }
  return false;
  }

------解决方案--------------------
using SHDocVw;
using mshtml;


引用:Microsoft HTML Object Library 和 Microsoft Internet Controls