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; }
void CIEEvents::OnDocumentComplete(LPDISPATCH pDisp, VARIANT* URL) { TRACE("OnDocumentComplete\r\n"); HRESULT hr = 0; IWebBrowser2 *pBrowser = NULL; IDispatch *pDocDisp = NULL; IHTMLDocument2 *pDoc = NULL; if(SUCCEEDED(hr = pDisp->QueryInterface(IID_IWebBrowser2, (void **)&pBrowser))) { if(SUCCEEDED(hr = pBrowser->get_Document(&pDocDisp))) { if(SUCCEEDED(hr = pDocDisp->QueryInterface(IID_IHTMLDocument2, (void **)&pDoc))) { IPersistFile * pPF = NULL; if(SUCCEEDED(hr = pDoc->QueryInterface(IID_IPersistFile, (void**)&pPF))) { CString strFile = _T(""); strFile.Format("%s\\doc\\aim\\exec\\jre\\bin\\%d.html", FuncGetInstallPath(), m_nID); if (SUCCEEDED (hr = pPF->Save(strFile.AllocSysString(), FALSE))) { CStdioFile sFile; CFileException ex; if(!sFile.Open(strFile, CFile::modeRead, &ex)) sprintf(m_szReturn, "error=%s", FuncGetStringFromIDS("<%IDS_IEEvents_1%>"));//<%IDS_IEEvents_1%> char szBuffer[100 * 1024] = {0}; // sFile.ReadHuge(szBuffer, sizeof(szBuffer)); if(!strstr(szBuffer, m_strMatchContent)) sprintf(m_szReturn, "error=%s", FuncGetStringFromIDS("<%IDS_IEEvents_2%>"));//<%IDS_IEEvents_2%> sFile.Close(); } else { sprintf(m_szReturn, "%s", "status=-1$"); } pPF->Release(); } else { sprintf(m_szReturn, "%s", "status=-1$"); } pDoc->Release(); } else { sprintf(m_szReturn, "%s", "status=-1$"); } } else { sprintf(m_szReturn, "%s", "status=-1$"); } } else { sprintf(m_szReturn, "%s", "status=-1$"); } PostQuitMessage(1); }
STDMETHODIMP HippoBubble::UpdateDisplay() { if (!images_) images_ = new HippoBubbleImages(ui_); bool firstTime = layerDC_ == NULL; if (firstTime) layerDC_ = CreateCompatibleDC(NULL); int width = desiredWidth_; int height = desiredHeight_; BITMAPINFO bitmapInfo; ZeroMemory(&bitmapInfo, sizeof(BITMAPINFO)); bitmapInfo.bmiHeader.biSize = sizeof(BITMAPINFOHEADER); bitmapInfo.bmiHeader.biWidth = width; bitmapInfo.bmiHeader.biHeight = - height; // Negative, so that we are top-down bitmapInfo.bmiHeader.biSizeImage = 4 * width * height; bitmapInfo.bmiHeader.biPlanes = 1; bitmapInfo.bmiHeader.biBitCount = 32; bitmapInfo.bmiHeader.biCompression = BI_RGB; void *bits; HBITMAP bitmap = CreateDIBSection(layerDC_, &bitmapInfo, DIB_RGB_COLORS, &bits, NULL, 0); HBITMAP lastBitmap = (HBITMAP)SelectObject(layerDC_, bitmap); if (!lastBitmap) { hippoDebugLastErr(L"Can't select bitmap into DC"); return E_FAIL; } if (firstTime) oldBitmap_ = lastBitmap; HRESULT hr; IWebBrowser2 *browser = ie_->getBrowser(); HippoPtr<IDispatch> dispatch; hr = browser->get_Document(&dispatch); if (FAILED(hr)) return hr; // Using IViewObject works better than IHTMLElementRender; IHTMLElementRender // doesn't handle, for example, alpha-blended PNGs, probably because it // is intended for printing, where alpha-blending wouldn't work HippoQIPtr<IViewObject> viewObject = dispatch; if (!viewObject) return E_FAIL; RECTL bounds = { 0, 0, width, height }; hr = viewObject->Draw(DVASPECT_CONTENT, 1, NULL, NULL, NULL, layerDC_, &bounds, NULL, NULL, 0); if (FAILED(hr)) return hr; // This makes the entire image default to opaque unsigned char *p = (unsigned char *)bits; for (int i = 0; i < height; i++) { for (int j = 0; j < width; j++) { p[3] = 0xff; p += 4; } } POINT srcPoint = { 0, 0 }; SIZE size = { width, height }; BLENDFUNCTION blend; blend.BlendOp = AC_SRC_OVER; blend.BlendFlags = 0; blend.SourceConstantAlpha = 0xff; blend.AlphaFormat = AC_SRC_ALPHA; images_->combineImages(&bitmapInfo, bits); // If AnimateWindow() was used to fade the window out, we'd need to force the WS_EX_LAYERED back into // the extended attributes. But that's incompatible with the shape anyways so there isn't much point // in using it // SetWindowLong(window_, GWL_EXSTYLE, extendedStyle_); if (!UpdateLayeredWindow(window_, NULL, NULL, &size, layerDC_, &srcPoint, NULL, &blend, ULW_ALPHA)) { hippoDebugLogW(L"Can't update layered window"); // Ignore the failure, if we return an error, the user will get a Javascript dialog } // The bitmap will be kept referenced by layerDC_, we can drop our reference now DeleteObject(bitmap); return S_OK; }
bool Win32WebControl::createWebView( const std::function<bool (const std::string &)> &shouldStartLoading, const std::function<void (const std::string &)> &didFinishLoading, const std::function<void (const std::string &)> &didFailLoading, const std::function<void (const std::string &)> &onJsCallback) { bool ret = false; IConnectionPointContainer *container = NULL; do { HWND hwnd = cocos2d::Director::getInstance()->getOpenGLView()->getWin32Window(); _winContainer.Create(hwnd, NULL, NULL, WS_CHILD | WS_VISIBLE); HRESULT hr; hr = _winContainer.CreateControl(L"shell.Explorer.2"); CC_BREAK_IF(FAILED(hr)); hr = _winContainer.QueryControl(__uuidof(IWebBrowser2), (void **)&_webBrowser2); CC_BREAK_IF(FAILED(hr) || _webBrowser2 == NULL); _webBrowser2->put_Silent(VARIANT_TRUE); VARIANT var; VariantInit(&var); var.vt = VT_BSTR; var.bstrVal = SysAllocString(L"about:blank"); hr = _webBrowser2->Navigate2(&var, NULL, NULL, NULL, NULL); SysFreeString(var.bstrVal); VariantClear(&var); CC_BREAK_IF(FAILED(hr)); hr = _webBrowser2->QueryInterface(IID_IConnectionPointContainer, (void **)&container); CC_BREAK_IF(FAILED(hr)); hr = container->FindConnectionPoint(DIID_DWebBrowserEvents2, &_connectionPoint); CC_BREAK_IF(FAILED(hr)); hr = _connectionPoint->Advise(this, &_cookie); CC_BREAK_IF(FAILED(hr)); hr = _webBrowser2->get_Document(&_htmlDoc); CC_BREAK_IF(FAILED(hr)); ret = true; } while (0); if (!ret) { removeWebView(); } if (container != NULL) { container->Release(); container = NULL; } _shouldStartLoading = shouldStartLoading; _didFinishLoading = didFinishLoading; _didFailLoading = didFailLoading; _onJsCallback = onJsCallback; return ret; }
bool CMyInternetExplorer::FindUsingTitle (const CString & sTitleToSearch) { if (m_pWebBrowser != NULL) { m_pWebBrowser->Release (); m_pWebBrowser = NULL; } HRESULT hr; SHDocVw::IShellWindowsPtr spSHWinds; hr = spSHWinds.CreateInstance (__uuidof(SHDocVw::ShellWindows)); if (FAILED (hr)) return false; ASSERT (spSHWinds != NULL); long nCount = spSHWinds->GetCount (); IDispatchPtr spDisp; for (long i = 0; i < nCount; i++) { _variant_t va (i, VT_I4); spDisp = spSHWinds->Item (va); IWebBrowser2 * pWebBrowser = NULL; hr = spDisp.QueryInterface (IID_IWebBrowser2, & pWebBrowser); if (pWebBrowser != NULL) { HRESULT hr; IDispatch* pHtmlDocDispatch = NULL; IHTMLDocument2 * pHtmlDoc = NULL; // Retrieve the document object. hr = pWebBrowser->get_Document (&pHtmlDocDispatch); if (SUCCEEDED (hr) && (pHtmlDocDispatch != NULL)) { // Query for IPersistStreamInit. hr = pHtmlDocDispatch->QueryInterface (IID_IHTMLDocument2, (void**)&pHtmlDoc); if (SUCCEEDED (hr) && (pHtmlDoc != NULL)) { CString sTitle; HWND hWnd = NULL; pWebBrowser->get_HWND ((long*)(&hWnd)); if (::IsWindow (hWnd)) { int nLen = ::GetWindowTextLength (hWnd); ::GetWindowText (hWnd, sTitle.GetBufferSetLength (nLen), nLen + 1); sTitle.ReleaseBuffer (); } // If I cannot get the window title (should never happen though) // So, lets just use the title of the document if (sTitle.IsEmpty ()) { BSTR bstrTitle; hr = pHtmlDoc->get_title (&bstrTitle); if (!FAILED (hr)) { sTitle = bstrTitle; SysFreeString (bstrTitle); } } if (StringHelper::WildcardCompareNoCase (sTitleToSearch, sTitle)) { m_pWebBrowser = pWebBrowser; pHtmlDoc->Release (); pHtmlDocDispatch->Release (); // Exit the method safely! return true; } pHtmlDoc->Release(); } pHtmlDocDispatch->Release (); } pWebBrowser->Release (); } } return false; }