我有一个将 powepoint 文件嵌入到 webBrowser 控件中的 wpf 应用程序。我设法使用下面的示例代码实现了该功能。但每当我运行 ppt 文件时,幻灯片放映会在屏幕中弹出几秒钟,然后只有它嵌入到控件中。有什么办法可以阻止它或将其作为后台进程运行?
using System;
using System.Runtime.InteropServices;
using System.Windows;
using Microsoft.Office.Core;
using PPT = Microsoft.Office.Interop.PowerPoint;
namespace WpfApplication1
{
public partial class MainWindow
{
public MainWindow()
{
InitializeComponent();
}
[DllImport("User32", CharSet = CharSet.Auto, ExactSpelling = true)]
internal static extern IntPtr SetParent(IntPtr hWndChild, IntPtr hWndParent);
private void BtnOpenClick(object sender, RoutedEventArgs e)
{
const string pptFilePath = @"E:\Sample.ppt";
var pptApplication = new PPT.Application
{
ShowWindowsInTaskbar = MsoTriState.msoFalse
};
var presentation = pptApplication.Presentations.Open(pptFilePath, MsoTriState.msoCTrue,
MsoTriState.msoTrue, MsoTriState.msoFalse);
var slideShowWindow = presentation.SlideShowSettings.Run();
slideShowWindow.Height = (int)(0.85 * webBrowser1.Height);
slideShowWindow.Width = (int)(0.75 * webBrowser1.Width);
SetParent(new IntPtr(presentation.SlideShowWindow.HWND), webBrowser1.Handle);
}
}
}