2012-12-04 7 views
3

J'ai une application wpf qui incorpore le fichier powepoint dans un contrôle webBrowser. J'ai réussi à implémenter cette fonctionnalité en utilisant l'exemple de code ci-dessous. Mais chaque fois que j'exécute le fichier ppt, le diaporama apparaît à l'écran pendant quelques secondes et ensuite seulement il s'intègre dans le contrôle. Est-il possible d'arrêter cela ou de l'exécuter en tant que processus d'arrière-plan?Intégration d'un diaporama PowerPoint dans un contrôleur

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

Avez-vous trouvé une solution à votre problème? Moi aussi j'essaie d'intégrer un PowerPoint dans une application WPF. – Meirion

+0

@Meirion désolé je n'ai pas encore eu de solution. La seule autre option consiste à enregistrer chaque diapositive sous forme d'images et à les utiliser de manière séquentielle. Mais ce n'est pas une solution décente. – pRimE

Répondre

1

J'ai eu le même problème et moi cette solution par Patrick Reisert. Il utilise le PowerpointViewer et non Powerpoint et convertit le diaporama en une liste de bitmaps. C'est une solution complète avec des capacités de navigation.

+0

Merci beaucoup Priyan. Cela a fonctionné. – pRimE

-1

Vous pouvez également le faire d'une autre manière que j'ai implémenté pour ouvrir ppt/pps. Il ouvre votre fichier ppt/pps directement au-dessus en plein écran. essayez ceci si vous voulez le faire.

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(); 
Questions connexes