case DISPID_DOCUMENTCOMPLETE: { #pragma region 获取页面总高度 HRESULT hr; IDispatch *pdisp; hr = m_pWebBrowser2->get_Document(&pdisp); if(pdisp == NULL) break; //if NULL, we failed // 获得Html文档指针 IHTMLDocument2 *pDocument = NULL; hr = pdisp->QueryInterface(IID_IHTMLDocument2, (void**)&pDocument); if (pDocument == NULL) break; IHTMLElement *pBody = NULL; hr = pDocument->get_body(&pBody); if (pBody == NULL) break; IHTMLTextContainer *pCont = NULL; pBody->QueryInterface(IID_IHTMLTextContainer, (LPVOID*)(&pCont)); if(pCont == NULL) break; // 获得页面总高度 long scroll_height = -1; if (FAILED(pCont->get_scrollHeight(&scroll_height))) break; pBody->Release(); pCont->Release(); pDocument->Release(); pdisp->Release(); if (scroll_height != -1) m_dwHtmlHeight = scroll_height; if (NULL != m_pManager) m_pManager->SendNotify(this, _T("document_complete"), scroll_height); #pragma endregion }
原文:http://www.cnblogs.com/shengshouzhaixing/p/6549739.html