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); }
void test_CShellMenu_params() { HRESULT hResult; IShellMenu* shellMenu; IDockingWindow* dockingMenu; IObjectWithSite* menuWithSite; IShellMenuCallback *psmc; UINT uId; UINT uIdAncestor; DWORD dwFlags; HWND hwndToolbar; HMENU hmenu; HWND hwndOwner; DWORD menuFlagss; IShellFolder *shellFolder; if (!CreateCShellMenu(&shellMenu, &dockingMenu, &menuWithSite)) { skip("failed to create CShellMenuObject\n"); return; } hResult = shellMenu->Initialize(NULL, 11, 22, 0xdeadbeef); test_S_OK(hResult, "Initialize failed"); hResult = shellMenu->GetMenuInfo(&psmc, &uId, &uIdAncestor, &dwFlags); test_S_OK(hResult, "GetMenuInfo failed"); ok (psmc == NULL, "wrong psmc\n"); ok (uId == 11, "wrong uid\n"); ok (uIdAncestor == 22, "wrong uIdAncestor\n"); ok (dwFlags == 0xdeadbeef, "wrong dwFlags\n"); hResult = shellMenu->Initialize(NULL, 0, ANCESTORDEFAULT, SMINIT_TOPLEVEL|SMINIT_VERTICAL); test_S_OK(hResult, "Initialize failed"); hResult = dockingMenu->GetWindow(&hwndToolbar); test_HRES(hResult, E_FAIL, "GetWindow should fail"); hResult = shellMenu->GetMenu(&hmenu, &hwndOwner, &menuFlagss); test_HRES(hResult, E_FAIL, "GetMenu should fail"); hmenu = CreatePopupMenu(); hResult = shellMenu->SetMenu(hmenu, NULL, 0); test_S_OK(hResult, "SetMenu failed"); hwndToolbar = (HWND)UlongToPtr(0xdeadbeef); hResult = dockingMenu->GetWindow(&hwndToolbar); test_S_OK(hResult, "GetWindow failed"); ok (hwndToolbar == NULL, "Expected NULL window\n"); hResult = shellMenu->SetMenu(NULL, NULL, 0); test_S_OK(hResult, "SetMenu failed"); hResult = shellMenu->GetMenu(&hmenu, &hwndOwner, &menuFlagss); test_S_OK(hResult, "GetMenu failed"); ok (hmenu == NULL, "Got a menu\n"); hResult = dockingMenu->GetWindow(&hwndToolbar); test_S_OK(hResult, "GetWindow failed"); hResult = SHGetDesktopFolder(&shellFolder); test_S_OK(hResult, "SHGetDesktopFolder failed"); hResult = shellMenu->SetShellFolder(shellFolder, NULL, 0, 0); test_S_OK(hResult, "SetShellFolder failed"); hResult = shellMenu->SetShellFolder(NULL, NULL, 0, 0); test_HRES(hResult, E_INVALIDARG, "SetShellFolder should fail"); hwndToolbar = (HWND)UlongToHandle(0xdeadbeef); hResult = dockingMenu->GetWindow(&hwndToolbar); test_S_OK(hResult, "GetWindow failed"); ok (hwndToolbar == NULL, "Expected NULL window\n"); hResult = dockingMenu->ShowDW(TRUE); test_HRES(hResult, S_FALSE, "ShowDW should fail"); menuWithSite->Release(); dockingMenu->Release(); shellMenu->Release(); }
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); } }
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; }