//------------------------------------------------------------------------------- // Name: HrGetBody // Desc: Получит тело Dockumeta если он создан ... //------------------------------------------------------------------------------- HRESULT COfsDhtmlEditCtrl::HrGetBody(IHTMLBodyElement** ppBody) { HRESULT hr = E_FAIL; IHTMLDocument2* pDoc = NULL; *ppBody = NULL; if (SUCCEEDED(HrGetDoc(&pDoc))) { IHTMLElement* pElement = NULL; hr = pDoc->get_body(&pElement); if (SUCCEEDED(hr)) { IHTMLBodyElement* pBody = NULL; hr = pElement->QueryInterface(IID_IHTMLBodyElement, (void **) &pBody); if (SUCCEEDED(hr)) { *ppBody = pBody; // don't release body - we are returning it } pElement->Release(); } pDoc->Release(); } return hr; }
//----------------------------------------------------------------------------- // Name: AddHtmlContentToBody // Object: // Parameters : // in : // out : // return : //----------------------------------------------------------------------------- BOOL CHtmlViewer::AddHtmlContentToBody(TCHAR* Content) { HRESULT hr; BOOL bRet; IDispatch* pHtmlDocDispatch = NULL; IHTMLDocument2* pHtmlDoc = NULL; IHTMLElement* pElem = NULL; if (this->pIWebBrowser==NULL) return FALSE; if (!this->IsPageCompleted()) return FALSE; // get IDispatch document interface hr = pIWebBrowser->get_Document(&pHtmlDocDispatch); if (FAILED (hr) || (pHtmlDocDispatch == NULL)) return FALSE; // get IHTMLDocument2 document interface hr = pHtmlDocDispatch->QueryInterface(IID_IHTMLDocument2,(void**)&pHtmlDoc); if (FAILED (hr) || (pHtmlDoc == NULL)) { pHtmlDocDispatch->Release(); return FALSE; } // get body hr = pHtmlDoc->get_body(&pElem); if (FAILED (hr) || (pElem == NULL)) { pHtmlDoc->Release(); pHtmlDocDispatch->Release(); return FALSE; } bRet=this->AddHtmlContentToElement(pElem,Content); pElem->Release(); pHtmlDoc->Release(); pHtmlDocDispatch->Release(); return bRet; }
void CShellDlg::DocumentCompleteExplorer2(LPDISPATCH pDisp3, VARIANT* URL) { HRESULT hr; // IDispatch *pDisp2 = m_webHead .get_Document (); IHTMLDocument2 *pDocument = NULL; IHTMLElement* pEl; IHTMLBodyElement * pBodyEl; // hr = pDisp2->QueryInterface(IID_IHTMLDocument2, (void**)&pDocument); if(SUCCEEDED(pDocument->get_body(&pEl))) { if(SUCCEEDED(pEl->QueryInterface(IID_IHTMLBodyElement, (void**)&pBodyEl))) { pBodyEl->put_scroll(L"no");//去滚动条 } IHTMLStyle *phtmlStyle; pEl->get_style(&phtmlStyle); } }
HRESULT TestDocumentText(IHTMLDocument3 *pHtmlDoc, BSTR &message) { IHTMLDocument2 *pDoc = NULL; IHTMLElement *pElem = NULL; BSTR bstrId = SysAllocString(L"test"); HRESULT hr = pHtmlDoc->QueryInterface(IID_PPV_ARGS(&pDoc)); if (SUCCEEDED(hr) && pDoc) { hr = pDoc->get_body(&pElem); if (SUCCEEDED(hr) && pElem) { BSTR bstrText = NULL; pElem->get_innerText(&bstrText); message = SysAllocString(bstrText); SysFreeString(bstrText); pElem->Release(); } pDoc->Release(); } SysFreeString(bstrId); return hr; }
//this function looks at the element's coordinates and the coordinates of the section of the //document which is being displayed, and decides if the element is visible or not bool TextRenderBrain::isElementInView(IHTMLElement* pElm) { if (pElm == NULL) return false; amis::util::Log::Instance()->writeTrace("Testing to see if the element is in view", "TextRenderBrain::isElementInView"); //the IHTMLELEMENT measurements long elm_width = 0; long elm_height = 0; long elm_top = 0; long elm_left = 0; //if any measurements go wrong, return false if (pElm->get_offsetWidth(&elm_width) != S_OK) return false; if (pElm->get_offsetHeight(&elm_height) != S_OK) return false; if (pElm->get_offsetTop(&elm_top) != S_OK) return false; if (pElm->get_offsetLeft(&elm_left) != S_OK) return false; HRESULT hr; // get the document dispatch from browser IDispatch *pDisp = MainWndParts::Instance()->mpHtmlView->GetHtmlDocument(); ASSERT( pDisp ); //if NULL, we failed IHTMLDocument2 *pDocument = NULL; hr = pDisp->QueryInterface( IID_IHTMLDocument2, (void**)&pDocument ); ASSERT( SUCCEEDED( hr ) ); ASSERT( pDocument ); IHTMLElement *pBody = NULL; hr = pDocument->get_body( &pBody ); ASSERT( SUCCEEDED( hr ) ); ASSERT( pBody ); // Attempt by Jack, following // <http://groups.google.com/group/microsoft.public.inetsdk.programming.webbrowser_ctl/browse_frm/thread/fa3452e1bbb6bcf5> // Depending on whether the HTML document has a doctype the scroll position can be stored // in one of two locations, we add the two to get what we want. IHTMLDocument3 *pDoc3 = NULL; IHTMLElement *pElem = NULL; IHTMLElement2 *pElem2 = NULL; hr = pDocument->QueryInterface(IID_IHTMLDocument3,(void**)&pDoc3); if (SUCCEEDED(hr)) { hr = pDoc3->get_documentElement(&pElem); if (SUCCEEDED(hr)) { hr = pElem->QueryInterface(IID_IHTMLElement2, (void**)&pElem2); } } IHTMLTextContainer *pContainer = NULL; hr = pBody->QueryInterface(IID_IHTMLTextContainer,(void**)&pContainer); ASSERT(SUCCEEDED(hr)); ASSERT( pContainer ); CPoint scroll_pos, scroll_pos2; pContainer->get_scrollTop(&scroll_pos.y); pContainer->get_scrollLeft(&scroll_pos.x); if (pElem2) { pElem2->get_scrollTop(&scroll_pos2.y); pElem2->get_scrollLeft(&scroll_pos2.x); scroll_pos.y += scroll_pos2.y; scroll_pos.x += scroll_pos2.x; } if (pElem2) pElem2->Release(); if (pElem) pElem->Release(); if (pDoc3) pDoc3->Release(); pContainer->Release(); pBody->Release(); pDocument->Release(); pDisp->Release(); //get the html view's width and height long view_width = 0; long view_height = 0; view_width = MainWndParts::Instance()->mpHtmlView->GetWidth(); view_height = MainWndParts::Instance()->mpHtmlView->GetHeight(); int top_visible = scroll_pos.y; int bottom_visible = scroll_pos.y + view_height; int left_visible = scroll_pos.x; int right_visible = scroll_pos.x + view_width; int elm_bottom = elm_top + elm_height; int elm_right = elm_left + elm_width; /* CString element_data; element_data.Format(_T("*****\nElement \ttop = %d \tbottom = %d \tleft = %d \tright = %d \n****\n"), elm_top, elm_bottom, elm_left, elm_right); CString screen_data; screen_data.Format(_T("******\nScreen \ttop = %d \tbottom = %d \tleft = %d \tright = %d \n****\n"), top_visible, bottom_visible, left_visible, right_visible); TRACE(L"%s", screen_data); TRACE(L"%s", element_data); */ if (elm_top < top_visible || elm_bottom > bottom_visible) return false; if (elm_left < left_visible || elm_right > right_visible) return false; //otherwise we assume it's in view return true; }