How to use Automation to create and to show a PowerPoint 2000 presentation or a PowerPoint 2002 presentation by using Visual C++ .NET 2002 or Visual C++ .NET 2003 and Microsoft Foundation Classes

Article translations Article translations
Article ID: 308336 - View products that this article applies to.
This article was previously published under Q308336
This article has been archived. It is offered "as is" and will no longer be updated.
For a Microsoft Visual Basic .NET version of this article, see 303717.
For a Microsoft C# .NET version of this article, see 303718.
Expand all | Collapse all

On This Page

Note Microsoft Visual C++ .NET 2002 and Microsoft Visual C++ .NET 2003 support both the managed code model that is provided by the Microsoft .NET Framework and the unmanaged native Microsoft Windows code model. The information in this article applies only to unmanaged Visual C++ code.

SUMMARY

This article describes how to use Automation to create and to show a Microsoft PowerPoint 2000 presentation or a PowerPoint 2002 presentation by using Microsoft Visual C++ .NET 2002 or Visual C++ .NET 2003 and Microsoft Foundation Classes.

MORE INFORMATION

Build the Automation sample

  1. Follow the steps in the "Create an Automation Client" section of the following Microsoft Knowledge Base article to create a basic Automation client:
    307473 How to use a type library for Office Automation from Visual C++ .NET
    In step 4 of the article, select the Microsoft PowerPoint type library and the Microsoft Graph type library. The default location for PowerPoint 2000 is C:\Program Files\Microsoft Office\Office\Msppt9.olb, the default location for PowerPoint 2002 is C:\Program Files\Microsoft Office\Office10\Msppt.olb, and the default location for Microsoft Office PowerPoint 2003 is C:\Program Files\Microsoft Office\Office11\Msppt.olb. The default location for Graph 2000 is C:\Program Files\Microsoft Office\Office\graph9.olb, the default location for Graph 2002 is C:\Program Files\Microsoft Office\Office10\Graph.exe, and the default location for Graph 2003 is C:\Program Files\Microsoft Office\Office11\Graph.exe. Then select the following PowerPoint interfaces:
    • _Application
    • _Presentation
    • _Slide
    • Font
    • OleFormat
    • Presentations
    • ShadowFormat
    • Shape
    • Shapes
    • SlideRange
    • Slides
    • SlideShowSettings
    • SlideShowTransition
    • SlideShowWindows
    • TextFrame
    • TextRange
    Select the following Graph interface:
    • Chart

    In step 6, add the following #include statements to 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. In the IDD_AUTOPROJECT_DIALOG dialog box, right-click Run and select Add event handler. In the Event Handler Wizard, select the BN_CLICKED message type and then click Add and Edit.
  3. Replace the following code
    void CAutoProjectDlg::OnBnClickedRun()
    {
    	// TODO: Add your control notification handler code here
    }
    					
    with:
    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();
    	}
    }
    					
    Note Modify the strPresentationTemplate and strPicture constants to point to the full path and file name of a PowerPoint template and a picture.

  4. Press F5 to build and run the program.
  5. Click the Run button to start PowerPoint, create the presentation, and run the slide show.

REFERENCES

For more information, see the following Microsoft Developer Network (MSDN) Web site:
Microsoft Office Development with Visual Studio
http://msdn2.microsoft.com/en-us/library/aa188489(office.10).aspx

Properties

Article ID: 308336 - Last Review: February 27, 2014 - Revision: 5.3
APPLIES TO
  • 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
Keywords: 
kbnosurvey kbarchive kbautomation kbhowto KB308336

Give Feedback

 

Contact us for more help

Contact us for more help
Connect with Answer Desk for expert help.
Get more support from smallbusiness.support.microsoft.com