Question

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);
        }
    }
}
Was it helpful?

Solution

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.

OTHER TIPS

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();
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top