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();
}
}