辐射4爆裂物散弹枪在哪:VC操作PowerPoint

来源:百度文库 编辑:九乡新闻网 时间:2024/04/28 01:08:31

主要内容包括:启动、打开、关闭、幻灯片播放、首页、末页、上一页、下一页等。
本代码以PowerPoint 2003为例,其他OFFICE组件及版本方法与此类似。

下面是主要步骤和代码:
1、创建MFC对话框应用程序,在向导的第2步选择automation,其他保持默认即可。

2、在对话框上添加启动、打开、关闭、幻灯片播放、首页、末页、上一页、下一页等按钮及函数。

3、在应用程序的InitInstance()中初始化OLE,代码如下:
// Initialize OLE libraries
if (!AfxOleInit())
{
AfxMessageBox("Failed to initialize OLE");
return FALSE;
}

4、运用类向导添加PowerPoint类型库,类型库默认在"C:\Program Files\Microsoft Office\Office11\"下,文件名为:msppt.olb。

5、在对话框应用程序的头文件中添加:
#include "msppt.h"

6、在在对话框应用程序的头文件中添加如下变量:
_Application app;
Presentations Presentations;
_Presentation Presentation;
SlideShowView View;
SlideShowWindow SlideShowWindow;
SlideShowSettings slideshow;
Slides slides;
_Slide slide;
DocumentWindow documentwindow;
View ActiveView;

7、在启动按钮函数中添加如下代码:
void CXXXDlg::OnBtnStart()
{
// Start PowerPoint and get Application object...
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!");
}
}

8、在打开按钮函数中添加如下代码:
void CXXXDlg::OnBtnOpen()
{
static char BASED_CODE szFilter[] = "PowerPoint Files (*.ppt)|*.ppt||";
CFileDialog FileDlg(TRUE,"PPT",NULL,OFN_FILEMUSTEXIST|OFN_NONETWORKBUTTON
|OFN_PATHMUSTEXIST,szFilter);
FileDlg.DoModal();

// To get the selected file's path and name
CString strFileName;
strFileName = FileDlg.GetPathName();

if(!strFileName.IsEmpty())
{
Presentations = app.GetPresentations();
Presentation = Presentations.Open(strFileName,0,0,1);
}
}

9、在关闭按钮函数中添加如下代码:
void CXXXDlg::OnBtnClose()
{
documentwindow=app.GetActiveWindow();//获得活动的文档
documentwindow.Close();//关闭当前活动的文档
if (CanExit())
app.Quit();
}

10、在运行按钮函数中添加如下代码:
void CXXXDlg::OnBtnRun()
{
Presentations = app.GetActivePresentation();
slides = Presentation.GetSlides();
// Show the first slide of the presentation
slide = slides.Item(COleVariant((long)1));

//Run the show
slideshow = Presentation.GetSlideShowSettings();
slideshow.Run();
}

11、在翻到首页按钮函数中添加如下代码:
void CXXXDlg::OnBtnFirst()
{
Presentation = app.GetActivePresentation();
SlideShowWindow = Presentation.GetSlideShowWindow();
View = SlideShowWindow.GetView();
View.First();
}

12、在翻到末叶按钮函数中添加如下代码:
void CXXXDlg::OnBtnLast()
{
Presentation = app.GetActivePresentation();
SlideShowWindow = Presentation.GetSlideShowWindow();
View = SlideShowWindow.GetView();
View.Last();
}

13、在翻到前页按钮函数中添加如下代码:
void CXXXDlg::OnBtnPrevious()
{
Presentation = app.GetActivePresentation();
SlideShowWindow = Presentation.GetSlideShowWindow();
View = SlideShowWindow.GetView();
View.Previous();
}

14、在翻到下页按钮函数中添加如下代码:
void CXXXDlg::OnBtnNext()
{
Presentation = app.GetActivePresentation();
SlideShowWindow = Presentation.GetSlideShowWindow();
View = SlideShowWindow.GetView();
View.Next();
}

15.获得幻灯片总数
void CXXXDlg::OnBtnGetSlidesCount()
{

Presentations=app.GetActivePresentation();

slides=Presentation.GetSlides();

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

 

其实我还是不懂

哪位高手再给点详细的操作

 

把ppt中的内容在内存中转化为bmp图像,然后在窗口中显示出来

PowerPoint使用SaveCopyAs方法指定保存BMP文件

将PowerPoint的库用#import导入vc就行了(就像使用ado连接数据库一样),会生成一个类。
其中各个函数的用法可以参照vb。