2012-12-04 72 views
3

我有一個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); 
     } 
    } 
} 
+0

你有解決你的問題嗎?我也試圖在WPF應用程序中嵌入PowerPoint。 – Meirion

+0

@Meirion抱歉,我還沒有得到解決方案。唯一的其他選擇是將每張幻燈片保存爲圖像並順序使用它們。但這不是一個體面的解決方案。 – pRimE

回答

1

我有同樣的問題,我用Patrick Reisert的這個solution。他使用powerpointviewer而不是powerpoint,並將幻燈片轉換爲位圖列表。這是一個具有導航功能的綜合解決方案。

+0

非常感謝Priyan。這工作。 – pRimE

-1

你也可以用另一種方法做到這一點,我已經實現了打開ppt/pps。 它以全屏模式直接打開您的ppt/pps文件。如果你想這樣做,試試這個。

Microsoft.Office.Interop.PowerPoint.Application application = new Microsoft.Office.Interop.PowerPoint.Application(); 
       Microsoft.Office.Interop.PowerPoint.Presentation presesntation = application.Presentations.Open2007("file path", Microsoft.Office.Core.MsoTriState.msoTrue, Microsoft.Office.Core.MsoTriState.msoFalse, Microsoft.Office.Core.MsoTriState.msoFalse, Microsoft.Office.Core.MsoTriState.msoTrue); 
       Microsoft.Office.Interop.PowerPoint.SlideShowSettings sst = presesntation.SlideShowSettings; 
       sst.ShowType = Microsoft.Office.Interop.PowerPoint.PpSlideShowType.ppShowTypeSpeaker; 
       sst.Run(); 
相關問題