⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 embed_pptview.cpp

📁 此程序运用MFC嵌入微软office的PPT功能
💻 CPP
字号:
// Embed_PPTView.cpp : implementation of the CEmbed_PPTView class
//

#include "stdafx.h"
#include "Embed_PPT.h"

#include "Embed_PPTDoc.h"
#include "CntrItem.h"
#include "Embed_PPTView.h"
#include "msppt.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CEmbed_PPTView

IMPLEMENT_DYNCREATE(CEmbed_PPTView, CView)

BEGIN_MESSAGE_MAP(CEmbed_PPTView, CView)
	//{{AFX_MSG_MAP(CEmbed_PPTView)
		// NOTE - the ClassWizard will add and remove mapping macros here.
		//    DO NOT EDIT what you see in these blocks of generated code!
	ON_WM_DESTROY()
	ON_WM_SETFOCUS()
	ON_WM_SIZE()
	ON_COMMAND(ID_OLE_INSERT_NEW, OnInsertObject)
	ON_COMMAND(ID_CANCEL_EDIT_CNTR, OnCancelEditCntr)
	//}}AFX_MSG_MAP
	// Standard printing commands
	ON_COMMAND(ID_FILE_PRINT, CView::OnFilePrint)
	ON_COMMAND(ID_FILE_PRINT_DIRECT, CView::OnFilePrint)
	ON_COMMAND(ID_FILE_PRINT_PREVIEW, CView::OnFilePrintPreview)
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CEmbed_PPTView construction/destruction

CEmbed_PPTView::CEmbed_PPTView()
{
	m_pSelection = NULL;
	// TODO: add construction code here

}

CEmbed_PPTView::~CEmbed_PPTView()
{
}

BOOL CEmbed_PPTView::PreCreateWindow(CREATESTRUCT& cs)
{
	// TODO: Modify the Window class or styles here by modifying
	//  the CREATESTRUCT cs

	return CView::PreCreateWindow(cs);
}

/////////////////////////////////////////////////////////////////////////////
// CEmbed_PPTView drawing

void CEmbed_PPTView::OnDraw(CDC* pDC)
{
		CEmbed_PPTDoc*   pDoc   =   GetDocument();     
  ASSERT_VALID(pDoc);     
  if   (m_pSelection   ==   NULL)     
  {     
  POSITION   pos   =   pDoc->GetStartPosition();     
  m_pSelection   =   (CEmbed_PPTCntrItem*)pDoc->GetNextClientItem(pos);     
  }     
  if   (m_pSelection   !=   NULL)     
  {     
  CRect   rect;     
  GetClientRect(&m_pSelection->rect);     
  m_pSelection->OnGetItemPosition(rect);     
  m_pSelection->Draw(pDC,rect);       
  }     
}

void CEmbed_PPTView::OnInitialUpdate()
{
	CView::OnInitialUpdate();


	// TODO: remove this code when final selection model code is written

  EmbedAutomatePPT();   //将Word嵌入     
  //m_pSelection   =   NULL;    
	m_pSelection = NULL;    // initialize selection

}

/////////////////////////////////////////////////////////////////////////////
// CEmbed_PPTView printing

BOOL CEmbed_PPTView::OnPreparePrinting(CPrintInfo* pInfo)
{
	// default preparation
	return DoPreparePrinting(pInfo);
}

void CEmbed_PPTView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
	// TODO: add extra initialization before printing
}

void CEmbed_PPTView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
	// TODO: add cleanup after printing
}

void CEmbed_PPTView::OnDestroy()
{
	// Deactivate the item on destruction; this is important
	// when a splitter view is being used.
   CView::OnDestroy();
   COleClientItem* pActiveItem = GetDocument()->GetInPlaceActiveItem(this);
   if (pActiveItem != NULL && pActiveItem->GetActiveView() == this)
   {
      pActiveItem->Deactivate();
      ASSERT(GetDocument()->GetInPlaceActiveItem(this) == NULL);
   }
}


/////////////////////////////////////////////////////////////////////////////
// OLE Client support and commands

BOOL CEmbed_PPTView::IsSelected(const CObject* pDocItem) const
{
	// The implementation below is adequate if your selection consists of
	//  only CEmbed_PPTCntrItem objects.  To handle different selection
	//  mechanisms, the implementation here should be replaced.

	// TODO: implement this function that tests for a selected OLE client item

	return pDocItem == m_pSelection;
}

