文章編號: 308336 - 上次校閱: 2007年6月29日 - 版次: 5.3

如何使用自動化來建立並顯示使用 Visual C++.NET 2002年或 Visual C++.NET 2003年和 MFC 的 PowerPoint 2000 簡報或 PowerPoint 2002 簡報

系統提示本文適用於您使用的作業系統之外的作業系統。與您不相關的文章內容已停用。
本文章的有 Microsoft Visual Basic.NET] 版本請參閱 303717? (http://support.microsoft.com/kb/303717/ )
本文章的有 Microsoft C#.NET] 版本請參閱 303718? (http://support.microsoft.com/kb/303718/ )

在此頁中

全部展開 | 全部摺疊
附註 Microsoft Visual C++.NET 2002年和 Microsoft Visual C++.NET 2003年支援 Managed 程式碼模型所提供的 Microsoft.NET Framework 和不受管理的原生 Microsoft Windows 程式碼模型。本文資訊僅適用於不受管理的 Visual C++ 程式碼。

結論

本文將告訴您,如何使用自動化來建立,並藉由使用 Microsoft Visual C++.NET 2002年或 Visual C++.NET 2003年和 MFC 顯示 Microsoft PowerPoint 2000 簡報或 PowerPoint 2002 簡報。

其他相關資訊

建置自動化範例

  1. 請遵循下列微軟知識庫文件,以建立基本的自動化用戶端 」 建立自動化用戶端 > 一節中步驟:
    307473? (http://support.microsoft.com/kb/307473/ ) 如何使用 Office 自動化在從 Visual C++.NET 型別程式庫
    在 [發行項的步驟 4,選取 Microsoft PowerPoint 型別程式庫和 Microsoft Graph 型別程式庫。PowerPoint 2000 預設的位置是 C:\Program Files\Microsoft Office\Office\Msppt9.olb、 PowerPoint 2002 預設的位置是 C:\Program Files\Microsoft Office\Office10\Msppt.olb 以及 Microsoft Office PowerPoint 2003 預設的位置是 C:\Program Files\Microsoft Office\Office11\Msppt.olb。Graph 2000 預設的位置是 C:\Program Files\Microsoft Office\Office\graph9.olb、 Graph 2002 預設的位置是 C:\Program Files\Microsoft Office\Office10\Graph.exe 而圖表 2003年預設的位置是 C:\Program Files\Microsoft Office\Office11\Graph.exe。然後選取下列 PowerPoint 介面:
    • _Application
    • _Presentation
    • _Slide
    • 字型
    • OleFormat
    • 簡報
    • ShadowFormat
    • 圖形
    • 圖形
    • SlideRange
    • 在投影片
    • SlideShowSettings
    • SlideShowTransition
    • SlideShowWindows
    • TextFrame
    • TextRange
    選取下列的圖表介面:
    • 圖表

    在第 6 步驟將下列的 # include 陳述式加入至 Autoprojectdlg.cpp:
    #include "CApplication.h"
    #include "CPresentations.h"
    #include "CPresentation.h"
    #include "CSlides.h"
    #include "CSlide.h"
    #include "CShapes.h"
    #include "CShape.h"
    #include "CTextFrame.h"
    #include "CTextRange.h"
    #include "CFont0.h"
    #include "COleFormat.h"
    #include "CChart.h"
    #include "CShadowFormat.h"
    #include "CSlideShowTransition.h"
    #include "CSlideRange.h"
    #include "CSlideShowSettings.h"
    #include "CSlideShowWindows.h"
    					
  2. 在 [IDD_AUTOPROJECT_DIALOG] 對話方塊用滑鼠右鍵按一下 [執行],然後選取 [新增事件處理常式。在事件處理常式精靈選取 BN_CLICKED 訊息類型,,然後按一下 [新增及編輯
  3. 取代下列程式碼
    void CAutoProjectDlg::OnBnClickedRun()
    {
    	// TODO: Add your control notification handler code here
    }
    					
    與:
    void CAutoProjectDlg::OnBnClickedRun()
    {
    	CApplication pptApp;
    	CPresentations pptPresentations;
    	CPresentation pptPresentation;
    	CSlides pptSlides;
    	LPDISPATCH pdisptemp = NULL;
    
    
    	//Template for the PowerPoint presentation.
    	const CString strPresentationTemplate("C:\\Program Files\\Microsoft "\ 
    		"Office\\Templates\\Presentation Designs\\Blends.pot");
    
    	//Bmp to put on slide.
    	const CString strPicture("C:\\WINNT\\Soap Bubbles.bmp");
    
    
    	//Automate PowerPoint and get a reference to the
    	//PowerPoint.Application object.
    	if(!pptApp.CreateDispatch("PowerPoint.Application"))
    	{
    		AfxMessageBox("Couldn't start PowerPoint and get Application object.");
    		return;
    	}
    	else
    	{
    		//Make the application visible. 
    		pptApp.put_Visible(TRUE);
    
    		//Get the Presentations collection.
    		pptPresentations =  pptApp.get_Presentations();
    
    		//Open a presentation based on the template.
    		pptPresentation = pptPresentations.Open(strPresentationTemplate, FALSE,
    			TRUE ,TRUE);
    
    		//Get the slides.
    		pptSlides = pptPresentation.get_Slides();
    
    
    		//Build Slide #1:
    		{
    			//PowerPoint.PpSlideLayout.ppLayoutTitleOnly = 11
    			CSlide pptSlide(pptSlides.Add(1,11)); 
    			CShapes slideshapes(pptSlide.get_Shapes());
    			COleVariant varindex(1L);
    			CShape slideshape(slideshapes.Item(varindex));
    			CTextFrame txtFrame(slideshape.get_TextFrame());
    			CTextRange txtrange(txtFrame.get_TextRange());
    
    			//Add text to the slide and format the text.
    			txtrange.put_Text("My Sample Presentation");
    
    			CFont0 objFont(txtrange.get_Font());
    			objFont.put_Name("Comic Sans MS");
    			objFont.put_Size(48);
    
    			//Add the picture to the slide.
    			pdisptemp = slideshapes.AddPicture(strPicture,FALSE, TRUE, 150,
    				150, 500, 350);
    			pdisptemp->Release();
    
    		}
    
    
    		//Build Slide #2:
    		{
    			//PowerPoint.PpSlideLayout.ppLayoutTitleOnly = 11
    			CSlide pptSlide(pptSlides.Add(2,11));  
    			CShapes slideshapes(pptSlide.get_Shapes());
    
    			COleVariant varindex(1L);
    			CShape slideshape(slideshapes.Item(varindex));
    			CTextFrame txtFrame(slideshape.get_TextFrame());
    			CTextRange txtrange(txtFrame.get_TextRange());
    
    			//Add and format text.
    			txtrange.put_Text("My Chart");
    			CFont0 objFont(txtrange.get_Font());
    			objFont.put_Name("Comic Sans MS");
    			objFont.put_Size(48);
    
    			//Add a third pie chart. 
    			CShape slideshape1(slideshapes.AddOLEObject(150,150,480,
    				320,"MSGraph.Chart",NULL,NULL,NULL,NULL,NULL,NULL));
    
    			COLEFormat oleformat(slideshape1.get_OLEFormat());
    			CChart objchart(oleformat.get_Object());
    			objchart.put_ChartType(-4102); // xl3dPie = -4102
    
    		}
    
    		//Build Slide #3:
    		{
    			//Add a text effect to the slide and apply shadows to 
    			//the text effect.
    			//PowerPoint.PpSlideLayout.ppLayoutBlank = 12
    			CSlide pptSlide(pptSlides.Add(3,12));  
    			pptSlide.put_FollowMasterBackground(FALSE);
    
    			CShapes slideshapes(pptSlide.get_Shapes());
    
    			CShape slideshape(slideshapes.AddTextEffect(26,"The End",
    				"Impact",96,FALSE, FALSE,239,200)); //msoTextEffect27 = 26
    			CShadowFormat objShadowFormat(slideshape.get_Shadow()); 
    			objShadowFormat.put_OffsetX(3);
    			objShadowFormat.put_OffsetY(3);
    		}
    
    
    
    		//Modify the slide show transition settings for all 3 slides in
    		//the presentation.
    		for(long count= 1; count <=3 ; count++)
    		{
    			COleVariant varindex(count);
    
    			CSlideRange objslideRange(pptSlides.Range(varindex));
    
    			CSlideShowTransition objSlideshowTransition(
    				objslideRange.get_SlideShowTransition());
    
    			objSlideshowTransition.put_AdvanceOnTime(TRUE);
    			objSlideshowTransition.put_AdvanceTime(3);
    			objSlideshowTransition.put_EntryEffect(3073); //ppEffectBoxOut = 3073
    		}
    
    		CSlideShowSettings objslideshowsettings(
    			pptPresentation.get_SlideShowSettings());
    		objslideshowsettings.put_StartingSlide(1);
    		objslideshowsettings.put_EndingSlide(3);
    
    
    		pdisptemp = objslideshowsettings.Run();
    		pdisptemp->Release();
    		pdisptemp = NULL;
    
    		//Run the slide show and wait for the slide show to end.
    		CSlideShowWindows objSlideShowWindows(pptApp.get_SlideShowWindows());
    		//Do some idle time processing while the show finishes.
    		while(objSlideShowWindows.get_Count() >= 1)
    		{
    			MSG msg;
    			if (PeekMessage(&msg,NULL,0,0,PM_NOREMOVE))
    			{
    				TranslateMessage(&msg);
    				DispatchMessage(&msg);
    			}
    		}
    
    
    		//Close the presentation without saving changes and quit PowerPoint.
    		pptPresentation.put_Saved(TRUE);
    		pptPresentation.Close();
    		pptApp.Quit();
    	}
    }
    					
    筆記 修改為指向完整的路徑和檔案名稱的一個 PowerPoint strPresentationTemplatestrPicture 常數範本和圖片。

  4. 按下 F5 以建置並執行程式。
  5. 按一下 [執行] 按鈕來開始 PowerPoint、 建立在簡報及執行投影片放映]。

?考

如需詳細資訊,請參閱下列 Microsoft 開發人員網路 MSDN 網站:
與 Visual Studio 的 Microsoft Office 程式開發
http://msdn2.microsoft.com/en-us/library/aa188489(office.10).aspx (http://msdn2.microsoft.com/en-us/library/aa188489(office.10).aspx)

這篇文章中的資訊適用於:
  • Microsoft Visual C++ .NET 2002 Standard Edition
  • Microsoft Foundation Class Library 4.2
  • Microsoft PowerPoint 2000 Standard Edition
  • Microsoft PowerPoint 2002 Standard Edition
  • Microsoft Visual C++ .NET 2003 Standard Edition
關鍵字:?
kbmt kbautomation kbhowto KB308336 KbMtzh
機器翻譯機器翻譯
重要:本文是以 Microsoft 機器翻譯軟體翻譯而成,而非使用人工翻譯而成。Microsoft 同時提供使用者人工翻譯及機器翻譯兩個版本的文章,讓使用者可以依其使用語言使用知識庫中的所有文章。但是,機器翻譯的文章可能不盡完美。這些文章中也可能出現拼字、語意或文法上的錯誤,就像外國人在使用本國語言時可能發生的錯誤。Microsoft 不為內容的翻譯錯誤或客戶對該內容的使用所產生的任何錯誤或損害負責。Microsoft也同時將不斷地就機器翻譯軟體進行更新。
按一下這裡查看此文章的英文版本:308336? (http://support.microsoft.com/kb/308336/en-us/ )
Microsoft及(或)其供應商不就任何在本伺服器上發表的文字資料及其相關圖表資訊的恰當性作任何承諾。所有文字資料及其相關圖表均以「現狀」供應,不負任何擔保責任。Microsoft及(或)其供應商謹此聲明,不負任何對與此資訊有關之擔保責任,包括關於適售性、適用於某一特定用途、權利或不侵權的明示或默示擔保責任。Microsoft及(或)其供應商無論如何不對因或與使用本伺服器上資訊或與資訊的實行有關而引起的契約、過失或其他侵權行為之訴訟中的特別的、間接的、衍生性的損害或任何因使用而喪失所導致的之損害、資料或利潤負任何責任。