HRESULT fsShellBrowsersEvents::Attach(SHDocVw::IWebBrowser2Ptr& spBrowser)
{
	if (m_bDetaching)
		return S_FALSE;

	IConnectionPointContainerPtr spConnPtContr;
	HRESULT hr;

	

	hr = spBrowser->QueryInterface (IID_IConnectionPointContainer, (LPVOID*) &spConnPtContr);
	if (FAILED (hr))
		return hr;

	hr = spConnPtContr->FindConnectionPoint (__uuidof (SHDocVw::DWebBrowserEvents2), &m_spConnPt);
	if (FAILED (hr))
		return hr;

	hr = m_spConnPt->Advise (GetIDispatch (FALSE), &m_dwCookie);

	if (SUCCEEDED (hr))
		m_spWB = spBrowser;

	return hr;
}
示例#2
0
HRESULT CPdnWnd::ContainerCreate(BOOL popUnder)
{
	/* Create the control */
	IOleObject* activeXControl = 
		m_ActiveXHost.Create(m_hWnd, L"Shell.Explorer.2", popUnder);
	if(activeXControl == NULL)
	{
		return E_FAIL;
	}
	/* Get the webbrowser control and initialize the browser */
	HRESULT hr = activeXControl->QueryInterface(IID_IWebBrowser2,
		(void**) &m_pBrowser);
	if(SUCCEEDED(hr))
	{
		DWORD dwCookie;
		IConnectionPointContainerPtr pCPC;
		IConnectionPointPtr pCP;
		HRESULT hr = activeXControl->QueryInterface(
			IID_IConnectionPointContainer, (LPVOID*) &pCPC);
		hr = pCPC->FindConnectionPoint(DIID_DWebBrowserEvents2, &pCP);
		hr = pCP->Advise(dynamic_cast<IDispatch*>(this), &dwCookie);

		m_pBrowser->put_RegisterAsBrowser(VARIANT_FALSE);
		m_pBrowser->put_RegisterAsDropTarget(VARIANT_FALSE);
		m_pBrowser->put_Silent(VARIANT_FALSE);
		m_pBrowser->Navigate(_bstr_t(m_URL.c_str()), 0, 0, 0, 0);
	}
	activeXControl->Release();

	return hr;
}
HRESULT WebBrowserEventSinker::AdviseWebBrowser(IWebBrowser2* pWebBrowser2)
{
	//设置连接点
	try
	{
		if (pWebBrowser2)
		{
			IConnectionPointContainerPtr pConnPtContainer;
			IConnectionPointPtr pConnectionPoint;

			// Get IConnectionPointContainer interface for the server.
			HRESULT hr = pWebBrowser2->QueryInterface( IID_IConnectionPointContainer, (void **)&pConnPtContainer );
			if (SUCCEEDED(hr) && pConnPtContainer != NULL)
			{
				// Find the connection point for events that you are interested in.
				hr = pConnPtContainer->FindConnectionPoint( DIID_DWebBrowserEvents2, &pConnectionPoint);
				if (SUCCEEDED(hr) && pConnectionPoint != NULL)
				{
					// Set up advisory connection.
					hr = pConnectionPoint->Advise((IUnknown*)this, &m_dwConnectionCookie);
					if (SUCCEEDED(hr))
					{
						m_pConnectionPoint = pConnectionPoint;
						m_pConnectionPoint->AddRef();
						return S_OK;
					}
				}
			}
		}
	}
	catch (...)
	{
	}
	return E_FAIL;
}
HRESULT CDownloads_Opinions_WBEvents::Attach()
{
	IConnectionPointContainerPtr spCPC;

	LPUNKNOWN pUnk = m_pwndOpinions->m_wb.GetControlUnknown ();
	if (pUnk == NULL)
		return E_FAIL;

	spCPC = pUnk;
	if (spCPC == NULL)
		return E_FAIL;

	spCPC->FindConnectionPoint (DIID_DWebBrowserEvents2, &m_spCP);
	if (m_spCP == NULL)
		return E_FAIL;

	return m_spCP->Advise (GetIDispatch (FALSE), &m_dwCookie);
}
示例#5
0
文件: Reference.cpp 项目: jbroll/tcom
Reference::Connection::Connection (Tcl_Interp *interp,
                                   IUnknown *pSource,
                                   const Interface &eventInterfaceDesc,
                                   TclObject servant)
{
    HRESULT hr;

    // Get connection point container.
    IConnectionPointContainerPtr pContainer;
    hr = pSource->QueryInterface(
        IID_IConnectionPointContainer,
        reinterpret_cast<void **>(&pContainer));
    if (FAILED(hr)) {
        _com_issue_error(hr);
    }

    // Find connection point.
    hr = pContainer->FindConnectionPoint(
        eventInterfaceDesc.iid(), &m_pConnectionPoint);
    if (FAILED(hr)) {
        _com_issue_error(hr);
    }

    // Create event sink.
    ComObject *pComObject = ComObject::newInstance(
        eventInterfaceDesc,
        interp,
        servant,
        "",
        true);

    // Connect to connection point.
    hr = m_pConnectionPoint->Advise(pComObject->unknown(), &m_adviseCookie);
    if (FAILED(hr)) {
        _com_issue_error(hr);
    }
}
示例#6
0
///////////////////////////////////////////////////////////////////////
//功 能:释放项目使用的资源
//描 述:必须在此释放项目使用的资源,否则程序无法完全退出
///////////////////////////////////////////////////////////////////////
void CCtrlItem::Release(OLECLOSE dwCloseOption)
{
	HRESULT hResult;
	IConnectionPointContainerPtr pConnectionPointContainer;

	UINT nState = GetItemState();
	if ((nState == activeUIState) || (nState == activeState) || (nState == openState))
	{
		Close( OLECLOSE_NOSAVE);
	}

    if (m_pOleInPlaceObjectWindowless != NULL)
	{
		m_pOleInPlaceObjectWindowless.Release();
	}

	if (m_pViewObjectEx != NULL)
    {
		m_pViewObjectEx.Release();
    }
   
	if (m_pExtendedControl != NULL)
	{
		// Salvage the display name from the extended control before it goes
		// away.
//		m_strDisplayName = BSTR( m_pExtendedControl->Name );
		m_pExtendedControl.Release();
	}

	if ((m_lpObject != NULL) && (m_dwPropertyCookie != 0))

//	if( (m_lpObject != NULL) && ((m_dwEventCookie != 0) ||
//	  (m_dwPropertyCookie != 0)) )
	{
		m_lpObject->QueryInterface(IID_IConnectionPointContainer,
			(void**)&pConnectionPointContainer);
	}

	if (m_dwPropertyCookie != 0)
	{
		if (m_pPropertyCP == NULL)
		{
			 // We must have quick activated
			hResult = pConnectionPointContainer->FindConnectionPoint(
				IID_IPropertyNotifySink, &m_pPropertyCP);
			if (FAILED(hResult))
			{
				TRACE("QuickActivated control connected to property notify sink, but doesn't support that connection point.\n" );
			}
		}
		if (m_pPropertyCP != NULL)
		{
			m_pPropertyCP->Unadvise(m_dwPropertyCookie);
			m_dwPropertyCookie = 0;
			m_pPropertyCP.Release();
		}
	}

	if (pConnectionPointContainer != NULL)
	{
		pConnectionPointContainer.Release();
	}

	COleClientItem::Release(dwCloseOption);

//  CoFreeUnusedLibraries();
}
示例#7
0
//#include "OLEACC.H"
////////////////////////////////////////////////////////////////////////////
//功 能:完成创建
////////////////////////////////////////////////////////////////////////////
BOOL CCtrlItem::FinishCreate(HRESULT hr)
{
	BOOL tSuccess;
	IConnectionPointContainerPtr pCPContainer;
	HRESULT hResult;

	tSuccess = COleClientItem::FinishCreate(hr);
	if (!tSuccess)
	{
		return tSuccess;
	}

	hResult = m_lpObject->QueryInterface( IID_IConnectionPointContainer,
	  (void**)&pCPContainer );
   if ( SUCCEEDED( hResult ) )
   {
	//  if( m_dwEventCookie == 0 )
	//  {
	//	 hResult = pCPContainer->FindConnectionPoint( m_infoEvents.GetIID(),
	//		&m_pEventCP );
	//	 if( SUCCEEDED( hResult ) )
	//	 {
	//		m_pEventCP->Advise( &m_xEventHandler, &m_dwEventCookie );
	//	 }
	 // }

	  if (m_dwPropertyCookie == 0)
	  {
		 hResult = pCPContainer->FindConnectionPoint( IID_IPropertyNotifySink,
			&m_pPropertyCP );
		 if (SUCCEEDED(hResult))
		 {
			m_pPropertyCP->Advise(&m_xPropertyNotifySink,
			   &m_dwPropertyCookie );
		 }
	  }
   }

	hResult = m_lpObject->QueryInterface(IID_IViewObjectEx,
		(void**)&m_pViewObjectEx);
	if (SUCCEEDED(hResult))
	{
		TRACE("Control supports IViewObjectEx.\n");
		m_pViewObjectEx->GetViewStatus(&m_dwViewStatus);
	}
	else
	{
		m_dwViewStatus = 0;
	}

/*	IAccessible* pAccessible = NULL;
	hResult = m_lpObject->QueryInterface(IID_IAccessible,
		(void**)&pAccessible);
	if (SUCCEEDED(hResult))
	{
		pAccessible->put_accName(COleVariant(long(0)), L"aa");
//		TRACE("Control supports IViewObjectEx.\n");
//		m_pViewObjectEx->GetViewStatus(&m_dwViewStatus);
	}
	if (pAccessible != NULL)
		pAccessible->Release();
*/
//	UpdateLink();
	

	return TRUE;
}