Microsoft KB Archive/308336

= 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 ID: 308336

Article Last Modified on 6/29/2007

-

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

-



This article was previously published under Q308336





For a Microsoft Visual Basic .NET version of this article, see 303717.



For a Microsoft C# .NET version of this article, see 303718.



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.



Build the Automation sample
  Follow the steps in the &quot;Create an Automation Client&quot; 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</li> OleFormat</li> Presentations</li> ShadowFormat</li> Shape</li> Shapes</li> SlideRange</li> Slides</li> SlideShowSettings</li> SlideShowTransition</li> SlideShowWindows</li> TextFrame</li> TextRange</li></ul>

Select the following Graph interface: <ul> Chart</li></ul>

In step 6, add the following #include statements to Autoprojectdlg.cpp: </li> 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.</li>  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;
 * 1) include &quot;CApplication.h&quot;
 * 2) include &quot;CPresentations.h&quot;
 * 3) include &quot;CPresentation.h&quot;
 * 4) include &quot;CSlides.h&quot;
 * 5) include &quot;CSlide.h&quot;
 * 6) include &quot;CShapes.h&quot;
 * 7) include &quot;CShape.h&quot;
 * 8) include &quot;CTextFrame.h&quot;
 * 9) include &quot;CTextRange.h&quot;
 * 10) include &quot;CFont0.h&quot;
 * 11) include &quot;COleFormat.h&quot;
 * 12) include &quot;CChart.h&quot;
 * 13) include &quot;CShadowFormat.h&quot;
 * 14) include &quot;CSlideShowTransition.h&quot;
 * 15) include &quot;CSlideRange.h&quot;
 * 16) include &quot;CSlideShowSettings.h&quot;
 * 17) include &quot;CSlideShowWindows.h&quot;

//Template for the PowerPoint presentation. const CString strPresentationTemplate(&quot;C:\\Program Files\\Microsoft &quot;\        &quot;Office\\Templates\\Presentation Designs\\Blends.pot&quot;);

//Bmp to put on slide. const CString strPicture(&quot;C:\\WINNT\\Soap Bubbles.bmp&quot;);

//Automate PowerPoint and get a reference to the //PowerPoint.Application object. if(!pptApp.CreateDispatch(&quot;PowerPoint.Application&quot;)) {       AfxMessageBox(&quot;Couldn't start PowerPoint and get Application object.&quot;); 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(&quot;My Sample Presentation&quot;);

CFont0 objFont(txtrange.get_Font); objFont.put_Name(&quot;Comic Sans MS&quot;); 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(&quot;My Chart&quot;); CFont0 objFont(txtrange.get_Font); objFont.put_Name(&quot;Comic Sans MS&quot;); objFont.put_Size(48);

//Add a third pie chart. CShape slideshape1(slideshapes.AddOLEObject(150,150,480, 320,&quot;MSGraph.Chart&quot;,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,&quot;The End&quot;, &quot;Impact&quot;,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.

</li> <li>Press F5 to build and run the program.</li> <li>Click the Run button to start PowerPoint, create the presentation, and run the slide show.</li></ol>

<div class="references_section">