3,055
社区成员
发帖
与我相关
我的任务
分享
//获取IHTMLDocument2
IHTMLDocument2 *pDoc2;
IHTMLFramesCollection2 *pFc2;
HWND hIE = (HWND)hWnd;
UINT msg = RegisterWindowMessage(TEXT("WM_HTML_GETOBJECT"));
DWORD_PTR Res;
SendMessageTimeout(hIE,msg,NULL,NULL,SMTO_ABORTIFHUNG,1000,&Res);
HRESULT hres = ObjectFromLresult(Res,IID_IHTMLDocument2,NULL,(void **)&pDoc2);
IHTMLElementCollection *pEc;
IHTMLElement *pE;
IDispatch *pDis;
IHTMLTable * pT;
VARIANT varindex,varname;
long len;
BSTR bstr;
VariantInit(&varindex);
VariantInit(&varname);
varindex.vt = VT_I4;
pDoc2->get_all(&pEc); //pDoc2是IHTMLDocument2
pEc->get_length(&len);
for(long i = 0;i < len;++i)
{
varindex.lVal = i;
pEc->item(varname,varindex,&pDis);
pDis->QueryInterface(IID_IHTMLElement,(void **)&pE);
pE->get_innerHTML(&bstr);
pE->Release();
pDis->Release();
}
//long p;
//pEc->get_length(&p);
//pEc->tags(CComVariant("table"),&pDis);
//pDis->QueryInterface(IID_IHTMLTable,(void **)&pT);
//pT->Release();
pEc->Release();
pEc->get_length(&len);
for(long i = 0;i < len;++i)
{
//varindex.lVal = i;
pEc->item(CComVariant(),CComVariant(i),&pDis);
pDis->QueryInterface(IID_IHTMLElement,(void **)&pE);
pE->get_innerHTML(&bstr);
OutputDebugString(bstr);
OutputDebugString(TEXT("\n"));
pE->Release();
pDis->Release();
}