vc 操作ppt的简单例子
来源:互联网 发布:模拟射击软件 编辑:程序博客网 时间:2024/06/06 03:33
vs2008
2007ppt
网上大多例子是其他版本的, 导致不少人没法使用。 类型库不一样。
我照着 codeproject的这篇文章写的,源码已经上传到“我的资源”里,可自行下载。原文:http://www.codeproject.com/Articles/2506/Automating-MS-Office-applications
Steps to follow
By following the same steps given below, you can automate , word, excel or any Microsoft office application.
- Create a dialog based application and in the App-wizard's step 3 of 6, select the automation checkbox.
- Create buttons for Start , Run, Close, First Slide, Last Slide, Previous Slide and Next Slide functions and use the following functions accordingly.
- In your application's
InitInstance
function , add the following lines.Collapse | Copy Code// Initialize OLE librariesif (!AfxOleInit()){ AfxMessageBox("Failed to initialize OLE"); return FALSE;}
- In your dialog's class , open class-wizard , select the automation tab, select "Add Class" ... "From a type library" and select msppt8.olb from "C:\Program Files\Microsoft Office\Office\"
- In your header file of your dialog, include the following line.Collapse | Copy Code
#include "msppt8.h"
- Add the following variables in your dialog's header file.Collapse | Copy Code
_Application app; // app is the PowerPoint _Application objectPresentations Presentations;_Presentation Presentation;SlideShowView View;SlideShowWindow SlideShowWindow;SlideShowSettings slideshow;Slides slides; _Slide slide;
- To start PowerPoint, you have to write this code in the Start button's function.Collapse | Copy Code
void CPowerPntDlg::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!"); }}
- To open a presentation from the hard disk, add this code in the Open button's function call.Collapse | Copy Code
void CPowerPntDlg::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); }}
- To close PowerPoint add this code in the Close button's function call.Collapse | Copy Code
void CPowerPntDlg::OnBtnClose() { if (CanExit()) app.Quit();}
- To run the slideshow use this code in the Run button's function callCollapse | Copy Code
void CPowerPntDlg::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();}
- Sometimes, you might want to start all over from the first slide. To go to the first slide you can use this code.Collapse | Copy Code
void CPowerPntDlg::OnBtnFirst() { Presentation = app.GetActivePresentation(); SlideShowWindow = Presentation.GetSlideShowWindow(); View = SlideShowWindow.GetView(); View.First();}
- And similarly, to go to the last slideCollapse | Copy Code
void CPowerPntDlg::OnBtnLast() { Presentation = app.GetActivePresentation(); SlideShowWindow = Presentation.GetSlideShowWindow(); View = SlideShowWindow.GetView(); View.Last();}
- Now that you have the slideshow running, you would obviously want to go to the previous slide at some point of time. To do just that, you can use this code.Collapse | Copy Code
void CPowerPntDlg::OnBtnPrevious() { Presentation = app.GetActivePresentation(); SlideShowWindow = Presentation.GetSlideShowWindow(); View = SlideShowWindow.GetView(); View.Previous();}
- Interested to go to the next slide now ? In that case, this function will help you.Collapse | Copy Code
void CPowerPntDlg::OnBtnNext() { Presentation = app.GetActivePresentation(); SlideShowWindow = Presentation.GetSlideShowWindow(); View = SlideShowWindow.GetView(); View.Next();}
- vc 操作ppt的简单例子
- VC 操作Word 2003的简单例子
- vc操作word的简单例子
- VC 防火墙的操作例子
- VC 防火墙的操作例子
- 对ppt文件的一些简单操作
- 简单的ppt转pdf操作技巧
- VC++.net 的第一个简单例子
- 简单的vc操作excel
- vc简单例子---浏览器
- ppt对应的例子位置
- 简单的文件操作的例子
- 简单的数据库链式操作的例子
- struts操作数据库 -一个简单的例子
- js操作cookie的简单例子
- C#操作MySQL数据库的简单例子
- c#操作Access数据库的简单例子
- c#操作Access数据库的简单例子
- Android 4.0 事件输入(Event Input)系统
- QTP_计算器_实现任意2个5位数的加减乘除
- performSelectorOnMainThread
- Linux-2.6.25移植
- linux里的CPU负载
- vc 操作ppt的简单例子
- Hibernate配置参数
- c#基础学习小笔记
- Clustering (1): k-means
- Verilog HDL Syntax And Semantics
- 玩玩小爬虫——抓取时的几个小细节
- android开发问题记录(2012/11/22)
- ioctl 官方说明
- SAP的新T台:在中国站稳脚跟