Article ID: 169505
Article Last Modified on 1/19/2007
C:\Program Files\Microsoft Office\Office
- _Application
- SlideShowSettings
- Presentations
- Slides
- _Slide
- Shapes
- _Presentation
Click OK when you have finished selecting the classes above, and
then click OK to close the MFC ClassWizard.
OnPowerpointStartpowerpoint
Click OK to accept this name.
Variable Type: _Application
Variable Declaration: m_ppt
Access: Private
CMainFrame::CMainFrame()
{
// Create an instance of the PowerPoint application.
m_ppt.CreateDispatch("PowerPoint.Application");
}
void CMainFrame::OnPowerpointStartpowerpoint()
{
// Check if the IDispatch connection exists with PowerPoint,
// if not create one.
if (m_ppt.m_lpDispatch == NULL) {
// Create IDispatch connection to PowerPoint.
m_ppt.CreateDispatch("PowerPoint.Application");
};
// Bring the PowerPoint application to the front.
m_ppt.Activate();
}
Start SlideShow:
void CMainFrame::OnPowerpointStartslideshow()
{
_Presentation oPresentation;
SlideShowSettings oShow;
// Attach to the Active Presentation.
oPresentation.AttachDispatch(m_ppt.GetActivePresentation());
// Attach to the slide-show settings.
oShow.AttachDispatch(oPresentation.GetSlideShowSettings());
// Run the slide show.
oShow.Run();
}
Quit PowerPoint:
void CMainFrame::OnPowerpointQuitpowerpoint()
{
// Check if PowerPoint is still running. If
// PowerPoint is not running, quit PowerPoint
// and release the dispatch pointer.
if(m_ppt.m_lpDispatch != NULL) {
// Quit PowerPoint. Note, the Quit command exits
// PowerPoint without displaying any dialog boxes. So,
// any unsaved data is lost.
m_ppt.Quit();
// Free the dispatch. This sets m_lpDispatch to NULL.
m_ppt.ReleaseDispatch();
};
}
Create Slide:
void CMainFrame::OnPowerpointCreateslide()
{
// Connect to the active presentation. There is no error trapping.
// If the active presentation the framework traps
// the error and displays a message box.
_Presentation ActivePresentation(m_ppt.GetActivePresentation());
// Connect to the slides collection.
Slides oSlides(ActivePresentation.GetSlides());
// This constant is defined in the PowerPoint Object model.
// You can use the Object Browser, with Visual Basic Editor
// (VBE), to look up the different constant values.
const ppLayoutTitleOnly = 11;
// Add a new slide to the presentation. This code adds the new
// slide to the end of the presentation.
oSlides.Add(oSlides.GetCount() + 1l, ppLayoutTitleOnly);
}
Create Presentation:
void CMainFrame::OnPowerpointCreatepresentation()
{
Presentations PresCollection;
// Make sure there is a dispatch pointer for PowerPoint.
if(m_ppt.m_lpDispatch == NULL) {
// Display a message indicating that PowerPoint is not running.
MessageBox("PowerPoint is not running.", "Start PowerPoint");
} else {
// Bring PowerPoint to the front.
m_ppt.Activate();
// Attach the presentations collection to the PresCollection
// variable.
PresCollection.AttachDispatch(m_ppt.GetPresentations());
// Create a new presentation.
PresCollection.Add(1);
};
}
Add Shape:
void CMainFrame::OnPowerpointAddshape()
{
// Connect to the active presentation object.
_Presentation ActivePresentation(m_ppt.GetActivePresentation());
// Connect to the Slides collection object.
Slides oSlides(ActivePresentation.GetSlides());
// Connect to the first slide in the presentation.
long lIndex = 1;
COleVariant SlideNumber(lIndex);
_Slide oSlide(oSlides.Item(SlideNumber));
// Connect to the Shapes collection.
Shapes oShape(oSlide.GetShapes());
// Create the heart shape on the slide.
const long msoShapeHeart = 21;
float l = 50,t = 150,w = 350,h = 350;
oShape.AddShape(msoShapeHeart, l, t, w, h);
}
Additional query words: ppt8 ppt9 ppt10 vba vbe
Keywords: kbprogramming kbhowto kbmacro KB169505