VS2013操作PowerPoint,在MFC窗口中打开PPT
来源:互联网 发布:汉王ocr扫描软件 编辑:程序博客网 时间:2024/05/16 01:45
操做PPT的主要内容包括:启动、打开、关闭、幻灯片播放、首页、末页、上一页、下一页等。
本代码以PowerPoint 2013为例,其他OFFICE组件及版本方法与此类似。
一、整体界面如下:
下面是主要步骤和代码:
1.创建MFC对话框应用程序,在向导的第2步选择automation,其他保持默认即可。
2.右击项目,"添加" -> "类" :
3.然后添加PPT的类库(word,excel同理),如下:
选择如下:
4.添加接口(如果不知道用哪个,那就都添加)
确定,将添加了很多头文件到文件里,如下:
主要用到的头文件如下(可以把不想用到的删掉:
5.把以上需要用到的头文件添加到工程的头文件中,并且要把以上添加的每个头文件的import注释掉,如CApplication.h
// Machine generated IDispatch wrapper class(es) created with Add Class from Typelib Wizard
//#import "D:\\Program Files\\Microsoft Office\\OFFICE11\\MSPPT.OLB" no_namespace
// CApplication wrapper class
6.在对话框上添加打开、关闭、首页、末页、上一页、下一页等按钮及函数。
7.在应用程序的InitInstance()中初始化OLE,代码如下:
1
// Initialize OLE libraries
2
if
(!AfxOleInit())
3
{
4
AfxMessageBox(
"Failed to initialize OLE"
);
5
return
FALSE;
6
}
8.在对话框应用程序的头文件中添加如下变量:
CApplication app;CPresentation presentation;CPresentations presentations;CSlideShowView slideShowView;CSlideShowWindow slideShowWindow;CSlideShowSettings slideShowSettings;CSlides slides;CSlide slide;
9.在打开按钮函数中添加如下代码:
//Start PowerPoint and get Application object...if (!app.CreateDispatch(L"Powerpoint.Application")){AfxMessageBox(L"Couldn't start PowerPoint.");}else // Make PowerPoint visible and display a message{app.put_Visible(TRUE);// 有时候为了ppt不影响程序,会设置启动大小// app.put_Width(100);// app.put_Height(100);}CString strFilter = L"PowerPoint Files (*.ppt;*.pptx)|*.ppt;*.pptx|All Files(*.*)|*.*||";CFileDialog FileDlg(TRUE, L"PPT", NULL, OFN_FILEMUSTEXIST | OFN_NONETWORKBUTTON| OFN_PATHMUSTEXIST, strFilter);FileDlg.DoModal();// To get the selected file's path and nameCString strFileName;strFileName = FileDlg.GetPathName();if (!strFileName.IsEmpty()){presentations = app.get_Presentations();presentation = presentations.Open(strFileName, 0, 0, 1);}presentations = app.get_ActivePresentation();slides = presentation.get_Slides();// Show the first slide of the presentation slide = slides.Item(COleVariant((long)1));//运行这个演示slideShowSettings = presentation.get_SlideShowSettings();slideShowSettings.Run();//这里可以改变ppt大小/*slideShowWindow = presentation.GetSlideShowWindow();slideShowWindow.SetWidth(100);slideShowWindow.SetHeight(100);*/app.put_WindowState((long)2);//addHWND hWnd = ::FindWindow(_T("screenClass"), 0);if (NULL != hWnd){CWnd *pWnd = GetDlgItem(IDC_SHOWING);CRect rect;pWnd->GetWindowRect(&rect);::SetParent(hWnd, pWnd->GetSafeHwnd());pWnd = CWnd::FromHandle(hWnd);rect.SetRect(0, 0, rect.Width(), rect.Height());pWnd->MoveWindow(&rect);pWnd->Invalidate();}
10.在关闭按钮函数中添加如下代码:
app.Quit();11.在首页按钮函数中添加如下代码:
presentation = app.get_ActivePresentation();slideShowWindow = presentation.get_SlideShowWindow();slideShowView = slideShowWindow.get_View();slideShowView.First();12.在末页按钮函数中添加如下代码:
presentation = app.get_ActivePresentation();slideShowWindow = presentation.get_SlideShowWindow();slideShowView = slideShowWindow.get_View();slideShowView.Last();13.在翻到前一页按钮函数中添加如下代码:
presentation = app.get_ActivePresentation();slideShowWindow = presentation.get_SlideShowWindow();slideShowView = slideShowWindow.get_View();slideShowView.Previous();14.在翻到下页按钮函数中添加如下代码:
presentation = app.get_ActivePresentation();slideShowWindow = presentation.get_SlideShowWindow();slideShowView = slideShowWindow.get_View();slideShowView.Next();以上就是大体的流程了,希望大家可以运行成功哦~
VS2013操作PowerPoint,在MFC窗口中打开PPT 配套的源码下载
0 0
- VS2013操作PowerPoint,在MFC窗口中打开PPT
- 关于mfc 对powerpoint的操作,控制ppt播放
- 在mfc中打开console窗口
- VS2013在MFC中使用ADO方法操作Access2013数据库
- 在mfc程序中,打开控制台窗口的方法
- 用Powerpoint打开ppt文件出现提示:"PowerPoint无法显示文件中某些幻灯片中的文字、图像或对象,“xx.ppt”解决办法
- VS2013 MFC对话框编程,资源视图--显示在另一个编辑器中打开
- 芒果PPT助手在POWERPOINT中的使用
- VS2013 MFC中操作MySQL数据库
- 在MFC(VS2013)对话框中添加菜单
- 在mfc中利用opencv打开摄像头并显示在窗口上
- MFC在窗口中贴图
- 在MFC中打开控制台
- 在A窗口中打开B窗口,在B窗口中操作完以后关闭B窗口,同时自动刷新A窗口
- MFC 打开目录窗口
- MFC VS2013 在静态库中使用MFC 和在共享DLL中使用MFC 切换
- 在powerpoint中插入flash
- 如何在运行中快速打开word、excel、ppt
- HttpClient4.3教程
- java:BIO、NIO、AIO区别
- php代码优化
- Activity生命周期
- 创建一个Spring+SpringMVC+MyBatis+MySql+Maven项目需要注意的地方
- VS2013操作PowerPoint,在MFC窗口中打开PPT
- JSP编译成servlet后的文件存放位置
- tomcat设置密码,访问 http://localhost:8080/manager/html,要密码
- 备用钥匙
- 消除svn选定(checkout)桌面上显示一大堆问号
- 自主研发一套PHP前端开发框架(22)
- JS面向对象的程序设计
- iOS基础笔记
- 前端开发学习笔记(一)