在多Frame的网页中怎么取出各个Frame的IHTMLDocument2的接口!急用.(高分)

ForeverListen 2002-07-22 08:52:10
加精
我已经取得整个窗口的IHTMLDocument2的接口,但是是多Frame的,不知道怎么取出各个Frame的IHTMLDocument2的接口,请高人指点,一定给高分,急用!!
...全文
368 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
SmallPigII 2002-09-09
  • 打赏
  • 举报
回复
得到了第一个frame:
CComPtr<IDispatch> pDisp;
HRESULT hr;
CComPtr<IHTMLFrameBase> pHtmlFrameBase;
CComPtr<IHTMLWindow2> pWindow2 = NULL;
CComPtr<IHTMLWindow2> pFrameWindow2 = NULL;
CComPtr<IHTMLDocument2> pFrameDoc = NULL;
CComPtr<IHTMLFramesCollection2> pFrameColl = NULL;

pHtmlDoc2 = (IHTMLDocument2 *)m_web.GetDocument();

if (pHtmlDoc2)
{
hr = pHtmlDoc2->get_parentWindow(&pWindow2);
ASSERT(!FAILED(hr) && pWindow2);

hr = pWindow2->get_frames(&pFrameColl);
ASSERT(!FAILED(hr) && pFrameColl);

COleVariant index, frame;
index.vt = VT_UINT;
index.iVal = 0;

hr = pFrameColl->item(&index, &frame);
ASSERT(!FAILED(hr));

hr = frame.pdispVal->QueryInterface(IID_IHTMLWindow2, (void **)&pFrameWindow2);
ASSERT(!FAILED(hr) && pFrameWindow2);

hr = pFrameWindow2->get_document(&pFrameDoc);
ASSERT(!FAILED(hr) && pFrameDoc);

hr = pFrameDoc->get_all(&pHtmlEleCol);
ASSERT(!FAILED(hr) && pHtmlEleCol);
}
蒋晟 2002-07-23
  • 打赏
  • 举报
回复
这个随IE版本而异
IE5.01之后,你可以直接查询Frame的IWebbrowser2接口
高版本的IEFrame也支持IHtmlFrameBase2接口,可以通过HRESULT IHTMLFrameBase2::get_contentWindow(IHTMLWindow2 **p);访问IHtmlWindow2接口。
蒋晟 2002-07-23
  • 打赏
  • 举报
回复
这个随IE版本而异
IE5.0之后,你可以直接查询Frame的IWebbrowser2接口
高版本的IEFrame也支持IHtmlFrameBase2接口,可以通过HRESULT IHTMLFrameBase2::get_contentWindow(IHTMLWindow2 **p);访问IHtmlWindow2接口。
蒋晟 2002-07-23
  • 打赏
  • 举报
回复
这个随IE版本而异
IE5.0之后,你可以直接查询Frame的IWebbrowser2接口
高版本的IEFrame支持IHtmlFrameBase2接口,可以通过HRESULT IHTMLFrameBase2::get_contentWindow(IHTMLWindow2 **p);访问IHtmlWindow2接口。
ForeverListen 2002-07-23
  • 打赏
  • 举报
回复
很抱歉,今天晚上才看到回帖,让masterz()久等了:)
masterz 2002-07-22
  • 打赏
  • 举报
回复
IHTMLDocument2 * pDoc = ...;
IHTMLWindow2 *pHTMLWnd = NULL;
IHTMLDocument2 * pFrameDoc=NULL;
IHTMLFramesCollection2 *pFramesCollection=NULL;
LPDISPATCH lpDispatch;

long p;
VARIANT varindex,varresult;
varresult.vt=VT_DISPATCH;
varindex.vt = VT_I4;
if(pDoc!=NULL)
{
HRESULT hr=pDoc->get_frames(&pFramesCollection);
if(SUCCEEDED(hr)&&pFramesCollection!=NULL)
{
hr=pFramesCollection->get_length(&p);
if(SUCCEEDED(hr))
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)))
{
//work with the pFrameDoc...
}
pHTMLWnd->Release();
pHTMLWnd=NULL;
}
}
}
pFramesCollection->Release();
}
pDoc->Release();
}

3,055

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC HTML/XML
社区管理员
  • HTML/XML社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