LRESULT CActiveXWnd::OnMouseActivate(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled) { IOleObject* pUnk = NULL; m_pOwner->m_pOwner->GetControl(IID_IOleObject, (LPVOID*) &pUnk); if( pUnk == NULL ) return 0; CSafeRelease<IOleObject> RefOleObject = pUnk; DWORD dwMiscStatus = 0; pUnk->GetMiscStatus(DVASPECT_CONTENT, &dwMiscStatus); if( (dwMiscStatus & OLEMISC_NOUIACTIVATE) != 0 ) return 0; if( !m_pOwner->m_bInPlaceActive ) DoVerb(OLEIVERB_INPLACEACTIVATE); bHandled = FALSE; return 0; }
void CRibbonSampleCntrItem::OnDeactivateUI(BOOL bUndoable) { COleClientItem::OnDeactivateUI(bUndoable); // hide the object if it is not an outside-in object DWORD dwMisc = 0; m_lpObject->GetMiscStatus(GetDrawAspect(), &dwMisc); if (dwMisc & OLEMISC_INSIDEOUT) DoVerb(OLEIVERB_HIDE, NULL); ActiveStateChanged(FALSE); }
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); }
// Attach the created control to a window and activate it HRESULT CControlSite::Attach(HWND hwndParent, const RECT &rcPos, IUnknown *pInitStream) { TRACE_METHOD(CControlSite::Attach); if (hwndParent == NULL) { NS_ASSERTION(0, "No parent hwnd"); return E_INVALIDARG; } m_hWndParent = hwndParent; m_rcObjectPos = rcPos; // Object must have been created if (m_spObject == NULL) { return E_UNEXPECTED; } m_spIViewObject = m_spObject; m_spIOleObject = m_spObject; if (m_spIOleObject == NULL) { return E_FAIL; } DWORD dwMiscStatus; m_spIOleObject->GetMiscStatus(DVASPECT_CONTENT, &dwMiscStatus); if (dwMiscStatus & OLEMISC_SETCLIENTSITEFIRST) { m_bSetClientSiteFirst = TRUE; } if (dwMiscStatus & OLEMISC_INVISIBLEATRUNTIME) { m_bVisibleAtRuntime = FALSE; } // Some objects like to have the client site as the first thing // to be initialised (for ambient properties and so forth) if (m_bSetClientSiteFirst) { m_spIOleObject->SetClientSite(this); } // If there is a parameter list for the object and no init stream then // create one here. CPropertyBagInstance *pPropertyBag = NULL; if (pInitStream == NULL && m_ParameterList.GetSize() > 0) { CPropertyBagInstance::CreateInstance(&pPropertyBag); pPropertyBag->AddRef(); for (unsigned long i = 0; i < m_ParameterList.GetSize(); i++) { pPropertyBag->Write(m_ParameterList.GetNameOf(i), const_cast<VARIANT *>(m_ParameterList.GetValueOf(i))); } pInitStream = (IPersistPropertyBag *) pPropertyBag; } // Initialise the control from store if one is provided if (pInitStream) { CComQIPtr<IPropertyBag, &IID_IPropertyBag> spPropertyBag = pInitStream; CComQIPtr<IStream, &IID_IStream> spStream = pInitStream; CComQIPtr<IPersistStream, &IID_IPersistStream> spIPersistStream = m_spIOleObject; CComQIPtr<IPersistPropertyBag, &IID_IPersistPropertyBag> spIPersistPropertyBag = m_spIOleObject; if (spIPersistPropertyBag && spPropertyBag) { spIPersistPropertyBag->Load(spPropertyBag, NULL); } else if (spIPersistStream && spStream) { spIPersistStream->Load(spStream); } } else { // Initialise the object if possible CComQIPtr<IPersistStreamInit, &IID_IPersistStreamInit> spIPersistStreamInit = m_spIOleObject; if (spIPersistStreamInit) { spIPersistStreamInit->InitNew(); } } m_spIOleInPlaceObject = m_spObject; m_spIOleInPlaceObjectWindowless = m_spObject; m_spIOleInPlaceObject->SetObjectRects(&m_rcObjectPos, &m_rcObjectPos); // In-place activate the object if (m_bVisibleAtRuntime) { DoVerb(OLEIVERB_INPLACEACTIVATE); } // For those objects which haven't had their client site set yet, // it's done here. if (!m_bSetClientSiteFirst) { m_spIOleObject->SetClientSite(this); } return S_OK; }