axWebBrowser组件自动播放ppt
来源:互联网 发布:axure 8.0 mac 破解版 编辑:程序博客网 时间:2024/05/01 02:37
最近做个项目,要求在winform中自动播放ppt,在网上查了很多资料,都不能自动,后来自己花了些时间研究了下,终于可以自动播放了,和大家分享下,程序还有待改善,感觉播放导入有点慢,ppt换页样式不能设置,还请高手指点了。
1.导入如下注册表值
Windows Registry Editor Version 5.00
[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\PowerPoint.Show.8]
"BrowserFlags"=dword:800000A0
[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\PowerPoint.Show.12]
"BrowserFlags"=dword:800000A0
[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\PowerPoint.ShowMacroEnabled.12]
"BrowserFlags"=dword:800000A0
[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\PowerPoint.SlideShow.8]
"BrowserFlags"=dword:800000A0
[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\PowerPoint.SlideShow.12]
"BrowserFlags"=dword:800000A0
[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\PowerPoint.SlideShowMacroEnabled.12]
"BrowserFlags"=dword:800000A0
2.创建一个winform,在设计视图拖入axWebBrowser和一个按钮,在Form1.cs中粘贴如下代码:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Reflection;
using OFFICECORE = Microsoft.Office.Core;
using PowerPoint = Microsoft.Office.Interop.PowerPoint;
using System.Runtime.InteropServices;
namespace pptTest
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
//文件加载完调用播放下一页
this.axWebBrowser1.DocumentComplete += new AxSHDocVw.DWebBrowserEvents2_DocumentCompleteEventHandler(axWebBrowser1_DocumentComplete);
this.axWebBrowser1.NavigateComplete2 += new AxSHDocVw.DWebBrowserEvents2_NavigateComplete2EventHandler(this.axWebBrowser1_NavigateComplete2);
this.Load += new System.EventHandler(this.Form1_Load);
this.Closed += new System.EventHandler(this.Form1_Closed);
}
private Object oDocument;
private String strFileName;
private int totalPage=0;
private int nowlPage = 0;
PowerPoint.Presentation objPresSet = null;
PowerPoint.Application pptApplication;
private void button1_Click(object sender, EventArgs e)
{
//Find the Office document.
openFileDialog1.FileName = "";
openFileDialog1.ShowDialog();
strFileName = openFileDialog1.FileName;
//打开文档
if (strFileName.Length != 0)
{
Object refmissing = System.Reflection.Missing.Value;
oDocument = null;
axWebBrowser1.Navigate(strFileName, ref refmissing, ref refmissing, ref refmissing, ref refmissing);
}
}
public void Form1_Load(object sender, System.EventArgs e)
{
openFileDialog1.Filter = "Office Documents(*.doc, *.xls, *.ppt, *.pptx, *.mp3,*.wmv)|*.doc;*.xls;*.ppt;*.pptx;*.mp3;*.wmv";
openFileDialog1.FilterIndex = 1;
}
public void Form1_Closed(object sender, System.EventArgs e)
{
oDocument = null;
}
public void axWebBrowser1_NavigateComplete2(object sender, AxSHDocVw.DWebBrowserEvents2_NavigateComplete2Event e)
{
Object o = e.pDisp;
oDocument = o.GetType().InvokeMember("Document", BindingFlags.GetProperty, null, o, null);
Object oApplication = o.GetType().InvokeMember("Application", BindingFlags.GetProperty, null, oDocument, null);
pptApplication = (PowerPoint.Application)oApplication;
//取出ppt对象进行设置
pptApplication.SlideShowEnd+=new PowerPoint.EApplication_SlideShowEndEventHandler(pptApplication_SlideShowEnd);
objPresSet = pptApplication.Presentations.Open(strFileName, OFFICECORE.MsoTriState.msoCTrue, OFFICECORE.MsoTriState.msoFalse, OFFICECORE.MsoTriState.msoFalse);
int Slides = objPresSet.Slides.Count;
totalPage = Slides;
pptApplication.SlideShowNextSlide += new Microsoft.Office.Interop.PowerPoint.EApplication_SlideShowNextSlideEventHandler(pptApplication_SlideShowNextSlide);
}
//播放下一页处理
void pptApplication_SlideShowNextSlide(Microsoft.Office.Interop.PowerPoint.SlideShowWindow Wn)
{
System.Threading.Thread.Sleep(5000);
NextSlide();
}
//结束事件处理
void pptApplication_SlideShowEnd(Microsoft.Office.Interop.PowerPoint.Presentation Pres)
{
//MessageBox.Show("end");
}
[DllImport("user32.dll", SetLastError = true)]
static extern int GetWindowThreadProcessId(IntPtr hWnd, out int lpdwProcessId);
public void NextSlide()
{
//if (this.pptApplication != null)
//this.objSST.EntryEffect = PowerPoint.PpEntryEffect.ppEffectCircleOut;
nowlPage++;
if (nowlPage != totalPage)
{
this.objPresSet.SlideShowWindow.View.Next();
}
else {
//如果播放完成,ppt退出axWebBrowser1
//this.objPresSet.SlideShowWindow.View.Exit();
totalPage = 0;
nowlPage = 0;
objPresSet.Close();
int lpdwProcessId;
GetWindowThreadProcessId(new IntPtr(pptApplication.HWND), out lpdwProcessId);
System.Diagnostics.Process.GetProcessById(lpdwProcessId).Kill();
}
}
//加载完后让播放下一页
public void axWebBrowser1_DocumentComplete(object sender, AxSHDocVw.DWebBrowserEvents2_DocumentCompleteEvent e)
{
System.Threading.Thread.Sleep(5000);
NextSlide();
}
}
}
3.运行播放,可以看到自动播放效果。
- axWebBrowser组件自动播放ppt
- 可调速自动播放ppt
- office 2010 ppt幻灯片自动播放
- 让PPT文档自动实现列表播放
- 【特种兵PPT教程】如何制作自动播放的PPT?
- PPT播放
- PPT2010中轻松实现PPT自动循环播放
- 打造自动播放动画,实现PPt模式的效果
- ppt播放进度条问题
- Kinect-播放ppt
- QObject怎样把ppt嵌入qt widget里显示,并控制自动播放
- UI组件之ViewFlipper实现自动播放的图片库
- PPT转SWF并播放
- PPT播放显示备注技巧
- 网页中播放PPT 幻灯片
- PPT不能播放下一页
- 【Kinect】Kinect控制PPT播放
- PPt插入视频同时播放
- 一致性 hash 算法( consistent hashing )
- 程序员 赚钱
- poj 3481 Double Queue(平衡树,SBT)
- spring 定时器配置
- android开发之interpolator的用法详解
- axWebBrowser组件自动播放ppt
- ios 开发经典书籍
- poj2443(简单的状态压缩)
- DRAM SPD基础知识
- FLV 文件格式
- Android使用GridView实现日历功能(详细代码)
- C#中的委托和事件——学习笔记
- Lucene Filter的例子
- em(倍)与px的区别与联系