How to get all the frames of a web page(CHtmlView)?
-
I tried as bellow,but I think it doesn't work correctly. Who knows how?? Thank you very much. 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; iitem(&varindex, &varresult) ==S_OK) { lpDispatch=(LPDISPATCH)varresult.ppdispVal; if (SUCCEEDED(lpDispatch->QueryInterface(IID_IHTMLWindow2, (LPVOID *)&pHTMLWnd))) { if(SUCCEEDED(pHTMLWnd->get_document( &pFrameDoc))) { BSTR bstr=NULL; HRESULT hr=pFrameDoc->get_URL(&bstr); ASSERT(SUCCEEDED(hr)); CString str= bstr; SysFreeString(bstr); pFrameDoc->Release(); pFrameDoc=NULL; } pHTMLWnd->Release(); pHTMLWnd=NULL; } } } } } } } catch(...) { }; try { if(pDoc != NULL) pDoc->Release(); if(pFramesCollection != NULL) pFramesCollection->Release(); } catch(...) { };
-
I tried as bellow,but I think it doesn't work correctly. Who knows how?? Thank you very much. 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; iitem(&varindex, &varresult) ==S_OK) { lpDispatch=(LPDISPATCH)varresult.ppdispVal; if (SUCCEEDED(lpDispatch->QueryInterface(IID_IHTMLWindow2, (LPVOID *)&pHTMLWnd))) { if(SUCCEEDED(pHTMLWnd->get_document( &pFrameDoc))) { BSTR bstr=NULL; HRESULT hr=pFrameDoc->get_URL(&bstr); ASSERT(SUCCEEDED(hr)); CString str= bstr; SysFreeString(bstr); pFrameDoc->Release(); pFrameDoc=NULL; } pHTMLWnd->Release(); pHTMLWnd=NULL; } } } } } } } catch(...) { }; try { if(pDoc != NULL) pDoc->Release(); if(pFramesCollection != NULL) pFramesCollection->Release(); } catch(...) { };
Code above doesn't look well . I paste it again . 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; iitem(&varindex, &varresult) ==S_OK) { lpDispatch=(LPDISPATCH)varresult.ppdispVal; if (SUCCEEDED(lpDispatch->QueryInterface(IID_IHTMLWindow2, (LPVOID *)&pHTMLWnd))) { if(SUCCEEDED(pHTMLWnd->get_document( &pFrameDoc))) { BSTR bstr=NULL; HRESULT hr=pFrameDoc->get_URL(&bstr); ASSERT(SUCCEEDED(hr)); CString str= bstr; SysFreeString(bstr); pFrameDoc->Release(); pFrameDoc=NULL; } pHTMLWnd->Release(); pHTMLWnd=NULL; } } } } } } } catch(...) { }; try { if(pDoc != NULL) pDoc->Release(); if(pFramesCollection != NULL) pFramesCollection->Release(); } catch(...) { };
-
Code above doesn't look well . I paste it again . 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; iitem(&varindex, &varresult) ==S_OK) { lpDispatch=(LPDISPATCH)varresult.ppdispVal; if (SUCCEEDED(lpDispatch->QueryInterface(IID_IHTMLWindow2, (LPVOID *)&pHTMLWnd))) { if(SUCCEEDED(pHTMLWnd->get_document( &pFrameDoc))) { BSTR bstr=NULL; HRESULT hr=pFrameDoc->get_URL(&bstr); ASSERT(SUCCEEDED(hr)); CString str= bstr; SysFreeString(bstr); pFrameDoc->Release(); pFrameDoc=NULL; } pHTMLWnd->Release(); pHTMLWnd=NULL; } } } } } } } catch(...) { }; try { if(pDoc != NULL) pDoc->Release(); if(pFramesCollection != NULL) pFramesCollection->Release(); } catch(...) { };
-
-
I tried as bellow,but I think it doesn't work correctly. Who knows how?? Thank you very much. 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; iitem(&varindex, &varresult) ==S_OK) { lpDispatch=(LPDISPATCH)varresult.ppdispVal; if (SUCCEEDED(lpDispatch->QueryInterface(IID_IHTMLWindow2, (LPVOID *)&pHTMLWnd))) { if(SUCCEEDED(pHTMLWnd->get_document( &pFrameDoc))) { BSTR bstr=NULL; HRESULT hr=pFrameDoc->get_URL(&bstr); ASSERT(SUCCEEDED(hr)); CString str= bstr; SysFreeString(bstr); pFrameDoc->Release(); pFrameDoc=NULL; } pHTMLWnd->Release(); pHTMLWnd=NULL; } } } } } } } catch(...) { }; try { if(pDoc != NULL) pDoc->Release(); if(pFramesCollection != NULL) pFramesCollection->Release(); } catch(...) { };
I am still using this 2024. Your example is useful and helped me through the jungle. i is an integer not a string. varindex.lval = i; Than things are working, already. Maybe someone else can use.