对ppt文件的一些简单操作

1.添加ppt类型库文件,"msppt.olb"(office 2003中)。

 

2.头文件 #include “msppt.h”

 

3.在应用程序中,InitInstance函数中,添加

if (!AfxOleInit())

{

AfxMessageBox("Failed to initialize OLE");

return FALSE;

}

 

4In header file中,

_Application  app;  //app is the PowerPoint _Application object

 

Presentations  Presentations;  //PPT环境

_Presentation  Presentation;  //打开的PPT文件

 

SlideShowView  View;

 

SlideShowWindow  SlideShowWindow;

SlideShowSettings  slideshow;

 

Slides  slides;

_Slide  slide;

 

5.启动PowerPoint,并获得应用程序对象。

if(!app.CreateDispatch("Powerpoint.Application"))

{

AfxMessageBox("Couldn't start PowerPoint.");

}

else // Make PowerPoint visible and display a message

{

app.SetVisible(TRUE);

TRACE("PowerPoint is Running!");

}

 

6.打开一个ppt文件

   static char BASED_CODE szFilter[] = "PowerPoint Files (*.ppt)|*.ppt||";

CFileDialog FileDlg(TRUE,”PPT”,NULL,OFN_FILEMUSTEXIST |OFN_NONETWORKBUTTON | OFN_PATHMUSTEXIST,szFilter);

FileDlg.DoModal();//打开“打开文件”对话框

Cstring   strFileName;

strFileName = FileDlg.GetPathName(); //获得选择的文件和路径名

if(!strFileName.IsEmpty())

{

Presentations = app.GetPresentations();   //

Presentation = Presentations.Open(strFileName,0,0,1); //打开ppt文件

}

 

7.关闭

           documentwindow=app.GetActiveWindow();//获得活动的文档

              documentwindow.Close();//关闭当前活动的文档

 

if(CanExit())

     app.Quit();  //关闭运行环境

 

8.运行幻灯片

   Presentations = app.GetActivePresentation(); //获得当前活动的窗体

slides = Presentation.GetSlides();    //获得当前活动ppt文件的幻灯片

// Show the first slide of the presentation

slide = slides.Item(COleVariant((long)1)); //显示第一张幻灯片

//Run the show

slideshow = Presentation.GetSlideShowSettings(); //获得幻灯片的设置

slideshow.Run(); //播放幻灯片

 

9.播放第一个或最后一个幻灯片

Presentation = app.GetActivePresentation();

SlideShowWindow = Presentation.GetSlideShowWindow();

View = SlideShowWindow.GetView();

View.First(); //定位到第一个幻灯片

View.Last(); //定位到最后一个幻灯片

View.Previous();//定位到上一个幻灯片

View.Next(); //定位到下一个幻灯片

 

10.获得幻灯片总数

       Presentations=app.GetActivePresentation();

       slides=Presentation.GetSlides();

long endpos=slides.GetCount(); //获得幻灯片总数

 

11.获得当前幻灯片序号

       Presentation=app.GetActivePresentation();

       SlideShowWindow=Presentation.GetSlideShowWindow();

       View=SlideShowWindow.GetView();    

       long Curpos=View.GetCurrentShowPosition();//当前幻灯片序号

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值