views:

532

answers:

1

I have:

1 Form 1 Panel

I do this with no issue: Run notepad.exe and get it to run inside the panel, no problems. however, running either the 2003 or 2007 viewer I get it to launch but not inside the form. (sample code below)

 //DLL Import
    using System.Runtime.InteropServices;

    [DllImport("user32.dll")]
    static extern IntPtr SetParent(IntPtr hWndChild, IntPtr hWndNewParent);


  string ppviewer = @"C:\Program Files\Microsoft Office\Office12\PPTVIEW.EXE";

        System.Diagnostics.ProcessStartInfo startinfo = new System.Diagnostics.ProcessStartInfo(ppviewer);
        startinfo.Arguments = @"D:\Test.pps /s";

        System.Diagnostics.Process pptprocess = System.Diagnostics.Process.Start(startinfo);

        pptprocess.WaitForInputIdle();

        SetParent(pptprocess.MainWindowHandle, this.panel1.Handle);

I try the same with PPTViewer.exe and I can't get the Powerpoint slide to run inside the form. It launches the viewer, but outside of the form.

Not sure if I have to do something special here.

A: 

Do I get points for answering my own question?

Basically, I used SPY++ to see that the viewer was opening up a child window(s). The child window was the window I wanted to force into my application, so I used the following API calls to get the handle on the child window.

[DllImport("user32.dll")] static extern IntPtr SetParent(IntPtr hWndChild, IntPtr hWndNewParent);

    [DllImport("user32.dll")]
    [return: MarshalAs(UnmanagedType.Bool)]
    public static extern bool EnumChildWindows(IntPtr window, EnumWindowProc callback, IntPtr i);

With PPT 2003 or below files this worked OK (only able to view first slide), but with PPT 2007 it still opened outside my form. It was very quick, but....

In the end, we have decided not to play PPTs in native format because Microsoft doesn't make a lightweight .net control to play PPTs. We don't want to launch PPT behind the scenes either and launching PPT files with the method takes a few seconds which is not acceptable performance.

So, We will convert the PPT to Flash and use the Flash active X control (which is super fast) to play the original PPT content.

This seems like the best solution.