凤之焚的博客

静者,无澜也.净者,无贪也.无贪无澜者,海纳百川也!
posts - 2, comments - 5, trackbacks - 0, articles - 0
  C++博客 :: 首页 :: 新随笔 :: 联系 :: 聚合  :: 管理

获得Frame或IFrame中的IHTMLDocumnet2接口

Posted on 2006-09-05 21:07 凤之焚 阅读(1940) 评论(3)  编辑 收藏 引用 所属分类: IE相关

IHTMLDocument2* GetDocFromFrame(IHTMLDocument2* pDoc2)
{
  CComPtr<IHTMLDocument3> pDoc3;
  CComPtr<IHTMLDocument2> pDoc2Frame;

  hr = pDoc2->QueryInterface(IID_IHTMLDocument3,(void**)&pDoc3) ;
  if(hr==S_OK)
  {
    CComBSTR bstrName("FRAME");//CComBSTR bstrName("IFRAME");
    CComPtr<IHTMLElementCollection> pElemCollFrame;
    hr=pDoc3->getElementsByTagName(bstrName,&pElemCollFrame);
    if (hr!=S_OK) return NULL;

    long pLength;
    hr=pElemCollFrame->get_length(&pLength);
    if(hr!=S_OK) return NULL;
   
    for(int i=0;i<pLength;i++)
    {
      IDispatch *pDispFrame=NULL;
      CComVariant vIndex=i;
      hr=pElemCollFrame->item(vIndex,vIndex,&pDispFrame);
      if(hr!=S_OK) continue;
     
      CComPtr<IHTMLElement> pElemFrame;
      hr=pDispFrame->QueryInterface(IID_IHTMLElement,(void**)&pElemFrame);
      if(hr!=S_OK) continue;

      CComPtr<IHTMLFrameBase2> pFrameBase2;
      hr=pElemFrame->QueryInterface(IID_IHTMLFrameBase2,(void**)&pFrameBase2);
      if(hr!=S_OK) continue;
     
      CComPtr<IHTMLWindow2> pWindow2;
      hr=pFrameBase2->get_contentWindow(&pWindow2);
      if(hr==S_OK)
      {
        hr=pWindow2->get_document(&pDoc2Frame);
        if (hr==S_OK)
        {
          return pDoc2Frame;
        }
      }
    }
    pDispFrame->Release();
  }
  return NULL;
}

Feedback

# re: 获得Frame或IFrame中的IHTMLDocumnet2接口  回复  更多评论   

2006-09-05 22:26 by 万连文
如果可以结合BHO讲解一下应该很不错!

# re: 获得Frame或IFrame中的IHTMLDocumnet2接口  回复  更多评论   

2006-09-06 10:14 by 凤之焚
好,有机会写一篇BHO的文章,不过不太明白万连文朋友的意思。

# re: 获得Frame或IFrame中的IHTMLDocumnet2接口  回复  更多评论   

2006-11-22 03:22 by lael
最近要区分这个,不过是用mimefilter
因为我只需在主框架过滤. 子框架不去操作

只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理