我有一個wpf應用程序,它將powepoint文件嵌入到webBrowser控件中。我設法使用下面的示例代碼來實現該功能。但是每當我運行ppt文件幻燈片顯示彈出屏幕幾秒鐘,然後只有它嵌入到控制。有什麼方法可以阻止它或將其作爲後臺進程運行?將PowerPoint幻燈片嵌入到控制器中
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);
}
}
}
你有解決你的問題嗎?我也試圖在WPF應用程序中嵌入PowerPoint。 – Meirion
@Meirion抱歉,我還沒有得到解決方案。唯一的其他選擇是將每張幻燈片保存爲圖像並順序使用它們。但這不是一個體面的解決方案。 – pRimE