void CEmbed_PPTView::OnInsertObject()
{
	// Invoke the standard Insert Object dialog box to obtain information
	//  for new CEmbed_PPTCntrItem object.
	COleInsertDialog dlg;
	if (dlg.DoModal() != IDOK)
		return;

	BeginWaitCursor();

	CEmbed_PPTCntrItem* pItem = NULL;
	TRY
	{
		// Create new item connected to this document.
		CEmbed_PPTDoc* pDoc = GetDocument();
		ASSERT_VALID(pDoc);
		pItem = new CEmbed_PPTCntrItem(pDoc);
		ASSERT_VALID(pItem);

		// Initialize the item from the dialog data.
		if (!dlg.CreateItem(pItem))
			AfxThrowMemoryException();  // any exception will do
		ASSERT_VALID(pItem);
		
        if (dlg.GetSelectionType() == COleInsertDialog::createNewItem)
			pItem->DoVerb(OLEIVERB_SHOW, this);

		ASSERT_VALID(pItem);

		// As an arbitrary user interface design, this sets the selection
		//  to the last item inserted.

		// TODO: reimplement selection as appropriate for your application

		m_pSelection = pItem;   // set selection to last inserted item
		pDoc->UpdateAllViews(NULL);
	}
	CATCH(CException, e)
	{
		if (pItem != NULL)
		{
			ASSERT_VALID(pItem);
			pItem->Delete();
		}
		AfxMessageBox(IDP_FAILED_TO_CREATE);
	}
	END_CATCH

	EndWaitCursor();
}

// The following command handler provides the standard keyboard
//  user interface to cancel an in-place editing session.  Here,
//  the container (not the server) causes the deactivation.
void CEmbed_PPTView::OnCancelEditCntr()
{
	// Close any in-place active item on this view.
	COleClientItem* pActiveItem = GetDocument()->GetInPlaceActiveItem(this);
	if (pActiveItem != NULL)
	{
		pActiveItem->Close();
	}
	ASSERT(GetDocument()->GetInPlaceActiveItem(this) == NULL);
}

// Special handling of OnSetFocus and OnSize are required for a container
//  when an object is being edited in-place.
void CEmbed_PPTView::OnSetFocus(CWnd* pOldWnd)
{
	COleClientItem* pActiveItem = GetDocument()->GetInPlaceActiveItem(this);
	if (pActiveItem != NULL &&
		pActiveItem->GetItemState() == COleClientItem::activeUIState)
	{
		// need to set focus to this item if it is in the same view
		CWnd* pWnd = pActiveItem->GetInPlaceWindow();
		if (pWnd != NULL)
		{
			pWnd->SetFocus();   // don't call the base class
			return;
		}
	}

	CView::OnSetFocus(pOldWnd);
}

void CEmbed_PPTView::OnSize(UINT nType, int cx, int cy)
{
	CView::OnSize(nType, cx, cy);
	COleClientItem* pActiveItem = GetDocument()->GetInPlaceActiveItem(this);
	if (pActiveItem != NULL)
		pActiveItem->SetItemRects();
}

/////////////////////////////////////////////////////////////////////////////
// CEmbed_PPTView diagnostics

#ifdef _DEBUG
void CEmbed_PPTView::AssertValid() const
{
	CView::AssertValid();
}

void CEmbed_PPTView::Dump(CDumpContext& dc) const
{
	CView::Dump(dc);
}

CEmbed_PPTDoc* CEmbed_PPTView::GetDocument() // non-debug version is inline
{
	ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CEmbed_PPTDoc)));
	return (CEmbed_PPTDoc*)m_pDocument;
}
#endif //_DEBUG

/////////////////////////////////////////////////////////////////////////////
// CEmbed_PPTView message handlers

void CEmbed_PPTView::EmbedAutomatePPT()
{
   BeginWaitCursor();     
  CEmbed_PPTCntrItem*   pItem   =   NULL;     
  TRY     
  {     
  CEmbed_PPTDoc*   pDoc   =   GetDocument();     
  ASSERT_VALID(pDoc);     
  pItem   =   new   CEmbed_PPTCntrItem(pDoc);     
  ASSERT_VALID(pItem);     
  GetClientRect(&pItem->rect);     
  CLSID   clsid;     
  if(FAILED(::CLSIDFromProgID(L"PowerPoint.show",&clsid)))     
  AfxThrowMemoryException();     
  if(!pItem->CreateNewItem(clsid))     
  AfxThrowMemoryException();     
  ASSERT_VALID(pItem);     
  pItem->DoVerb(OLEIVERB_SHOW,   this);     
  m_pSelection   =   pItem;     
  pDoc->UpdateAllViews(NULL);     
  LPDISPATCH   lpDisp;     
  lpDisp   =   pItem->GetIDispatch();     
  }     
  CATCH(CException,   e)     
  {     
  if   (pItem   !=   NULL)     
  {     
  ASSERT_VALID(pItem);     
  pItem->Delete();     
  }     
  AfxMessageBox(IDP_FAILED_TO_CREATE);       
  }     
  END_CATCH     
  EndWaitCursor();     
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -