none
Create an app to show slide.when I click 'Esc' to quit 'Slide Show',PPT quit,too.It is the question. RRS feed

  • Question

  • creating an ATL control to play ppt to show slide or save ppt(office 2013 ver).then embedded into MFC Dialog. when i click 'Esc' to quit slide show,ppt quit too,it is not my mind.i just want to quit slide show,do not want to quit ppt. i do not know how to solve this problem,could anybody help me

    Sample code like these:

    BOOL CInstanceFactory::OpenOfficeDoc(REFCLSID rclsid,const CString &strPath)
    {

            pItem = new CAxDocConCntrItem(pDoc);
            ASSERT_VALID(pItem);
            CString strPath1 = strPath;
            LPCTSTR lpszPath1 = strPath1.GetBuffer();
            pItem->CreateFromFile(lpszPath1, rclsid,OLERENDER_DRAW,CF_TEXT,NULL);    

            m_pItem = pItem;

            LPDISPATCH lpDisp = m_pItem->GetDispatch_PowerPoint();
            PowerPoint::_PresentationPtr  _appPresent = lpDisp;
            DocumentWindowsPtr docsPtr = _appPresent->GetWindows();
            PowerPoint::SlideShowSettingsPtr appSlideRun = _appPresent->GetSlideShowSettings();
            SlideShowWindowPtr slideShowWidnowPtr = appSlideRun->Run();
            slideShowWidnowPtr->Activate();

    }

    BOOL CAxDocConCntrItem::CreateFromFile(LPCTSTR lpszFileName, REFCLSID clsid,
        OLERENDER render, CLIPFORMAT cfFormat, LPFORMATETC lpFormatEtc)

    {

        SCODE sc = ::OleCreateFromFile(clsid, T2COLE(lpszFileName),
            IID_IUnknown, render, lpFormatEtc, m_lpClientSite, m_lpStorage,
            (LPLP)&m_lpObject);

    }


    Monday, November 23, 2015 8:28 AM

