我有兴趣在窗口面板中播放 Power Point 演示文稿。它在 Panel 中播放 power point 文件,但问题是它首先在几秒钟内播放全屏,然后继续在 Panel 中播放。但我需要直接在面板上玩。如果有人知道,请帮助。
using System.Diagnostics;
using System.Runtime.InteropServices;
using ppt = Microsoft.Office.Interop.PowerPoint;
using Microsoft.Office.Core;
[DllImport("user32.dll", EntryPoint = "FindWindow", SetLastError = true)]
static extern IntPtr FindWindow(IntPtr ZeroOnly, string lpWindowName);
[DllImport("user32.dll", SetLastError = true)]
static extern IntPtr SetParent(IntPtr hWndChild, IntPtr hWndNewParent);
[DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Auto)]
public static extern bool SetWindowText(IntPtr hwnd, String lpString);
ppt.Presentation presentation;
Microsoft.Office.Interop.PowerPoint.SlideShowView oSlideShowView;
bool flag = false;
public void open(string FileName)
{
try
{
ppt.Application application;
// For Display in Panel
IntPtr screenClasshWnd = (IntPtr)0;
IntPtr x = (IntPtr)0;
application = new ppt.Application();
presentation = application.Presentations.Open(FileName, MsoTriState.msoTrue, MsoTriState.msoTrue, MsoTriState.msoFalse);
panel1.Controls.Add(application as Control);
ppt.SlideShowSettings sst1 = presentation.SlideShowSettings;
sst1.LoopUntilStopped = Microsoft.Office.Core.MsoTriState.msoCTrue;
ppt.Slides objSlides = presentation.Slides;
sst1.LoopUntilStopped = MsoTriState.msoTrue;
sst1.StartingSlide = 1;
sst1.EndingSlide = objSlides.Count;
panel1.Dock = DockStyle.Fill;
sst1.ShowType = ppt.PpSlideShowType.ppShowTypeKiosk;
ppt.SlideShowWindow sw = sst1.Run();
oSlideShowView = presentation.SlideShowWindow.View;
IntPtr pptptr = (IntPtr)sw.HWND;
SetParent(pptptr, panel1.Handle);
}
catch (Exception)
{
throw;
}
}
private void Form3_Load(object sender, EventArgs e)
{
string FileName = "D:\\test.pptx";
open(FileName);
}
private void timer1_Tick(object sender, EventArgs e)
{
oSlideShowView.Next();
}