void IEView::scrollToBottom() { /* IHTMLDocument2 *document = getDocument(); if (document != NULL) { wchar_t *p = NULL; if (SUCCEEDED(document->get_readyState(&p))) { int licznik = 0; do { if (FAILED(document->get_readyState(&p))) { break; } licznik++; if (licznik == 1) break; Sleep(10); } while (!wcscmp(p, L"loading")); } IHTMLWindow2* pWindow = NULL; if (SUCCEEDED(document->get_parentWindow( &pWindow )) && pWindow != NULL) { pWindow->scrollBy( 0, 0x01FFFFFF ); } document->Release(); }*/ IHTMLDocument2 *document = getDocument(); if (document != NULL) { IHTMLElementCollection *collection; IHTMLElement *element; IDispatch *dispatch; if (SUCCEEDED(document->get_all(&collection)) && (collection != NULL)) { long len; if (SUCCEEDED(collection->get_length(&len))) { VARIANT variant; variant.vt = VT_I4; variant.lVal = len-1; if (SUCCEEDED(collection->item(variant, variant, &dispatch)) && (dispatch != NULL)) { if (SUCCEEDED(dispatch->QueryInterface(IID_IHTMLElement,(void**)&element)) && (element != NULL)) { variant.vt = VT_BOOL; variant.boolVal = VARIANT_FALSE; if (SUCCEEDED(element->scrollIntoView(variant))) { } element->Release(); } dispatch->Release(); } } collection->Release(); } IHTMLWindow2* pWindow = NULL; if (SUCCEEDED(document->get_parentWindow( &pWindow )) && (pWindow != NULL)) { pWindow->scrollBy( -0x01FFFFFF, 0x01FFFFFF ); pWindow->Release(); } document->Release(); } }
void IEView::scrollToBottomSoft() { IHTMLDocument2 *document = getDocument(); if (document != NULL) { IHTMLWindow2* pWindow = NULL; if (SUCCEEDED(document->get_parentWindow( &pWindow )) && (pWindow != NULL)) { pWindow->scrollBy( -0x01FFFFFF, 0x01FFFFFF ); pWindow->Release(); } document->Release(); } }
BOOL SimpleBrowser::ExecuteJavascript(LPCTSTR script) { IHTMLDocument2* pDocument = GetDocument(); if (pDocument == NULL) return FALSE; BOOL bRet = FALSE; IHTMLWindow2* pHTMLWindow = NULL; if (pDocument->get_parentWindow(&pHTMLWindow) == S_OK)// execCommand(_T("testFunction()"), TRUE, value, &ret)) { VARIANT vEmpty = {0}; CComBSTR bstrFunction = script; CComBSTR bstrLanguage = L"javascript"; HRESULT hr = pHTMLWindow->execScript(bstrFunction, bstrLanguage, &vEmpty); bRet = (hr == S_OK); pHTMLWindow->Release(); } pDocument->Release(); return bRet; }
//--------------------------------------------------------------------------- void __fastcall TGoogleMapView::ExecFunc(AnsiString func) { IHTMLWindow2 *win; IHTMLDocument2 *doc=NULL; VARIANT var; HRESULT hr; wchar_t func_w[1024]={0}; if (!WebBrowser->Document) return; WebBrowser->Document->QueryInterface(IID_IHTMLDocument2,(void **)&doc); if (!doc) return; hr=doc->get_parentWindow(&win); doc->Release(); if (hr!=S_OK) return; VariantInit(&var); ::MultiByteToWideChar(CP_UTF8,0,func.c_str(),-1,func_w,512); hr=win->execScript(func_w,L"javascript",&var); VariantClear(&var); }
void run( const char *script ){ IDispatch *disp; IHTMLDocument2 *doc; IHTMLWindow2 *win; HRESULT res; VARIANT result; wchar_t *buf; int sz=MultiByteToWideChar( CP_ACP,0,script,-1,0,0 ); buf=new wchar_t[sz]; MultiByteToWideChar( CP_ACP,0,script,-1,buf,sz ); BSTR bstr=SysAllocString(buf); res=iBrowser->get_Document(&disp); if (res==S_OK) { res=disp->QueryInterface(IID_IHTMLDocument2,(void**)&doc); res=doc->get_parentWindow(&win); result.vt=VT_EMPTY; res=win->execScript(bstr,0,&result); } SysFreeString(bstr); delete[] buf; }
STDMETHODIMP CPdnWnd::FireEvent(BSTR handler, VARIANT* parameters, DWORD nParams) { if(!m_pBrowser) return S_FALSE; IHTMLDocument2* pHTDoc; HRESULT hr; hr = m_pBrowser->get_Document((IDispatch**) &pHTDoc); if(SUCCEEDED(hr) && pHTDoc) { IHTMLWindow2* pHTWnd = NULL; hr = pHTDoc->get_parentWindow(&pHTWnd); if(SUCCEEDED(hr)) { UINT errArg; DISPID dispid; hr = pHTWnd->GetIDsOfNames(IID_NULL, &handler, 1, LOCALE_SYSTEM_DEFAULT, &dispid); if(SUCCEEDED(hr)) { DISPPARAMS dParams = { parameters, 0, nParams, 0 }; hr = pHTWnd->Invoke(dispid, IID_NULL, LOCALE_SYSTEM_DEFAULT, DISPATCH_METHOD, &dParams, 0, 0, &errArg); if(SUCCEEDED(hr)) { pHTWnd->Release(); pHTDoc->Release(); return S_OK; } } pHTWnd->Release(); } pHTDoc->Release(); } return hr; }
HRESULT HtmlDlg::OnALinkClickedMethod(IHTMLElement *pElement) { CString attr( _T("href") ); CString href; if( !GetHtmlAttrValue( pElement, attr, href ) ) { MessageBox(_T("href error")); } MessageBox( href ); { //复选框 CComPtr<IHTMLInputElement> CkbOpen; GetElementInterface(_T("vehicle_id"), IID_IHTMLInputElement, (void **) &CkbOpen); if (CkbOpen) { VARIANT_BOOL bc=true; CkbOpen->put_checked(bc); VARIANT_BOOL b; CkbOpen->get_checked(&b); CString csb; int i = b; csb.Format(_T("%d"), i); MessageBox( csb ); } CComPtr<IHTMLElement> spP1; HRESULT hr = S_OK; CString csId = _T("car"); hr = GetElementInterface( csId, &spP1 ); if( S_OK == hr ) { CString csAttr=_T( "value" ); BSTR bStr = csAttr.AllocSysString(); VARIANT v; //spP1->get_innerHTML(&bStr); spP1->getAttribute( bStr,0, &v ); CString csShow( v.bstrVal ); MessageBox( csShow ); //spP1->put_innerHTML(bstrTable); ::VariantClear( &v ); ::SysFreeString( bStr ); } } //call js { CString csFunc = _T("showAlert()"); BSTR bStr = csFunc.AllocSysString(); VARIANT v; v.vt = VT_EMPTY; IHTMLWindow2* pWindow; HRESULT hr = m_spHtmlDoc->get_parentWindow(&pWindow); hr = pWindow->execScript( bStr, L"javascript", &v ); ::VariantClear( &v ); ::SysFreeString( bStr ); } //GotoUrl( _T("http://www.baidu.com/") ); return TRUE; }
std::string ExplorerElement::getComputedStyle(const char* style) { std::string value; // pDoc = element.document IHTMLDocument2 *pDoc = m_pApp->getHTMLDocument2(); if (pDoc != NULL) { IHTMLWindow2 *w = NULL; // w = pDoc.parentWindow HRESULT hr = pDoc->get_parentWindow(&w); if (! FAILED (hr)) { IHTMLWindow7 *w7 = NULL; w->QueryInterface(local_IID_IHTMLWindow7, reinterpret_cast<void**>(&w7)); if (FAILED(hr) || w7 == NULL) { // MZNSendDebugMessageA("Cannot get w7"); } else { IHTMLDOMNode *node; HRESULT hr = m_pElement->QueryInterface(IID_IHTMLDOMNode, reinterpret_cast<void**>(&node)); if (FAILED(hr) || node == NULL) { // MZNSendDebugMessageA("Cannot cast to htmldomnode"); } else { IHTMLCSSStyleDeclaration *pComputedStyle; hr = w7->getComputedStyle(node, NULL, &pComputedStyle); if ( FAILED(hr)) { // MZNSendDebugMessage("Cannot get computedStyle"); } else { BSTR bstr = Utils::str2bstr(style); BSTR bstr2 = NULL; hr = pComputedStyle->getPropertyValue(bstr, &bstr2); if (FAILED(hr)) { // MZNSendDebugMessage("Cannot get property on computedStyle %s", style); } else { Utils::bstr2str(value, bstr2); if (bstr2 != NULL) SysFreeString(bstr2); } SysFreeString(bstr); pComputedStyle -> Release(); } node->Release(); } w7->Release(); } w->Release(); } } return value; }
void ReadiumJSApi::loadJS(QString jScript) { #if 0 QAxObject* doc = WebBrowser->querySubObject("Document()"); //IDispatch* Disp; IDispatch* winDoc = NULL; IHTMLDocument2* document = NULL; //332C4425-26CB-11D0-B483-00C04FD90119 IHTMLDocument2 //25336920-03F9-11CF-8FD0-00AA00686F13 HTMLDocument doc->queryInterface(QUuid("{332C4425-26CB-11D0-B483-00C04FD90119}"), (void**)(&winDoc)); if (winDoc) { document = NULL; winDoc->QueryInterface(IID_IHTMLDocument2, (void**)&document); IHTMLWindow2 *window = NULL; document->get_parentWindow(&window); QAxObject* documentWin = new QAxObject(document, WebBrowser); QAxObject* jScriptWin = new QAxObject(window, WebBrowser); //connect(jScriptWin, SIGNAL(exception(int, QString, QString, QString)), this, SLOT(printWinException(int, QString, QString, QString))); //jScriptInitialized = true; QVariantList params; //params.append(javaScript); //params.append("alert('Hi')"); params.append("JScript"); //QVariant result = jScriptWin->dynamicCall("execScript(QString, QString)", params); VARIANT var; QString strCode = jScript; QString stringLang("JScript"); BSTR bstrCode = SysAllocString(strCode.toStdWString().c_str()); BSTR bstrLang = SysAllocString(stringLang.toStdWString().c_str()); window->execScript(bstrCode, bstrLang, &var); SysFreeString(bstrCode); SysFreeString(bstrLang); document->Release(); winDoc->Release(); } else { //qDebug() << "COULD NOT GET DOCUMENT OBJECT! Aborting"; } #else if (WebBrowser) { CComPtr<IDispatch> pDispDoc = WebBrowser->get_Document(); CComQIPtr<IHTMLDocument2> pHtmlDoc(pDispDoc); if (pHtmlDoc) { CComPtr<IHTMLWindow2> pMainWin2; pHtmlDoc->get_parentWindow(&pMainWin2); if (pMainWin2) { CComVariant vtRv(0); CComBSTR bsCode = jScript.c_str() /*L"alert (\" Hi !\");"*/, bsLang = L"JavaScript"; HRESULT hr = pMainWin2->execScript(bsCode, bsLang, &vtRv); if (!SUCCEEDED(hr)) { //AfxMessageBox(L"Error executing script"); } } } } //QAxObject* qv = WebBrowser->querySubObject("Document()"); //QAxObject* qv1 = qv->querySubObject("parentWindow"); //QString script = "(function(){" + jScript + "})()"; //qDebug() << script; /*{ QString filename = "Data.txt"; QFile file(filename); if (file.open(QIODevice::ReadWrite)) { QTextStream stream(&file); stream << script << endl; } file.close(); }*/ //QVariantList params; //params.append("alert('hello')"); //params.append("JScript"); //QVariant result = qv1->dynamicCall("execScript(QString, QString)", params); //qv1->dynamicCall("execScript(Qstring)", script, "javascript"); //qv1->dynamicCall("execScript(Qstring, QString)", script, "JScript"); //, "javascript" //qv1->deleteLater(); //qv->deleteLater(); //Log.i(TAG, "loadJS: "+jScript); //mJSLoader.loadJS("javascript:(function(){" + jScript + "})()"); //pWebBrowser->dynamicCall(script); #endif }