如何得到网页中的Frame的HTML接口

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,框架,iframe,null,文档)