Beispiel #1
0
void CJs2nCtrl::OnSetClientSite() 
{
	// TODO: Add your specialized code here and/or call the base class
	LPOLECLIENTSITE pClientSite = GetClientSite();

	if (pClientSite != NULL)
	{
		// Obtain URL from container moniker.
		IMoniker*	ppmk;
		LPOLESTR	pszDisplayName;

		if (SUCCEEDED(pClientSite->GetMoniker( OLEGETMONIKER_TEMPFORUSER,
											   OLEWHICHMK_CONTAINER,
											   &ppmk)))
		{
			if (SUCCEEDED(ppmk->GetDisplayName(NULL, NULL, &pszDisplayName)))
			{
				PString strURL( (WORD *)pszDisplayName );
				PString strPluginsPath = FindPluginsPath();
				m_NativeLogic.Init( strURL, strPluginsPath );
				CoTaskMemFree((LPVOID)pszDisplayName);
			}
		}
	}

	COleControl::OnSetClientSite();
}
Beispiel #2
0
BOOL
ZDrOleClient::FinishCreate( SCODE sc )
{
   HRESULT hResult = 0;
   BOOL bReturn = COleClientItem::FinishCreate( sc );

   // Determine whether we have to set the ClientSite first
   // by passing our IOleClientSite
   m_lpObject->GetMiscStatus( DVASPECT_CONTENT, &m_dwMiscStatus );
   if ( m_dwMiscStatus & OLEMISC_SETCLIENTSITEFIRST )
   {
      hResult = m_lpObject->SetClientSite( GetClientSite( ) );
      if ( FAILED( hResult ) )
      {
         bReturn = FALSE;
      }
   }

   if ( bReturn )
   {
      if ( IsInvisibleAtRuntime() )
      {
         DoVerb( OLEIVERB_HIDE, GetParentView() );
      }
      else
      {
         DoVerb( OLEIVERB_SHOW, GetParentView() );
      }
   }

   return( bReturn );
}
Beispiel #3
0
void COleClientItem::Activate(LONG nVerb, CView* pView, LPMSG lpMsg)
{
    ASSERT_VALID(this);
    ASSERT(m_lpObject != NULL);
    if (pView != NULL)
        ASSERT_VALID(pView);
    if (lpMsg != NULL)
        ASSERT(AfxIsValidAddress(lpMsg, sizeof(MSG), FALSE));

    // store the container HWND for in place activation then do the verb
    if (m_pView == NULL)
        m_pView = pView;

    _AFX_OLE_STATE* pOleState = _afxOleState;
    CView* pViewSave = pOleState->m_pActivateView;
    pOleState->m_pActivateView = NULL;

    // get item rectangle for in-place players
    //  (that may not support in-place activation)
    LPCRECT lpPosRect = NULL;
    CRect rectPos;
    if (pView != NULL)
    {
        ASSERT_VALID(pView);
        rectPos.SetRectEmpty();
        OnGetItemPosition(rectPos);
        if (!rectPos.IsRectEmpty())
        {
            lpPosRect = &rectPos;
            pOleState->m_pActivateView = pView;
        }
    }

    // prepare DoVerb parameters and call into the server
    LPOLECLIENTSITE lpClientSite = GetClientSite();
    HWND hWnd = pView->GetSafeHwnd();
    SCODE sc = m_lpObject->DoVerb(nVerb, lpMsg, lpClientSite, -1,
                                  hWnd, lpPosRect);

    pOleState->m_pActivateView = pViewSave;

    // clear out m_pView in case in-place activation only partially worked
    if (!IsInPlaceActive())
        m_pView = NULL;

    // update available status based on the results of DoVerb
    //  (this is used in the links dialog).
    m_bLinkUnavail = (BYTE)FAILED(sc);

    CheckGeneral(sc);
}
Beispiel #4
0
void CfsNVRPluginCtrl::OnSetClientSite()
{
	// TODO: 在此添加专用代码和/或调用基类
	try
	{
		LPOLECLIENTSITE pClientSite = GetClientSite();
		LPOLECONTAINER  pOleContainer;
		if (pClientSite == NULL)
		{
			goto RET;
		}

		HRESULT hr = pClientSite->GetContainer(&pOleContainer);
		if (FAILED(hr))
		{
			goto RET;
		}

		IHTMLDocument* doc = NULL;
		hr =  pOleContainer->QueryInterface(IID_IHTMLDocument2,reinterpret_cast <void   **> (&doc)); 
		if (FAILED(hr))
		{
			goto RET;
		}

		IDispatch* script = NULL;
		hr = doc->get_Script(&script);
		doc->Release();
		if(FAILED(hr))
		{
			goto RET;
		}

		m_pScript = script;
	}
	catch (...)
	{

	}
RET:
	COleControl::OnSetClientSite();
}
Beispiel #5
0
/////////////////////////////////////////////////////////////////////////////
//功 能:创建或者导入控件项目
/////////////////////////////////////////////////////////////////////////////
BOOL CCtrlItem::CreateOrLoad(REFCLSID clsid, 
	REFIID iidPersistanceMedium, IUnknown* pPersistanceMedium)
{
	HRESULT hResult;
	BOOL bSuccess;
	IPersistStreamInitPtr pPersistStreamInit;
	IPersistStreamPtr pPersistStream;
	IPersistStoragePtr pPersistStorage;
	IStreamPtr pStream;
	IStoragePtr pStorage;

	ASSERT(m_lpObject == NULL);
	ASSERT(m_pDocument != NULL);

	m_dwItemNumber = GetNewItemNumber();
	GetItemStorage();
	ASSERT(m_lpStorage != NULL);

   	m_bExtendedControl = TRUE;
	hResult = CExtendedControl::CreateInstance(clsid, this, NULL,
		IID_IOleObject, (void**)&m_lpObject);
	if (FAILED(hResult))
	{
		m_bExtendedControl = FALSE;
		hResult = CoCreateInstance(clsid, NULL, CLSCTX_INPROC_SERVER|
			CLSCTX_INPROC_HANDLER|CLSCTX_LOCAL_SERVER, IID_IOleObject,
			(void**)&m_lpObject);

		if (SUCCEEDED(hResult))
		{
			TRACE("Could not aggregate on the control, so it won't support extended properties.\n");
		}
	}

	if (m_bExtendedControl)
	{
		m_pExtendedControl = m_lpObject;
		ASSERT(m_pExtendedControl != NULL);
	}

	//设置客户站点
	if (SUCCEEDED(hResult))
	{
		m_lpObject->GetMiscStatus(DVASPECT_CONTENT, &m_dwMiscStatus);
		if (m_dwMiscStatus&OLEMISC_SETCLIENTSITEFIRST)
		{
			//GetClientSite 得到接口
			hResult = m_lpObject->SetClientSite(GetClientSite());
			if (FAILED(hResult))
			{
			   TRACE("SetClientSite failed.\n");
			}
		 }
	}

	//初始化或装载对象的状态
	if (SUCCEEDED(hResult))
	{
		if( iidPersistanceMedium == IID_NULL )
		{
			pPersistStreamInit = m_lpObject;
			if (pPersistStreamInit != NULL)
			{
				hResult = pPersistStreamInit->InitNew();
				if (hResult == E_NOTIMPL)
				{
					//没有实现 InitNew 为 Ok。
					hResult = S_OK;
				}
			}
			else
			{
				pPersistStorage = m_lpObject;
				if (pPersistStorage != NULL)
				{
					hResult = pPersistStorage->InitNew(m_lpStorage);
				}
				else
				{
					// 假设控件不支持持久性。
					hResult = S_OK;
				}
			}
		}
		else if (iidPersistanceMedium == IID_IStream)
		{
			pStream = pPersistanceMedium;
			ASSERT(pStream != NULL);

			pPersistStreamInit = m_lpObject;
			if (pPersistStreamInit != NULL)
			{
				hResult = pPersistStreamInit->Load(pStream);
			}
			else
			{
				pPersistStream = m_lpObject;
				if (pPersistStream != NULL)
				{
					hResult = pPersistStream->Load(pStream);
				}
				else
				{
					hResult = E_NOINTERFACE;
				}
			}
		}
		else if (iidPersistanceMedium == IID_IStorage)
		{
			pStorage = pPersistanceMedium;
			ASSERT(pStorage != NULL);

			pPersistStorage = m_lpObject;
			if (pPersistStorage != NULL)
			{
				hResult = pStorage->CopyTo(0, NULL, NULL, m_lpStorage);
				if (SUCCEEDED(hResult))
				{
					hResult = pPersistStorage->Load(m_lpStorage);
				}
			}
			else
			{
				hResult = E_NOINTERFACE;
			}
		}
	}

	if (SUCCEEDED(hResult))
	{
		if (!(m_dwMiscStatus&OLEMISC_SETCLIENTSITEFIRST))
		{
			hResult = m_lpObject->SetClientSite(GetClientSite());
			if (FAILED(hResult))
			{
				TRACE("SetClientSite failed.\n");
			}
		}
	}
	//SetClientSite 必须被使用

	bSuccess = FinishCreate(hResult);

	return bSuccess;
}
Beispiel #6
0
IOleClientSite* CP3DActiveXCtrl::GetClientSte( )
{
    return GetClientSite();
}
Beispiel #7
0
int CP3DActiveXCtrl::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
    if (COleControl::OnCreate(lpCreateStruct) == -1)
        return -1;

    // TODO:  Add your specialized creation code here

    int error(0);
    m_spClientSite = GetClientSite();
    if ( !m_spClientSite )
    {
        return ( error = -1 );
    }
    CComPtr<IOleContainer> pOleContainer;
    HRESULT hr = m_spClientSite->GetContainer( &pOleContainer );
    if ( FAILED( hr ) || !pOleContainer )
    {
        return ( error = -1 );
    }
    CComPtr<IHTMLDocument2> pHtml2Doc;
    hr = pOleContainer->QueryInterface( IID_IHTMLDocument, ( void** )&pHtml2Doc );
    if ( FAILED( hr ) || !pHtml2Doc )
    {
        return ( error = -1 );
    }
    BSTR url;
    hr = pHtml2Doc->get_URL( &url );
    if ( FAILED( hr ) ||  !url )
    {
        return ( error = -1 );
    }
    m_hostingPageUrl = url;
    m_hostingPageUrl.Replace( '\\', '/' );

    ::SysFreeString( url );

    CComPtr<IHTMLElementCollection> pHtmlElementCollect;
    hr = pHtml2Doc->get_scripts( &pHtmlElementCollect );
    if ( FAILED( hr ) || !pHtmlElementCollect )
    {
        return ( error = -1 );
    }
    long collectionLength = 0;
    hr = pHtmlElementCollect->get_length( &collectionLength );
    if ( FAILED( hr ) || !pHtmlElementCollect )
    {
        return ( error = -1 );
    }
    if ( collectionLength < 1 )
    {
        // javascript engine was not specified on the page.  hence we need to
        // initialize it by infusing javascript element tags

        CComPtr<IHTMLElement> spHtmlElement;
        hr = pHtml2Doc->createElement( CComBSTR( "script" ), &spHtmlElement );
        if ( SUCCEEDED( hr ) && spHtmlElement )
        {
            hr = spHtmlElement->put_language( CComBSTR( "javascript" ) );
            if ( SUCCEEDED( hr ) )
            {
                CComPtr<IHTMLDOMNode> spElementDomNode;
                hr = spHtmlElement->QueryInterface( IID_IHTMLDOMNode, ( void** )&spElementDomNode );
                if ( SUCCEEDED( hr ) && spElementDomNode )
                {
                    CComPtr<IHTMLDOMNode> spHtmlDomNode;
                    hr = pHtml2Doc->QueryInterface( IID_IHTMLDOMNode, ( void** )&spHtmlDomNode );
                    if ( SUCCEEDED( hr ) && spHtmlDomNode )
                    {
                        CComPtr<IHTMLDOMNode> newNode;
                        hr = spHtmlDomNode->appendChild( spElementDomNode, &newNode );
                    }
                }
            }
        }
    }
    return 0;
}