求助各位大虾:
小弟刚入门MFC编程,要实现office中PPT的自动评分,目前到第4步卡住了:
1.添加ppt类型库文件,"msppt.olb"(office 2003中)。
2.头文件 #include “msppt.h”。
3.在应用程序中,InitInstance函数中,添加.....
4.In 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; 就是在第4步卡住了,我不知道在哪个头文件声明第4步,“msppt.h”和对话框头文件我都试过了,
希望大虾能帮我一下,最好能截图给我,发给我邮箱[email protected]里面,交流一下,再次感谢!
小弟刚入门MFC编程,要实现office中PPT的自动评分,目前到第4步卡住了:
1.添加ppt类型库文件,"msppt.olb"(office 2003中)。
2.头文件 #include “msppt.h”。
3.在应用程序中,InitInstance函数中,添加.....
4.In 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; 就是在第4步卡住了,我不知道在哪个头文件声明第4步,“msppt.h”和对话框头文件我都试过了,
希望大虾能帮我一下,最好能截图给我,发给我邮箱[email protected]里面,交流一下,再次感谢!
感谢你的回复,只有_Application app;能够声明有效,其他都显示未声明!
我原本是提问的,现在变答问了,VC++6.0里面的操作是:类向导->Automation->from a type lib->C:\Program Files\Microsoft Office\office11->添加确定,生成msppt.h和msppt.cpp
嗯,操作之后只有一个_Application,查了一些资料好像还要添加其他的类,请问下其余的怎么添加进去?
向老师留个邮箱或QQ吧,这样来去回复时间很浪费,我的是[email protected],谢谢你啊!
你是好人,回复了这么多,能否详细一些,我博客转载的有VC操作PPT,能否帮忙编写一下,以便改正我上面还未解决的问题!
本代码以PowerPoint 2003为例,其他OFFICE组件及版本方法与此类似。
下面是主要步骤和代码:
1、创建MFC对话框应用程序,在向导的第3步选择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 "msppt8.h"
6、在在对话框应用程序的头文件中添加如下变量:
_Application app;
Presentations Presentations;
_Presentation Presentation;
SlideShowView View;
SlideShowWindow SlideShowWindow;
SlideShowSettings slideshow;
Slides slides;
_Slide slide;
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()
{
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();
}