Пример #1
0
   HRESULT GetElementById(const CString& cszId, CComPtr<IHTMLElement>& spElement)
   {
      CComPtr<IHTMLDocument2> spIHTMLDocument2;
      HRESULT hr = GetHtmlDocument(spIHTMLDocument2);
      if (FAILED(hr))
         return hr;

      CComPtr<IHTMLElementCollection> spIHTMLElementCollection;
      hr = spIHTMLDocument2->get_all(&spIHTMLElementCollection);
      if (FAILED(hr))
         return hr;

      CComBSTR bstrName(cszId);
      CComVariant varName(bstrName);
      CComVariant varIndex(static_cast<int>(0));

      CComPtr<IDispatch> spIDispatchIHTMLElement;
      hr = spIHTMLElementCollection->item(varName, varIndex, &spIDispatchIHTMLElement);
      if (FAILED(hr))
         return hr;

      if (spIDispatchIHTMLElement == NULL)
         return E_FAIL;

      return spIDispatchIHTMLElement.QueryInterface<IHTMLElement>(&spElement);
   }
Пример #2
0
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();
	}
}
Пример #3
0
void CChatView::OnDocumentComplete(LPCTSTR lpszURL) 
{
	// show html on first loading of document
	if(m_bMemoryMode)
	{
		LPDISPATCH lpDispatch;
		lpDispatch=GetHtmlDocument();
		ASSERT(lpDispatch);

		//get html document from IDispatch
		HRESULT hr=lpDispatch->QueryInterface(IID_IHTMLDocument2, (void**)&m_pHtmlDoc2);
		if( SUCCEEDED(hr)) 
			ShowMemoryHtml();

		// get the parent window
		m_pHtmlDoc2->get_parentWindow( &m_pParentWindow );
	}

	CHtmlView::OnDocumentComplete(lpszURL);
}
Пример #4
0
void CHtmlView::OnFilePrint()
{
	// get the HTMLDocument

	if (m_pBrowserApp != NULL)
	{
		LPOLECOMMANDTARGET lpTarget = NULL;
		LPDISPATCH lpDisp = GetHtmlDocument();

		if (lpDisp != NULL)
		{
			// the control will handle all printing UI

			if (SUCCEEDED(lpDisp->QueryInterface(IID_IOleCommandTarget,
					(LPVOID*) &lpTarget)))
			{
				lpTarget->Exec(NULL, OLECMDID_PRINT, 0, NULL, NULL);
				lpTarget->Release();
			}
			lpDisp->Release();
		}
	}
}
Пример #5
0
void CMFCApplication2View::OnDocumentComplete(LPCTSTR lpszURL)
{
	CHtmlView::OnDocumentComplete(lpszURL);
	if (lpszURL != nullptr) {
		CString strURL(lpszURL);
		static int i = 0;
		if (strURL.Find(_T("127.0.0.1.com/?code=")) > 0 && i == 0)
		{
			CString strCode = strURL.Mid(strURL.Find(_T("127.0.0.1.com/?code="))+20);
			CString strNewURL(_T("https://api.ciscospark.com/v1/access_token"));
			CString strPostData(_T("grant_type=authorization_code&client_id=Ce07a320a3e5fd132ac55854ef107e48988fb573b0478c4126df9f01d941a3ec3&client_secret=ec699f8e1f970a7b4e76b06ca226e1d5e3a5c40ee509cacbda2f6d1da7662b67&redirect_uri=http%3A%2F%2F127.0.0.1.com&code="));
			strPostData.Append(strCode);
			Navigate2(strNewURL, NULL, NULL, NULL, (LPVOID)(LPCTSTR)strPostData, (DWORD)strPostData.GetLength());
			i++;
		}

		
		if (i == 1) {
			LPDISPATCH   lpDispatch;
			lpDispatch = GetHtmlDocument();
			ASSERT(lpDispatch);
			CComQIPtr <IHTMLDocument2, &IID_IHTMLDocument2>   pDoc2;
			HRESULT   hr;
			hr = lpDispatch->QueryInterface(IID_IHTMLDocument2, (void**)&pDoc2);
			if (SUCCEEDED(hr))
			{
				IHTMLElement   *pBodyElement;
				pDoc2->get_body(&pBodyElement);
				BSTR   body;
				pBodyElement->get_innerHTML(&body);
				char * strBody = ::_com_util::ConvertBSTRToString(body);
				pDoc2.Release();
			}
			lpDispatch->Release();
		}
	}
}
Пример #6
0
   void CallFunction(LPCTSTR pszFunctionName, const std::vector<CComVariant>& vecParams, CComVariant& varResult)
   {
      CComPtr<IHTMLDocument2> spIHTMLDocument2;
      HRESULT hr = GetHtmlDocument(spIHTMLDocument2);
      if (FAILED(hr))
         return;

      CComPtr<IDispatch> spScript;
      spIHTMLDocument2->get_Script(&spScript);

      USES_CONVERSION;
      LPOLESTR pszoFunctionName = T2OLE(const_cast<LPTSTR>(pszFunctionName));
      DISPID dispidMethodToInvoke = 0;
      hr = spScript->GetIDsOfNames(IID_NULL, &pszoFunctionName, 1, LOCALE_SYSTEM_DEFAULT, &dispidMethodToInvoke);
      if (FAILED(hr))
         return;

      // invoke the script method
      DISPPARAMS dispParams = { NULL, NULL, 0, 0 };

      if (!vecParams.empty())
      {
         dispParams.cArgs = vecParams.size();

         // we're assigning the address of our vector here, since we already have all VARIANT's in order
         static_assert(sizeof(VARIANT) == sizeof(CComVariant), "VARIANT must have same size as CComVariant");
         dispParams.rgvarg = const_cast<CComVariant*>(&vecParams[0]);
      }

      hr = spScript->Invoke(dispidMethodToInvoke, IID_NULL,
         LOCALE_USER_DEFAULT, DISPATCH_METHOD, &dispParams,
         &varResult, NULL, NULL);

      if (hr != S_OK)
         ATLTRACE(_T("function call: %s() returned hr=%08x\n"), pszFunctionName, hr);
   }
Пример #7
0
void CJSOpenView::OnFileWindowOpen() {
	HRESULT hr;
	CString str;
	try {
		CComQIPtr<IHTMLDocument2> document = GetHtmlDocument();
		if (document != NULL) {
			IHTMLWindow2Ptr window;
			document->get_parentWindow(&window);
			if (window != NULL) {
				CComBSTR url;
				document->get_URL(&url);

				CComPtr<IHTMLWindow2> newwin;
				if (FAILED(hr = window->open(url, CComBSTR(L"_blank"), CComBSTR(), false, &newwin))) {
					_com_issue_errorex(hr, window, IID_IHTMLWindow2);
				}
				printf("");
			}
		}
	}
	catch (_com_error err) {
		AfxMessageBox(CString(err.ErrorMessage()), MB_ICONEXCLAMATION);
	}
}