Beispiel #1
0
bool CActiveXUI::DelayedControlCreation()
{
	ReleaseControl();
	// At this point we'll create the ActiveX control
	m_bCreated = true;
	IOleControl* pOleControl = NULL;
	HRESULT Hr = ::CoCreateInstance(m_clsid, NULL, CLSCTX_ALL, IID_IOleControl, (LPVOID*) &pOleControl);
	ASSERT(SUCCEEDED(Hr));
	if( FAILED(Hr) ) return false;
	pOleControl->QueryInterface(IID_IOleObject, (LPVOID*) &m_pUnk);
	pOleControl->Release();
	if( m_pUnk == NULL ) return false;
	// Create the host too
	m_pControl = new CActiveXCtrl();
	m_pControl->m_pOwner = this;
	// More control creation stuff
	DWORD dwMiscStatus = 0;
	m_pUnk->GetMiscStatus(DVASPECT_CONTENT, &dwMiscStatus);
	IOleClientSite* pOleClientSite = NULL;
	m_pControl->QueryInterface(IID_IOleClientSite, (LPVOID*) &pOleClientSite);
	CSafeRelease<IOleClientSite> RefOleClientSite = pOleClientSite;
	// Initialize control
	if( (dwMiscStatus & OLEMISC_SETCLIENTSITEFIRST) != 0 ) m_pUnk->SetClientSite(pOleClientSite);
	IPersistStreamInit* pPersistStreamInit = NULL;
	m_pUnk->QueryInterface(IID_IPersistStreamInit, (LPVOID*) &pPersistStreamInit);
	if( pPersistStreamInit != NULL ) {
		Hr = pPersistStreamInit->InitNew();
		pPersistStreamInit->Release();
	}
	if( FAILED(Hr) ) return false;
	if( (dwMiscStatus & OLEMISC_SETCLIENTSITEFIRST) == 0 ) m_pUnk->SetClientSite(pOleClientSite);
	// Grab the view...
	Hr = m_pUnk->QueryInterface(IID_IViewObjectEx, (LPVOID*) &m_pControl->m_pViewObject);
	if( FAILED(Hr) ) Hr = m_pUnk->QueryInterface(IID_IViewObject2, (LPVOID*) &m_pControl->m_pViewObject);
	if( FAILED(Hr) ) Hr = m_pUnk->QueryInterface(IID_IViewObject, (LPVOID*) &m_pControl->m_pViewObject);
	// Activate and done...
	m_pUnk->SetHostNames(OLESTR("UIActiveX"), NULL);
	if( (dwMiscStatus & OLEMISC_INVISIBLEATRUNTIME) == 0 ) {
		Hr = m_pUnk->DoVerb(OLEIVERB_INPLACEACTIVATE, NULL, pOleClientSite, 0, m_pManager->GetPaintWindow(), &m_rcItem);
		::RedrawWindow(m_pManager->GetPaintWindow(), &m_rcItem, NULL, RDW_INVALIDATE | RDW_UPDATENOW | RDW_ERASE | RDW_INTERNALPAINT | RDW_FRAME);
	}
	IObjectWithSite* pSite = NULL;
	m_pUnk->QueryInterface(IID_IObjectWithSite, (LPVOID*) &pSite);
	if( pSite != NULL ) {
		pSite->SetSite(static_cast<IOleClientSite*>(m_pControl));
		pSite->Release();
	}
	return SUCCEEDED(Hr);
}
Beispiel #2
0
void test_CShellMenu()
{
    HRESULT hResult;
    IShellMenu* shellMenu;
    IDockingWindow* dockingMenu;
    IShellFolder *shellFolder;
    IObjectWithSite *menuWithSite;
    HWND hwndToolbar;

    HWND hWndParent = CreateWindowExW(0, L"EDIT", L"miau", 0, CW_USEDEFAULT, CW_USEDEFAULT,
        CW_USEDEFAULT, CW_USEDEFAULT, NULL, NULL, GetModuleHandle(NULL), NULL);
    CDummyWindow* dummyWindow = new CDummyWindow(hWndParent);

    if (!CreateCShellMenu(&shellMenu, &dockingMenu, &menuWithSite))
    {
        skip("failed to create CShellMenuObject\n");
        delete dummyWindow;
        return;
    }

    hResult = SHGetDesktopFolder(&shellFolder);
    test_S_OK(hResult, "SHGetDesktopFolder failed");

    hResult = shellMenu->Initialize(NULL, 0, ANCESTORDEFAULT, SMINIT_TOPLEVEL|SMINIT_VERTICAL);
    test_S_OK(hResult, "Initialize failed");

    hResult = shellMenu->SetShellFolder(shellFolder, NULL, NULL, 0);
    test_S_OK(hResult, "SetShellFolder failed");

    hResult = menuWithSite->SetSite(dummyWindow);
    test_S_OK(hResult, "SetSite failed");

    hResult = dockingMenu->GetWindow(&hwndToolbar);
    test_S_OK(hResult, "GetWindow failed");
    ok(hwndToolbar != NULL, "GetWindow should return a window\n");

    HWND hwndRealParent = GetParent(hwndToolbar);
    ok(GetParent(hwndRealParent) == hWndParent, "Wrong parent\n");
    ok(CheckWindowClass(hwndToolbar, L"ToolbarWindow32"), "Wrong class\n");
    ok(CheckWindowClass(hwndRealParent, L"SysPager"), "Wrong class\n");

    menuWithSite->Release();
    dockingMenu->Release();
    shellMenu->Release();
    ok(!IsWindow(hwndToolbar), "The toolbar window should not exist\n");

    DestroyWindow(hWndParent);
}
void CActiveXUI::ReleaseControl()
{
    m_hwndHost = NULL;
    if( m_pUnk != NULL ) {
        IObjectWithSite* pSite = NULL;
        m_pUnk->QueryInterface(IID_IObjectWithSite, (LPVOID*) &pSite);
        if( pSite != NULL ) {
            pSite->SetSite(NULL);
            pSite->Release();
        }
        m_pUnk->Close(OLECLOSE_NOSAVE);
        m_pUnk->SetClientSite(NULL);
        m_pUnk->Release(); 
        m_pUnk = NULL;
    }
    if( m_pControl != NULL ) {
        m_pControl->m_pOwner = NULL;
        m_pControl->Release();
        m_pControl = NULL;
    }
    m_pManager->RemoveMessageFilter(this);
}
bool CActiveXUI::DoCreateControl()
{
    ReleaseControl();
    // At this point we'll create the ActiveX control
    m_bCreated = true;
    IOleControl* pOleControl = NULL;

    HRESULT Hr = -1;
    if( !m_sModuleName.IsEmpty() ) {
        HMODULE hModule = ::LoadLibrary((LPCTSTR)m_sModuleName);
        if( hModule != NULL ) {
            IClassFactory* aClassFactory = NULL;
            DllGetClassObjectFunc aDllGetClassObjectFunc = (DllGetClassObjectFunc)::GetProcAddress(hModule, "DllGetClassObject");
            Hr = aDllGetClassObjectFunc(m_clsid, IID_IClassFactory, (LPVOID*)&aClassFactory);
            if( SUCCEEDED(Hr) ) {
                Hr = aClassFactory->CreateInstance(NULL, IID_IOleObject, (LPVOID*)&pOleControl);
            }
            aClassFactory->Release();
        }
    }
    if( FAILED(Hr) ) {
        Hr = ::CoCreateInstance(m_clsid, NULL, CLSCTX_ALL, IID_IOleControl, (LPVOID*)&pOleControl);
    }
    ASSERT(SUCCEEDED(Hr));
    if( FAILED(Hr) ) return false;
    pOleControl->QueryInterface(IID_IOleObject, (LPVOID*) &m_pUnk);
    pOleControl->Release();
    if( m_pUnk == NULL ) return false;
    // Create the host too
    m_pControl = new CActiveXCtrl();
    m_pControl->m_pOwner = this;
    // More control creation stuff
    DWORD dwMiscStatus = 0;
    m_pUnk->GetMiscStatus(DVASPECT_CONTENT, &dwMiscStatus);
    IOleClientSite* pOleClientSite = NULL;
    m_pControl->QueryInterface(IID_IOleClientSite, (LPVOID*) &pOleClientSite);
    CSafeRelease<IOleClientSite> RefOleClientSite = pOleClientSite;
    // Initialize control
    if( (dwMiscStatus & OLEMISC_SETCLIENTSITEFIRST) != 0 ) m_pUnk->SetClientSite(pOleClientSite);
    IPersistStreamInit* pPersistStreamInit = NULL;
    m_pUnk->QueryInterface(IID_IPersistStreamInit, (LPVOID*) &pPersistStreamInit);
    if( pPersistStreamInit != NULL ) {
        Hr = pPersistStreamInit->InitNew();
        pPersistStreamInit->Release();
    }
    if( FAILED(Hr) ) return false;
    if( (dwMiscStatus & OLEMISC_SETCLIENTSITEFIRST) == 0 ) m_pUnk->SetClientSite(pOleClientSite);
    // Grab the view...
    Hr = m_pUnk->QueryInterface(IID_IViewObjectEx, (LPVOID*) &m_pControl->m_pViewObject);
    if( FAILED(Hr) ) Hr = m_pUnk->QueryInterface(IID_IViewObject2, (LPVOID*) &m_pControl->m_pViewObject);
    if( FAILED(Hr) ) Hr = m_pUnk->QueryInterface(IID_IViewObject, (LPVOID*) &m_pControl->m_pViewObject);
    // Activate and done...
    m_pUnk->SetHostNames(OLESTR("UIActiveX"), NULL);
    if( m_pManager != NULL ) m_pManager->SendNotify((CControlUI*)this, _T("showactivex"), 0, 0, false);
    if( (dwMiscStatus & OLEMISC_INVISIBLEATRUNTIME) == 0 ) {
        Hr = m_pUnk->DoVerb(OLEIVERB_INPLACEACTIVATE, NULL, pOleClientSite, 0, m_pManager->GetPaintWindow(), &m_rcItem);
        //::RedrawWindow(m_pManager->GetPaintWindow(), &m_rcItem, NULL, RDW_INVALIDATE | RDW_UPDATENOW | RDW_ERASE | RDW_INTERNALPAINT | RDW_FRAME);
    }
    IObjectWithSite* pSite = NULL;
    m_pUnk->QueryInterface(IID_IObjectWithSite, (LPVOID*) &pSite);
    if( pSite != NULL ) {
        pSite->SetSite(static_cast<IOleClientSite*>(m_pControl));
        pSite->Release();
    }
    return SUCCEEDED(Hr);
}
Beispiel #5
0
bool AxContainer::CreateControl( const std::string &strModule, REFCLSID rclsid )
{
	IOleControl* pOleControl = NULL;

	HRESULT hr = -1;
	if( !strModule.empty() ) 
	{
		HMODULE hModule = ::LoadLibrary((LPCTSTR)strModule.c_str());
		if( hModule != NULL ) 
		{
			IClassFactory* aClassFactory = NULL;
			DllGetClassObjectFunc aDllGetClassObjectFunc = (DllGetClassObjectFunc)::GetProcAddress(hModule, "DllGetClassObject");
			hr = aDllGetClassObjectFunc(rclsid, IID_IClassFactory, (LPVOID*)&aClassFactory);
			if( SUCCEEDED(hr) ) 
			{
				hr = aClassFactory->CreateInstance(NULL, IID_IOleObject, (LPVOID*)&pOleControl);
			}
			aClassFactory->Release();
		}
	}
	if( FAILED(hr) ) 
		hr = ::CoCreateInstance(rclsid, NULL, CLSCTX_ALL, IID_IOleControl, (LPVOID*)&pOleControl);

	if( FAILED(hr) ) 
		return false;
	pOleControl->QueryInterface(IID_IOleObject, (LPVOID*) &m_pOleObject);
	pOleControl->Release();
	if( m_pOleObject == NULL ) 
		return false;

	hr = m_pOleObject->QueryInterface(IID_IOleInPlaceObjectWindowless, (LPVOID*) &m_pInPlaceObject);

	// More control creation stuff
	DWORD dwMiscStatus = 0;
	m_pOleObject->GetMiscStatus(DVASPECT_CONTENT, &dwMiscStatus);
	// Initialize control
	if( (dwMiscStatus & OLEMISC_SETCLIENTSITEFIRST) != 0 ) 
		m_pOleObject->SetClientSite(this);
	IPersistStreamInit* pPersistStreamInit = NULL;
	m_pOleObject->QueryInterface(IID_IPersistStreamInit, (LPVOID*) &pPersistStreamInit);
	if( pPersistStreamInit != NULL )
	{
		hr = pPersistStreamInit->InitNew();
		pPersistStreamInit->Release();
	}
	if( FAILED(hr) ) 
		return false;
	if( (dwMiscStatus & OLEMISC_SETCLIENTSITEFIRST) == 0 ) 
		m_pOleObject->SetClientSite(this);
	// Grab the view...
	hr = m_pOleObject->QueryInterface(IID_IViewObjectEx, (LPVOID*) &m_pViewObject);
	if( FAILED(hr) ) 
		hr = m_pOleObject->QueryInterface(IID_IViewObject2, (LPVOID*) &m_pViewObject);
	if( FAILED(hr) ) 
		hr = m_pOleObject->QueryInterface(IID_IViewObject, (LPVOID*) &m_pViewObject);

	// Activate and done...
	m_pOleObject->SetHostNames(OLESTR("UIActiveX"), NULL);
	if( (dwMiscStatus & OLEMISC_INVISIBLEATRUNTIME) == 0 ) 
		DoVerb(OLEIVERB_INPLACEACTIVATE);

	IObjectWithSite* pSite = NULL;
	m_pOleObject->QueryInterface(IID_IObjectWithSite, (LPVOID*) &pSite);
	if( pSite != NULL ) 
	{
		pSite->SetSite(static_cast<IOleWindow*>(this));
		pSite->Release();
	}

	return SUCCEEDED(hr);
}
/* The following steps are taken when showing shell
extensions on an existing menu:
1. Load shell extensions.
2. Build and show menu.
3. Pass selection to shell extension (if necessary).
4. Release shell extensions (also free the DLL's they reside in). */
CContextMenuManager::CContextMenuManager(ContextMenuType_t ContextMenuType,
	LPCITEMIDLIST pidlDirectory,IDataObject *pDataObject,IUnknown *pUnkSite)
{
	ItemType_t ItemType = GetItemType(pidlDirectory);

	const TCHAR *pszRegContext = NULL;

	switch(ItemType)
	{
	case ITEM_TYPE_FOLDER:
		if(ContextMenuType == CONTEXT_MENU_TYPE_DRAG_AND_DROP)
		{
			pszRegContext = CMH_FOLDER_DRAG_AND_DROP;
		}
		break;

	case ITEM_TYPE_DIRECTORY:
		if(ContextMenuType == CONTEXT_MENU_TYPE_BACKGROUND)
		{
			pszRegContext = CMH_DIRECTORY_BACKGROUND;
		}
		else if(ContextMenuType == CONTEXT_MENU_TYPE_DRAG_AND_DROP)
		{
			pszRegContext = CMH_DIRECTORY_DRAG_AND_DROP;
		}
		break;
	}

	if(pszRegContext == NULL)
	{
		return;
	}

	BOOL bRet = LoadContextMenuHandlers(pszRegContext,m_ContextMenuHandlers);

	if(!bRet)
	{
		return;
	}

	/* Initialize the shell extensions, and extract
	an IContextMenu interface. */
	for each(auto ContextMenuHandler in m_ContextMenuHandlers)
	{
		IShellExtInit *pShellExtInit = NULL;
		HRESULT hr;

		IUnknown *pUnknown = ContextMenuHandler.pUnknown;

		hr = pUnknown->QueryInterface(IID_PPV_ARGS(&pShellExtInit));

		if(SUCCEEDED(hr))
		{
			MenuHandler_t MenuHandler;
			IContextMenu *pContextMenu = NULL;
			IContextMenu2 *pContextMenu2 = NULL;
			IContextMenu3 *pContextMenu3 = NULL;

			pShellExtInit->Initialize(pidlDirectory,pDataObject,NULL);
			pShellExtInit->Release();

			if(pUnkSite != NULL)
			{
				IObjectWithSite *pObjectSite = NULL;

				hr = pUnknown->QueryInterface(IID_PPV_ARGS(&pObjectSite));

				if(SUCCEEDED(hr))
				{
					pObjectSite->SetSite(pUnkSite);
					pObjectSite->Release();
				}
			}

			hr = pUnknown->QueryInterface(IID_PPV_ARGS(&pContextMenu3));
			MenuHandler.pContextMenuActual = pContextMenu3;

			if(FAILED(hr) || pContextMenu3 == NULL)
			{
				hr = pUnknown->QueryInterface(IID_PPV_ARGS(&pContextMenu2));
				MenuHandler.pContextMenuActual = pContextMenu2;

				if(FAILED(hr) || pContextMenu2 == NULL)
				{
					hr = pUnknown->QueryInterface(IID_PPV_ARGS(&pContextMenu));
					MenuHandler.pContextMenuActual = pContextMenu;
				}
			}

			MenuHandler.pContextMenu = pContextMenu;
			MenuHandler.pContextMenu2 = pContextMenu2;
			MenuHandler.pContextMenu3 = pContextMenu3;

			MenuHandler.uStartID = 0;
			MenuHandler.uEndID = 0;

			m_MenuHandlers.push_back(MenuHandler);
		}
	}
Beispiel #7
0
HRESULT CXcpControlHost::ActivateXcpControl(IUnknown* pUnKnown) 
{
    if (pUnKnown == NULL)
	{
        return S_OK;
    }

    m_spUnknown = pUnKnown;

    HRESULT hr = S_OK;
    pUnKnown->QueryInterface(__uuidof(IOleObject), (void**)&m_spOleObject);
    if (m_spOleObject) 
	{
        //m_spOleObject->GetMiscStatus(DVASPECT_CONTENT, &m_dwMiscStatus);
		OleRegGetMiscStatus( __uuidof(m_spOleObject), DVASPECT_CONTENT, &m_dwMiscStatus );
        if (m_dwMiscStatus & OLEMISC_SETCLIENTSITEFIRST) 
		{
            //CComQIPtr<IOleClientSite> spClientSite(GetControllingUnknown());
			IOleClientSite	*spClientSite = NULL;
			((ATL::CAxHostWindow *)this)->QueryInterface( __uuidof(IOleClientSite), (void **)&spClientSite );
			if( NULL != spClientSite )
			{
				m_spOleObject->SetClientSite(spClientSite);
				spClientSite->Release();
			}
        }

        //CComQIPtr<IPersistPropertyBag> pPersist(m_spOleObject);
		IPersistPropertyBag	*pPersist = NULL;
		m_spOleObject->QueryInterface( __uuidof(IPersistPropertyBag), (void **)&pPersist );

        if ( NULL != pPersist ) 
		{
            IPropertyBag* pPropBag = (IPropertyBag*)new CXcpPropertyBag();
            pPropBag->AddRef();

            pPersist->Load((IPropertyBag*)pPropBag, NULL);
            pPropBag->Release();
        }

        if (0 == (m_dwMiscStatus & OLEMISC_SETCLIENTSITEFIRST)) 
		{
            //CComQIPtr<IOleClientSite> spClientSite(GetControllingUnknown());
			IOleClientSite	*spClientSite = NULL;
			((ATL::CAxHostWindow *)this)->QueryInterface(  __uuidof(IOleClientSite), (void **)&spClientSite);
			//GetControllingUnknown()->QueryInterface( __uuidof(IOleClientSite), (void **)&spClientSite );
			if( NULL != spClientSite )
			{
				m_spOleObject->SetClientSite(spClientSite);
				spClientSite->Release();
			}
        }

        m_dwViewObjectType = 0;
        hr = m_spOleObject->QueryInterface(__uuidof(IViewObjectEx), (void**) &m_spViewObject);
        if (FAILED(hr)) 
		{
            hr = m_spOleObject->QueryInterface(__uuidof(IViewObject2), (void**) &m_spViewObject);
            if (SUCCEEDED(hr))
			{
                m_dwViewObjectType = 3;
            }
        }
        else
		{
            m_dwViewObjectType = 7;
        }

        if (FAILED(hr)) 
		{
            hr = m_spOleObject->QueryInterface(__uuidof(IViewObject), (void**) &m_spViewObject);
            if (SUCCEEDED(hr))
			{
                m_dwViewObjectType = 1;
			}
        }

        //CComQIPtr<IAdviseSink> spAdviseSink(GetControllingUnknown());
		IAdviseSink *spAdviseSink = NULL;
		//GetControllingUnknown()->QueryInterface( __uuidof(IAdviseSink), (void **)&spAdviseSink );
		((ATL::CAxHostWindow *)this)->QueryInterface( __uuidof(IAdviseSink), (void **)&spAdviseSink );
		if( NULL != spAdviseSink )
		{
			m_spOleObject->Advise(spAdviseSink, &m_dwOleObject);
			if (m_spViewObject) 
			{
				m_spViewObject->SetAdvise(DVASPECT_CONTENT, 0, spAdviseSink);
			}
			spAdviseSink->Release();
		}

        m_spOleObject->SetHostNames(OLESTR("AXWIN"), NULL);

        if ((m_dwMiscStatus & OLEMISC_INVISIBLEATRUNTIME) == 0) 
		{
			m_spOleObject->GetExtent( DVASPECT_CONTENT, &m_hmSize );
            m_pxSize.cx =  m_rcPos.right - m_rcPos.left;
            m_pxSize.cy =  m_rcPos.bottom - m_rcPos.top;
            AtlPixelToHiMetric(&m_pxSize, &m_hmSize);
            m_spOleObject->SetExtent(DVASPECT_CONTENT, &m_hmSize);
            m_spOleObject->GetExtent(DVASPECT_CONTENT, &m_hmSize);
            AtlHiMetricToPixel(&m_hmSize, &m_pxSize);
            m_rcPos.right = m_rcPos.left + m_pxSize.cx ;
            m_rcPos.bottom = m_rcPos.top + m_pxSize.cy ;
            //CComQIPtr<IOleClientSite> spClientSite(GetControllingUnknown());
			IOleClientSite *spClientSite = NULL;
			//GetControllingUnknown()->QueryInterface( __uuidof(IOleClientSite), (void **)&spClientSite );
			((ATL::CAxHostWindow *)this)->QueryInterface( __uuidof(IOleClientSite), (void **)&spClientSite );
			if( NULL != spClientSite )
			{
				m_rcPos.left = m_rcPos.top = 0;
				m_rcPos.right = m_hmSize.cx;
				m_rcPos.bottom = m_hmSize.cy;
				hr = m_spOleObject->DoVerb( OLEIVERB_INPLACEACTIVATE, NULL, spClientSite, 0, m_hWnd, &m_rcPos );
				::RedrawWindow( m_hWnd, NULL, NULL, RDW_INVALIDATE | RDW_UPDATENOW | RDW_ERASE | RDW_INTERNALPAINT | RDW_FRAME );
				spClientSite->Release();
			}
        }
		if( NULL != pPersist )
		{
			pPersist->Release();
		}
    }

    //CComPtr<IObjectWithSite> spSite;
	IObjectWithSite		*spSite = NULL;
    pUnKnown->QueryInterface(__uuidof(IObjectWithSite), (void**)&spSite);
    if ( NULL != spSite ) 
	{
//        spSite->SetSite(GetControllingUnknown());
		IUnknown *iUnknown = NULL;
		((ATL::CAxHostWindow *)this)->QueryInterface( __uuidof(IUnknown), (void **)&iUnknown );
		spSite->SetSite( iUnknown );
		spSite->Release();
    }

    return hr;
}