Microsoft Knowledge Base Email Alertz

KBAlertz.com: (308336) - This article demonstrates how to create a PowerPoint Presentation and run a slide show from Visual C++ .NET and Microsoft Foundation Classes (MFC).

Receive Microsoft Knowledge Base articles by E-Mail?

Every night we scan the Microsoft Knowledge Base. If technologies you're interested in are updated, we'll send you an e-mail. You only get one e-mail a day, and only when new articles are added.

Click here to create a
FREE account
Already have an account?
[Click here to Login]

Search KbAlertz

Advanced Search

Webmasters
Put kbAlertz on your website.
[ Click Here for more! ]





ASP.NET 3.5 Web Hosting with Windows 2008 and SQL 2008: Click Here!
Discount ASP.NET Hosting
ASP.NET 2.0 and 3.5
Windows2008 and SQL2008
US and UK Hosting
The ad says 3 - but KBAlertz referrals get
** SIX MONTHS FREE **


Bug Tracking Software
For bug tracking software or defect tracking software or issue tracking software, visit Axosoft.


Community Site



We Send hundreds of thousands of emails using ASP.NET Email



Expert Web Design & Graphic Design
Design44.com

ASP.NET 3.5 Web Hosting with Windows 2008 and SQL 2008: Click Here!
Discount ASP.NET Hosting
ASP.NET 2.0 and 3.5
Windows2008 and SQL2008
US and UK Hosting
The ad says 3 - but KBAlertz referrals get
** SIX MONTHS FREE **




Mentioned In








Microsoft Knowledge Base Article

This article contents is Microsoft Copyrighted material.
©2005-©2007 Microsoft Corporation. All rights reserved. Terms of Use | Trademarks




Article ID: 308336 - Last Review: June 29, 2007 - Revision: 5.2

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

This article was previously published under Q308336
For a Microsoft Visual Basic .NET version of this article, see 303717  (http://kbalertz.com/Feedback.aspx?kbNumber=303717/ ) .
For a Microsoft C# .NET version of this article, see 303718  (http://kbalertz.com/Feedback.aspx?kbNumber=303718/ ) .

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  (http://kbalertz.com/Feedback.aspx?kbNumber=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 (http://msdn2.microsoft.com/en-us/library/aa188489(office.10).aspx)

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: 
kbautomation kbhowto KB308336
       

Community Feedback System

Very often, it takes hours to solve a problem. Very often, you've looked high and low, and have tried a lot of solutions. When you finally found it, chances are, it was because someone else helped you. Here's your chance to give back. Use our community feedback tool to let others know what worked for you and what didn't.

Please also understand that the community feedback system is not warranted to be correct, it's simply a system that we've built to let people try and help each other. If something in a feedback response doesn't make sense to you, or you're not comfortable making changes that the feedback talks about (like registry edits), please consult a professional.

Thank you for using kbAlertz.com Feedback System.

-- Scott Cate

Be the first to leave feedback, to help others about this knowledge base article.

(Optional) Name

(Optional) Public URL Or Email

Comments
No HTML -- Text Only Please