HRESULT WebBrowserEventSinker::SetCustomDocUIHandler(LPDISPATCH lpDisp) { if(lpDisp == NULL) return E_INVALIDARG; IWebBrowser2Ptr pWebBrowser2; HRESULT hr = lpDisp->QueryInterface(IID_IWebBrowser2, (void**)&pWebBrowser2); if(SUCCEEDED(hr) && pWebBrowser2) { IDispatchPtr pDoc; hr = pWebBrowser2->get_Document(&pDoc); if(SUCCEEDED(hr) && pDoc) { ICustomDocPtr pCustDoc; hr = pDoc->QueryInterface(IID_ICustomDoc, (void**)&pCustDoc); if(SUCCEEDED(hr) && pCustDoc != NULL) { IDocHostUIHandler* pUIHandler; CreateObjectInterface<CDocHostUIHandler, IDocHostUIHandler>(NULL, &pUIHandler); if (pUIHandler) pCustDoc->SetUIHandler(pUIHandler); pUIHandler->Release(); } } } return hr; }
void vmsWebBrowserEvents::OnDocumentComplete(LPDISPATCH pdWB, VARIANT *URL) { if (m_spUIHandler != NULL) { IWebBrowser2Ptr spWB (pdWB); if (spWB == NULL) return; IDispatchPtr spdDoc; spWB->get_Document (&spdDoc); IHTMLDocumentPtr spDoc (spdDoc); if (spDoc == NULL) return; ICustomDocPtr spCD (spDoc); if (spCD != NULL) spCD->SetUIHandler (m_spUIHandler); } }
void CDownloads_Opinions_WBEvents::OnDocumentComplete(LPDISPATCH pdWB, VARIANT *URL) { IWebBrowser2Ptr spWB (pdWB); if (spWB == NULL) return; IDispatchPtr spdDoc; spWB->get_Document (&spdDoc); IHTMLDocumentPtr spDoc (spdDoc); if (spDoc == NULL) return; ICustomDocPtr spCD (spDoc); if (spCD != NULL) spCD->SetUIHandler (&m_wbUIHandler); bool bSetTab = false; if (m_pwndOpinions->m_cSetAsCurrentTabAfterLoadComplete) { InterlockedDecrement (&m_pwndOpinions->m_cSetAsCurrentTabAfterLoadComplete); bSetTab = true; } if (m_pwndOpinions->m_dld == NULL) return; if (bSetTab) _pwndDownloads->m_wndDownloads.m_info.set_CurTab (DIT_OPINIONS); IDispatch *pdScript; spDoc->get_Script (&pdScript); if (pdScript == NULL) return; DISPID didFun; OLECHAR* pwszFunName = L"processform"; HRESULT hr; hr = pdScript->GetIDsOfNames (IID_NULL, &pwszFunName, 1, LOCALE_SYSTEM_DEFAULT, &didFun); if (FAILED (hr)) return; COleVariant vtResult; BYTE params [] = {VTS_BSTR VTS_BSTR VTS_BSTR VTS_BSTR VTS_BSTR}; CString strVersion; CMainFrame* pFrm = (CMainFrame*)AfxGetApp ()->m_pMainWnd; strVersion.Format ("%s_%d", vmsFdmAppMgr::getBuildNumberAsString (), pFrm->m_Customizations.get_AffiliateID ()); CString strState; if (m_pwndOpinions->m_dld->pMgr->IsDone ()) strState = "Downloaded"; else if (m_pwndOpinions->m_dld->pMgr->IsRunning ()) strState = "Downloading"; else strState = "Paused"; CString strSize; UINT64 u = m_pwndOpinions->m_dld->pMgr->GetSSFileSize (); if (u != _UI64_MAX) { char sz [100]; _i64toa ((__int64)u, sz, 10); strSize = sz; } else strSize = "Unknown"; CString strComment = m_pwndOpinions->m_dld->strComment; strComment.Replace ("\r\n", " "); strComment.Replace ("\r", " "); strComment.Replace ("\n", " "); CString strUrl; if (m_pwndOpinions->m_dld->pMgr->IsBittorrent ()) strUrl = m_pwndOpinions->m_dld->pMgr->GetBtDownloadMgr ()->get_InfoHash (); else strUrl = m_pwndOpinions->m_dld->pMgr->get_URL (); COleDispatchDriver ddr (pdScript); ddr.InvokeHelper (didFun, DISPATCH_METHOD, VT_VARIANT, (void*)&vtResult, params, strVersion, strUrl, strComment, strState, strSize); RetrieveLinkToUsText (spdDoc); }