我有:
1表格 1小组
我这样做没有问题:运行notepad.exe并让它在面板内运行,没有问题。但是,运行2003或2007的查看器,我将其启动但不在表单内。 (以下示例代码)
//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);
我尝试使用PPTViewer.exe,我无法让Powerpoint幻灯片在表单内运行。它启动了查看器,但在表单之外。
不确定我是否必须在这做一些特别的事情。
答案 0 :(得分:2)
我能回答自己的问题吗?
基本上,我使用SPY ++来查看查看器正在打开一个子窗口。子窗口是我想强制进入我的应用程序的窗口,所以我使用以下API调用来获取子窗口的句柄。
[的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);
使用PPT 2003或以下文件,这可以正常工作(只能查看第一张幻灯片),但是使用PPT 2007,它仍然在我的表单之外打开。这很快,但是......
最后,我们决定不以原生格式播放PPT,因为微软没有制作轻量级的.net控件来播放PPT。我们不想在幕后启动PPT,并且使用该方法启动PPT文件需要几秒钟,这是不可接受的性能。
因此,我们将PPT转换为Flash并使用Flash主动X控件(超快)来播放原始PPT内容。
这似乎是最好的解决方案。