All replies

  • Hi qiuyx,

    >> creating an ATL control to play ppt to show slide or save ppt(office 2013 ver).then embedded into MFC Dialog. when i click 'Esc' to quit slide show,ppt quit too

    I made a test with ppt automation, and it would not quit ppt application when click “Esc”. Based on your description, your ppt embedded into MFC Dialog, I assume it might be related with how you embedded ppt into MFC dialog. Could you share us details steps and code to reproduce your issue?

    Best Regards,

    Edward


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.


    Wednesday, November 25, 2015 6:54 AM
  • OK,Thank you!

    Here are my codes:

    First,In my MFC test dialog,open office.

    void CtesterDlg::OnBnClickedBtnopen()
    {    
        CWnd *pCWnd = GetDlgItem(IDC_EXT2);
        if (pCWnd)
        {
            CComPtr<IUnknown> spUnk = NULL;
            spUnk = pCWnd->GetControlUnknown();
            if (NULL != spUnk)
            {
                spUnk->QueryInterface(IID_IEmbOleObjControl,(void**)&m_pCtrl);//CComPtr<IEmbOleObjControl> m_pCtrl;
            }
        }

        CString strInfo=_T("D://1.pptx");
        CComBSTR bstrFile(strInfo);
        m_pCtrl->OpenFile(bstrFile.m_str);
    }

    then,ATL control,IEmbOleObjControl Interface

    STDMETHODIMP CEmbOleObjControl::OpenFile(BSTR strFileName)
    {
        AFX_MANAGE_STATE(AfxGetStaticModuleState());

        CLSID clsid;
        CWnd * pMainFrm;
        if (NULL==m_pOfficeBase)
        {
            ::CLSIDFromProgID(L"PowerPoint.Application", &clsid);
            m_pOfficeBase = new CMSPpt((HWND)m_hWnd);
            m_pOfficeBase->SetContainerInfo(IDR_CNTR_INPLACE);
            m_pOfficeBase->OpenDocumentFile(NULL);

            pMainFrm =AfxGetMainWnd();
            ATLASSERT(pMainFrm);
            pMainFrm->UpdateWindow();
            m_pOfficeBase->OpenOfficeDoc(clsid,CString(strFileName));
        }

        return S_OK;
    }

    BOOL CMSPpt::OpenOfficeDoc(REFCLSID rclsid,const CString &strPath)
    {
    //...
        BeginWaitCursor();    
        CAxDocConCntrItem* pItem = NULL;
        TRY
        {
            pItem = new CAxDocConCntrItem(pDoc);
            ASSERT_VALID(pItem);
            CString strPath1 = strPath;
            LPCTSTR lpszPath1 = strPath1.GetBuffer();
            pItem->CreateFromFile(lpszPath1, rclsid);

            VERIFY(pItem->DoVerb(OLEIVERB_SHOW, pView));
            IPersistFile *pPersistFile = NULL;
             int nStyle = GetWindowLong(m_wndOwner.m_hWnd, GWL_STYLE);
            
            ASSERT_VALID(pItem);
            pDoc->UpdateAllViews(NULL);
        }
    //...
    }

    BOOL CAxDocConCntrItem::CreateFromFile(LPCTSTR lpszFileName, REFCLSID clsid,
        OLERENDER render, CLIPFORMAT cfFormat, LPFORMATETC lpFormatEtc)
    {
    //...
        SCODE sc = ::OleCreateFromFile(clsid, T2COLE(lpszFileName),
            IID_IUnknown, render, lpFormatEtc, m_lpClientSite, m_lpStorage,
            (LPLP)&m_lpObject);
    //...
    }

    Second,show my presentaiton

    void CtesterDlg::OnBnClickedPlay()
    {
        // TODO: 在此添加控件通知处理程序代码
        if (m_pCtrl)
        {
            m_hInstance = AfxGetInstanceHandle();    
            m_pCtrl->Play();
        }
    }

    void CMSPpt::Play()
    {
        LPDISPATCH lpDisp = m_pItem->GetDispatch_PowerPoint();
        if (lpDisp/*0*/)
        {
            PowerPoint::_PresentationPtr  _appPresent = lpDisp;    
             DocumentWindowsPtr docsPtr = _appPresent->GetWindows();
            PowerPoint::_PresentationPtr pp = docsPtr->Application->ActivePresentation;
            PowerPoint::SlideShowSettingsPtr appSlideRun = _appPresent->GetSlideShowSettings();
            SlideShowWindowPtr slideShowWidnowPtr = appSlideRun->Run();        
            
            HWND hDecWnd = ::FindWindow(_T("screenClass"), 0);        
             int nStyle = GetWindowLong(hDecWnd, GWL_STYLE);
            int nNewStyle = nStyle & (~WS_MINIMIZEBOX)
                & (~WS_MAXIMIZEBOX) & (~WS_SYSMENU)
            |WS_CAPTION & (~WS_THICKFRAME) & (~CS_NOCLOSE);
            SetWindowLong(m_hDecWnd,GWL_STYLE,nNewStyle);

            if (NULL != hDecWnd)
            {
                CWnd *pWnd;
                CRect rect;
                m_wndOwner.GetClientRect(&rect);
                ::SetParent(hDecWnd, m_wndOwner.GetSafeHwnd());
                pWnd = CWnd::FromHandle(m_hDecWnd);
                rect.SetRect(0, 0, rect.Width(), rect.Height());
                pWnd->MoveWindow(&rect);
            }
         }
    }

    If it's not in detail,i can sent my sourse code to you if you can,my email is 389501427@qq.com.Thanks a lot,since it took me a long time .


    Wednesday, November 25, 2015 7:55 AM
  • Hi qiuyx,

    When you use “VERIFY(pItem->DoVerb(OLEIVERB_SHOW, pView));”, was the ppt file in Slide Show mode or Normal mode? If it is in Slide Show mode, PPT application would exist when you press “Esc”. I suggest you try “OLEIVERB_OPEN”. OLEIVERB_OPEN opens the file for editing in a window separate from that of its container. With Normal mode, you will need to get ppt object, and set it as Slide Show mode with automation if you want it in Slide Show mode.

    # IOleObject::DoVerb method
    https://msdn.microsoft.com/en-us/library/windows/desktop/ms694508%28v=vs.85%29.aspx?f=255&MSPPError=-2147217396

    Best Regards,

    Edward


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.



    Thursday, November 26, 2015 6:23 AM
  • Hi Edward Z,
    It didn't work.Both OLEIVERB_OPEN and OLEIVERB_SHOW run in Normal mode.

    My requirement is operateing ppt which should be embbed in to dialog through my  MFC dialog:open ppt,save ppt,add slide,add 3d models,slide show by calling the method 'run' ,and so on.I don't want slide show when I open the ppt .they all work well except calling the method 'run',when slide show end, issue occurs,ppt quit.

    I try other way to create project,but  don't meet my needs.
    Thursday, November 26, 2015 9:23 AM