如何得到网页中的Frame的HTML接口
2006-07-20 13:40
288 查看
Frame访问
如果是框架,并且其中的文档是HTML,那么可以查询其IWebBrowser2接口来获得你需要的接口
否则可以查询当前HTML文档的IServiceProvider接口,然后查询IID_IWebBrowserApp服务。
参考 http://msdn.microsoft.com/msdnmag/issues/01/06/c/, http://support.microsoft.com/default.aspx?id=196340
IHTMLDocument2* pDoc2;
CComBSTR tagName;
pElement->get_tagName(&tagName);
CString str = tagName;
str.MakeUpper();
if (str == "FRAME" || str == "IFRAME")
{
HRESULT hr;
IHTMLWindow2 *pHTMLWindow;
IHTMLFrameBase2* pHTMLFrameBase2;
hr =pElement->QueryInterface(IID_IHTMLFrameBase2, (void**)&pHTMLFrameBase2);
pElement->Release();
hr = pHTMLFrameBase2->get_contentWindow(&pHTMLWindow);
pHTMLFrameBase2->Release();
hr = pHTMLWindow->get_document(&pDoc2);
然后用IHTMLDocument2对域进行操作
from csdn
-- ------------------------------------------------------------------------------------------------
void CMyView::EnumFrames()
{
IHTMLDocument2 * pDoc = NULL;
IHTMLWindow2 *pHTMLWnd = NULL;
IHTMLDocument2 * pFrameDoc=NULL;
IHTMLFramesCollection2 *pFramesCollection=NULL;
LPDISPATCH lpDispatch;
long p;
VARIANT varindex,varresult;
varresult.vt=VT_DISPATCH;
varindex.vt = VT_I4;
try
{
pDoc = (IHTMLDocument2*)(GetHtmlDocument());
if(pDoc!=NULL)
{
pDoc->get_frames(&pFramesCollection);
if(pFramesCollection!=NULL)
{
pFramesCollection->get_length(&p);
if(p>0)
{
for(int i=0; i<p; i++)
{
varindex.lVal = i;
if(pFramesCollection->item(&varindex, &varresult) ==S_OK)
{
lpDispatch=(LPDISPATCH)varresult.ppdispVal;
if (SUCCEEDED(lpDispatch->QueryInterface(IID_IHTMLWindow2,
(LPVOID *)&pHTMLWnd)))
{
if(SUCCEEDED(pHTMLWnd->get_document( &pFrameDoc)))
{
CString info;
info.Format("%d",pFrameDoc);
MessageBox(info);
pFrameDoc->Release();
pFrameDoc=NULL;
}
pHTMLWnd->Release();
pHTMLWnd=NULL;
}
}
}
}
}
}
}
catch(...)
{
};
try
{
if(pDoc != NULL)
pDoc->Release();
if(pFramesCollection != NULL)
pFramesCollection->Release();
}
catch(...)
{
};
}
如果是框架,并且其中的文档是HTML,那么可以查询其IWebBrowser2接口来获得你需要的接口
否则可以查询当前HTML文档的IServiceProvider接口,然后查询IID_IWebBrowserApp服务。
参考 http://msdn.microsoft.com/msdnmag/issues/01/06/c/, http://support.microsoft.com/default.aspx?id=196340
IHTMLDocument2* pDoc2;
CComBSTR tagName;
pElement->get_tagName(&tagName);
CString str = tagName;
str.MakeUpper();
if (str == "FRAME" || str == "IFRAME")
{
HRESULT hr;
IHTMLWindow2 *pHTMLWindow;
IHTMLFrameBase2* pHTMLFrameBase2;
hr =pElement->QueryInterface(IID_IHTMLFrameBase2, (void**)&pHTMLFrameBase2);
pElement->Release();
hr = pHTMLFrameBase2->get_contentWindow(&pHTMLWindow);
pHTMLFrameBase2->Release();
hr = pHTMLWindow->get_document(&pDoc2);
然后用IHTMLDocument2对域进行操作
from csdn
-- ------------------------------------------------------------------------------------------------
void CMyView::EnumFrames()
{
IHTMLDocument2 * pDoc = NULL;
IHTMLWindow2 *pHTMLWnd = NULL;
IHTMLDocument2 * pFrameDoc=NULL;
IHTMLFramesCollection2 *pFramesCollection=NULL;
LPDISPATCH lpDispatch;
long p;
VARIANT varindex,varresult;
varresult.vt=VT_DISPATCH;
varindex.vt = VT_I4;
try
{
pDoc = (IHTMLDocument2*)(GetHtmlDocument());
if(pDoc!=NULL)
{
pDoc->get_frames(&pFramesCollection);
if(pFramesCollection!=NULL)
{
pFramesCollection->get_length(&p);
if(p>0)
{
for(int i=0; i<p; i++)
{
varindex.lVal = i;
if(pFramesCollection->item(&varindex, &varresult) ==S_OK)
{
lpDispatch=(LPDISPATCH)varresult.ppdispVal;
if (SUCCEEDED(lpDispatch->QueryInterface(IID_IHTMLWindow2,
(LPVOID *)&pHTMLWnd)))
{
if(SUCCEEDED(pHTMLWnd->get_document( &pFrameDoc)))
{
CString info;
info.Format("%d",pFrameDoc);
MessageBox(info);
pFrameDoc->Release();
pFrameDoc=NULL;
}
pHTMLWnd->Release();
pHTMLWnd=NULL;
}
}
}
}
}
}
}
catch(...)
{
};
try
{
if(pDoc != NULL)
pDoc->Release();
if(pFramesCollection != NULL)
pFramesCollection->Release();
}
catch(...)
{
};
}
相关文章推荐
- [VB.NET]VB.NET中如何向网页提交一个请求,并得到返回的HTML代码?
- 如何得到网页中所有内嵌框架的IHTMLDocument2接口
- Helloj2ee学Silverlight之三--SL的程序组成和如何在HTML网页里嵌入SL程序
- UIWebView中运行javascript的方法得到网页的html内容
- HTML中如何利用frame结构写出导航框架
- js如何判断是否在iframe中及防止网页被别站用 iframe嵌套 (Load denied by X-Frame-Options)
- 【HTML】网页中如何让DIV在网页滚动到特定位置时出现
- JN系列(3):如何得到JavaVM,JNIEnv接口
- 【周记】如何将CSS文件引用到html网页里方法
- Powerbuilder编程技巧 如何获取网页的HTML源码
- 如何用photoshop输出html网页
- VR 照片和 VR 电影如何嵌入网页html中(Google VR 框架的使用)
- 如何通过VIM把代码格式化后生成HTML网页代码
- 用javascript实现控制打开网页窗口的大小 和HTML如何关闭窗口的技巧大全
- Android 编程下 WebView 加载一个网页如何得到网页的 Cookie 值
- 如何分析网页数据并且去除Html标签(C#)
- 如何通过JS,在html网页上进行添加元素,包括div 以及下拉框等
- 如何去设计一个自适应的网页设计或HTMl5
- 如何管理HTML网页的内容
- flex 3如何通过iframe嵌入html网页