[DllImport("user32.dll")]
public extern static int GetWindowText(IntPtr hWnd, StringBuilder lpString, int nMaxCount);ide
/// <summary>
/// 打开ppt文件
/// </summary>
/// <param name="filePath">路径</param>
/// <returns></returns>
public string PPTOpen(string filePath)
{
StringBuilder s = new StringBuilder(512);
//防止连续打开多个PPT程序.
if (this.objApp != null)
{
this.objApp.Quit();
GC.Collect();
}
try
{
objApp = new POWERPOINT.Application();
//以非只读方式打开,方便操做结束后保存.
objPresSet = objApp.Presentations.Open(filePath, OFFICECORE.MsoTriState.msoFalse, OFFICECORE.MsoTriState.msoFalse, OFFICECORE.MsoTriState.msoFalse);ui
//objSlides = objPresSet.Slides;
//int[] SlideIdx = new int[3];
//for (int i = 0; i < 3; i++) SlideIdx[i] = i + 1;
//objSldRng = objSlides.Range(SlideIdx);
//objSST = objSldRng.SlideShowTransition;
//objSST.AdvanceOnTime = MsoTriState.msoTrue;
//objSST.AdvanceTime = 5;
//objSST.EntryEffect = POWERPOINT.PpEntryEffect.ppEffectBoxOut;this
//bAssistantOn = objApp.Assistant.On;
objApp.Assistant.On = false;
objSSS = this.objPresSet.SlideShowSettings;
pptCount = objPresSet.Slides.Count;
//objSSS.ShowType = POWERPOINT.PpSlideShowType.ppShowTypeWindow;
objSSS.Run();
IntPtr aa = (IntPtr)objPresSet.SlideShowWindow.HWND;
int j = GetWindowText(aa, s, s.Capacity); //把this.handle换成你须要的句柄
}
catch (Exception ex)
{
this.objApp.Quit();
}
return s.ToString();
}orm
以阅览模式打开PPT文件,这个嗯简单,经过getwindowtext,获取到打开PPT的句柄,便于以后将句柄在winform的窗体中显示ci
//将ppt嵌入到你想嵌入的控件中
private void intoWebbrower(string pptTitle)
{
ParenthWnd = new IntPtr(0);
ParenthWnd = FindWindow(null, pptTitle);//123.pptx - WPS 演示get
SetParent(ParenthWnd, this.pictureBox1.Handle);
int x = 0;
int y = 0;
int width = this.pictureBox1.Width;
int height = this.pictureBox1.Height-100;
MoveWindow(ParenthWnd, x, y, width, height, true);
}string
经过SetParent能够现实前面获取到句柄的PPT嵌入到控件中的it
而MoveWindow是控制句柄在控件中显示的位置和大小io
对于PPT其余的操做上一页下一页就挺简单的了,能够查阅MSDN的Powerpointform
//上一页
public void preButton()
{
try
{
objPresSet.SlideShowWindow.View.Previous();
}
catch { }
}
//下一页
public void nextButton()
{
try
{
objPresSet.SlideShowWindow.View.Next();
}
catch { }
}
播放PPT还有一个比较麻烦的就是须要及时的释放掉PPT的句柄,否者会一直被占用这
public void PPTExit()
{
try
{
if (objApp != null)
objApp.SlideShowWindows[1].View.Exit();
}
catch { }
}
而轮播的效果也能够经过objApp.SlideShowWindows[1].View.Slide.SlideIndex目前播放的是第几页来实现轮播的效果,
检测到是最后一页是objPresSet.SlideShowWindow.View.First();,就OK了