在多Frame的网页中怎么取出各个Frame的IHTMLDocument2的接口!急用.(高分)
我已经取得整个窗口的IHTMLDocument2的接口,但是是多Frame的,不知道怎么取出各个Frame的IHTMLDocument2的接口,请高人指点,一定给高分,急用!! 问题点数:50、回复次数:5Top
1 楼masterz(www.fruitfruit.com)回复于 2002-07-22 22:56:12 得分 40
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();
}Top
2 楼jiangsheng(蒋晟.Net[MVP])回复于 2002-07-23 10:10:31 得分 10
这个随IE版本而异
IE5.0之后,你可以直接查询Frame的IWebbrowser2接口
高版本的IEFrame支持IHtmlFrameBase2接口,可以通过HRESULT IHTMLFrameBase2::get_contentWindow(IHTMLWindow2 **p);访问IHtmlWindow2接口。Top
3 楼jiangsheng(蒋晟.Net[MVP])回复于 2002-07-23 10:24:55 得分 0
这个随IE版本而异
IE5.0之后,你可以直接查询Frame的IWebbrowser2接口
高版本的IEFrame也支持IHtmlFrameBase2接口,可以通过HRESULT IHTMLFrameBase2::get_contentWindow(IHTMLWindow2 **p);访问IHtmlWindow2接口。Top
4 楼jiangsheng(蒋晟.Net[MVP])回复于 2002-07-23 10:39:19 得分 0
这个随IE版本而异
IE5.01之后,你可以直接查询Frame的IWebbrowser2接口
高版本的IEFrame也支持IHtmlFrameBase2接口,可以通过HRESULT IHTMLFrameBase2::get_contentWindow(IHTMLWindow2 **p);访问IHtmlWindow2接口。Top
5 楼ForeverListen(寻求)回复于 2002-07-23 21:13:39 得分 0
很抱歉,今天晚上才看到回帖,让masterz()久等了:)Top
6 楼SmallPigII(小猪II我没有猪的形象,但我有猪的气质)回复于 2002-09-09 19:27:40 得分 0
得到了第一个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);
}Top





