2

I have a wpf application that embeds powepoint file into a webBrowser control. I managed to implement that functionality using the below sample code. But whenever i run the ppt file the slide show popups into the screen for a few seconds and then only it embeds into the control. Is there any way to stop this or run it as a background process ?

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);
        }
    }
}
Dimith
  • 379
  • 2
  • 12
  • did you get a solution to your problem? I too am trying to embed a PowerPoint in a WPF application. – Meirion Oct 23 '13 at 13:11
  • @Meirion sorry i didnt get a solution yet. The only other option is to save each slide as images and use them sequentially. But it's not decent solution. – Dimith Oct 25 '13 at 07:04

2 Answers2

1

I had the same issue and I used this solution by Patrick Reisert. He uses the powerpointviewer and not powerpoint and converts the slide show to a list of bitmaps. It is a comprehensive solution with navigation capabilities.

Priyan Perera
  • 560
  • 1
  • 7
  • 20
-1

You can also do it in another way that I have Implemented to open ppt/pps. It opens your ppt/pps file directly on top in Full Screen. try this if you wants to do so.

 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();
Rahul Saksule
  • 417
  • 5
  • 15