将Powerpoint节目嵌入到C#应用程序中

我希望能够将powerpoint演示文稿嵌入到C#表单(WinForms)中。 基本上我们有一个52’显示器,我们的想法是在一个角落里我们将有一个PPT循环,然后其他三个角落将显示来自程序本身的信息。

我曾预料到这很简单,但似乎我错了。

我被建议使用WebBrowser控件,但这不起作用,而是将powerpoint文件视为下载,即给我一个“保存,打开”对话框。

有什么建议?

AK

您可以使用SetParent函数运行PowerPoint,获取Windows句柄并设置新的父窗口。


您所需要的只是PowerPoint窗口的窗口类的名称,但是由于Spy ++ ,这没什么大不了的。

间谍++


以下是运行自定义应用程序“内部”的PowerPoint的屏幕截图:

微软幻灯片软件


完整示例(取自此处并为PowerPoint修改):

public partial class Form1 : Form { public Form1() { this.Size = new System.Drawing.Size(800, 600); this.TopMost = true; this.Text = "My Application"; this.FormBorderStyle = FormBorderStyle.FixedToolWindow; Func run = () => Window.Find(hwnd => { var cn = Window.GetClassName(hwnd); var res = (cn == "PPTFrameClass"); if (res) { this.Controls.Clear(); Window.SetParent(hwnd, this.Handle); Window.SetWindowPos(hwnd, new IntPtr(0), -8, -30, this.Width + 10, this.Height + 37, 0x0040); } return res; }); new Button { Parent = this, Text = "Start" } .Click += (s, e) => { if (run() == false) MessageBox.Show("Open PowerPoint"); }; } } public static class Window { public static bool Find(Func fn) { return EnumWindows((hwnd, lp) => !fn(hwnd), 0) == 0; } public static string GetClassName(IntPtr hwnd) { var sb = new StringBuilder(1024); GetClassName(hwnd, sb, sb.Capacity); return sb.ToString(); } public static uint GetProcessId(IntPtr hwnd) // {0:X8} { uint pid; GetWindowThreadProcessId(hwnd, out pid); return pid; } public static string GetText(IntPtr hwnd) { var sb = new StringBuilder(1024); GetWindowText(hwnd, sb, sb.Capacity); return sb.ToString(); } delegate bool CallBackPtr(IntPtr hwnd, int lParam); [DllImport("user32.dll")] static extern int EnumWindows(CallBackPtr callPtr, int lPar); [DllImport("user32.dll")] static extern uint GetWindowThreadProcessId(IntPtr hWnd, out uint lpdwProcessId); [DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)] static extern int GetWindowText(IntPtr hWnd, StringBuilder lpString, int nMaxCount); [DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Auto)] static extern int GetClassName(IntPtr hWnd, StringBuilder lpClassName, int nMaxCount); [DllImport("User32", CharSet = CharSet.Auto, ExactSpelling = true)] public static extern IntPtr SetParent(IntPtr hWndChild, IntPtr hWndParent); [DllImport("user32.dll", SetLastError = true)] public static extern bool SetWindowPos(IntPtr hWnd, IntPtr hWndInsertAfter, int X, int Y, int W, int H, uint uFlags); } 

一个可嵌入的Active / X控件的PowerPoint查看器应该是要走的路 – 你可以试试这个 (显然它不起作用 – 见评论)或者这个

有关在Windows窗体应用程序中嵌入Active / X控件的信息,请参见此处

如果您计划显示PowerPoint的窗口没有更改大小,您还可以将PowerPoint幻灯片转换为位图,然后只显示位图

我真的不知道是否可以在winforms中嵌入ppt-viewer。 我还有另外一个建议:使用浏览器控件(如果你想要更好的html5支持,可以下载一个用于webkit)并使用像impress.js这样的js库来呈现演示文稿。 只是一个想法。

最初由@danish发布, 在这里 。

看到这个链接 。 您还可以在WebBrowser控件中显示ppt。 这可能也很有用。

基本上它允许你在一个可以轻松嵌入的WebBrowser控件中打开ppt。 如果您需要更多相关信息,请与我们联系。