C
cyberwalker
Unregistered / Unconfirmed
GUEST, unregistred user!
如果没有框架(frame),网页的doc:IHtmlDocumet2很容易获得,但是如果有框架,只能得到主框架的doc,问大虾能否遍历所有的框架中的doc
// 有一个VC例子,供参考
//find doc in all frames
int MyApp:oWorkOnFrames(IHTMLDocument2 *pDoc)
{
int hr;
IHTMLWindow2* pWindow2 = NULL;
IHTMLWindow2* pFrameWindow2 = NULL;
IHTMLDocument2* pFrameDoc = NULL;
IHTMLFramesCollection2* pFrameColl = NULL;
long cFrames;
hr = pDoc->get_parentWindow(&pWindow2);
ASSERT(SUCCEEDED(hr) && pWindow2);
pWindow2->get_frames(&pFrameColl);
if (SUCCEEDED(hr = pFrameColl->get_length( &cFrames )))
{
for ( int i=0; i < cFrames ; i++ )
{
VARIANT vIndex;
vIndex.vt = VT_UINT;
vIndex.lVal = i;
VARIANT var2 = { 0 };
LPDISPATCH pDisp;
VARIANT frame;
if (SUCCEEDED(hr = pFrameColl->item( &vIndex, &frame ))){
hr = frame.pdispVal->QueryInterface(IID_IHTMLWindow2, (void**)&pFrameWindow2);
hr = pFrameWindow2->get_document(&pFrameDoc);
DoWorkOnDoc(pFrameDoc);
DoWorkOnFrames(pFrameDoc);
}
}
}
}
//请大虾看看上面的程序,把它翻译成Delphi
// 有一个VC例子,供参考
//find doc in all frames
int MyApp:oWorkOnFrames(IHTMLDocument2 *pDoc)
{
int hr;
IHTMLWindow2* pWindow2 = NULL;
IHTMLWindow2* pFrameWindow2 = NULL;
IHTMLDocument2* pFrameDoc = NULL;
IHTMLFramesCollection2* pFrameColl = NULL;
long cFrames;
hr = pDoc->get_parentWindow(&pWindow2);
ASSERT(SUCCEEDED(hr) && pWindow2);
pWindow2->get_frames(&pFrameColl);
if (SUCCEEDED(hr = pFrameColl->get_length( &cFrames )))
{
for ( int i=0; i < cFrames ; i++ )
{
VARIANT vIndex;
vIndex.vt = VT_UINT;
vIndex.lVal = i;
VARIANT var2 = { 0 };
LPDISPATCH pDisp;
VARIANT frame;
if (SUCCEEDED(hr = pFrameColl->item( &vIndex, &frame ))){
hr = frame.pdispVal->QueryInterface(IID_IHTMLWindow2, (void**)&pFrameWindow2);
hr = pFrameWindow2->get_document(&pFrameDoc);
DoWorkOnDoc(pFrameDoc);
DoWorkOnFrames(pFrameDoc);
}
}
}
}
//请大虾看看上面的程序,把它翻译成Delphi