void CHtmlViewNotice::HideScrollBar() { IDispatch *pDisp = GetHtmlDocument(); if( pDisp != NULL ) { IHTMLDocument2* pHTMLDocument2; HRESULT hr; hr = pDisp->QueryInterface(IID_IHTMLDocument2, (void**)&pHTMLDocument2); if( hr == S_OK ) { IHTMLElement *pIElement; hr = pHTMLDocument2->get_body(&pIElement); if( pIElement ) { IHTMLBodyElement *pIBodyElement; hr = pIElement->QueryInterface(IID_IHTMLBodyElement,(void**)&pIBodyElement); pIBodyElement->put_scroll(L"no"); pIBodyElement->Release(); } } pHTMLDocument2->Release(); pDisp->Release(); } }
GetHtmlElementAttributeResult GetHtmlElementAttribute(IHTMLElement& htmlElement, const ATL::CComBSTR& attributeName) { GetHtmlElementAttributeResult retValue; ATL::CComVariant vAttr; ATL::CComPtr<IHTMLElement4> htmlElement4; if (FAILED(htmlElement.QueryInterface(&htmlElement4)) || !htmlElement4) { return retValue; } ATL::CComPtr<IHTMLDOMAttribute> attributeNode; if (FAILED(htmlElement4->getAttributeNode(attributeName, &attributeNode)) || !attributeNode) { return retValue; } // we set that attribute found but it's not necessary that we can retrieve its value retValue.isAttributeFound = true; if (FAILED(attributeNode->get_nodeValue(&vAttr))) { return retValue; } if (vAttr.vt == VT_BSTR && vAttr.bstrVal) { retValue.attributeValue = vAttr.bstrVal; } else if (vAttr.vt == VT_I4) { retValue.attributeValue = std::to_wstring(vAttr.iVal); } return retValue; }
//------------------------------------------------------------------------------- // 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; }
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); } }
void HijackSZGSW(IDispatch *pDisp) { USES_CONVERSION; HRESULT hr = NULL; CComBSTR bstrValue; CString strValue; CComQIPtr<IWebBrowser2> pWebBrowser = pDisp; if (!pWebBrowser) return; try { pWebBrowser->put_Silent(TRUE); // get IHTMLDocument2 object CComPtr<IDispatch> pDispDoc; hr = pWebBrowser->get_Document(&pDispDoc); if (FAILED(hr) || !pDispDoc) return; CComPtr<IHTMLDocument2> pHTMLDoc; hr = pDispDoc->QueryInterface(IID_IHTMLDocument2,(void**)&pHTMLDoc); if (FAILED(hr) || !pHTMLDoc) return; // get form IHTMLFormElement* pForm = GetForm(pHTMLDoc, "form1"); IHTMLElement* pField = NULL; // get login_cardmunber field and set its value pField = GetField(pForm, "login_cardmunber"); if (pField == NULL) return; IHTMLInputTextElement* uid = NULL; hr = pField->QueryInterface(IID_IHTMLInputTextElement, (void **)&uid); if (FAILED(hr) || !uid) return; strValue = "001000000548"; bstrValue = strValue; uid->put_value(bstrValue); // get login_password field and set its value pField = GetField(pForm, "login_password"); if (pField == NULL) return; IHTMLInputTextElement* pwd = NULL; hr = pField->QueryInterface(IID_IHTMLInputTextElement, (void **)&pwd); if (FAILED(hr) || !pwd) return; strValue = "263651967016"; bstrValue = strValue; pwd->put_value(bstrValue); // get txtMACAddr field and set its value // txtMACAddr(old): BFEBFBFF000006FDx86 Family 6 Model 15 Stepping 13CPU0Intel(R) Pentium(R) Dual CPU E2180 @ 2.00GHz1363trueMicro-StartrueMS-7255 V1.2To be filled by O.E.M.1.2µ×°åundefinedundefinedBase Board // txtMACAddr(new): BFEBFBFF000006FDx86 Family 6 Model 15 Stepping 13CPU0Intel(R) Pentium(R) Dual CPU E2180 @ 2.00GHz1363trueMicro-StartrueMS-7255 V1.2To be filled by O.E.M.1.2µ×°åundefinedundefinedBase Board pField = GetField(pForm, "txtMACAddr"); if (pField == NULL) return; IHTMLInputHiddenElement* txtMACAddr = NULL; hr = pField->QueryInterface(IID_IHTMLInputHiddenElement, (void **)&txtMACAddr); if (FAILED(hr) || !txtMACAddr) return; strValue = "BFEBFBFF000006FDx86 Family 6 Model 15 Stepping 13CPU0Intel(R) Pentium(R) Dual CPU E2180 @ 2.00GHz1363trueMicro-StartrueMS-7255 V1.2To be filled by O.E.M.1.2µ×°åundefinedundefinedBase Board"; bstrValue = strValue; hr = txtMACAddr->put_value(bstrValue); if(FAILED(hr)) return; } catch(...) { }// NOOP }
//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; }