如何在不打开另一个窗口的情况下将PowerPoint演示文稿嵌入到WPF应用程序中? [英] How can I embed a PowerPoint presentation into a WPF application without opening another window?

查看:534
本文介绍了如何在不打开另一个窗口的情况下将PowerPoint演示文稿嵌入到WPF应用程序中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当前,我在C#中有一个WPF应用程序,但是我发现很难找到任何有用的方法将PowerPoint演示文稿嵌入到我的窗口中。

Currently I have a WPF application in C#, but I'm finding it to be incredibly difficult to find any useful ways to embed a PowerPoint presentation into my window.

我在这里找到的一个解决方案:将Powerpoint演示嵌入C#应用程序中

One solution I found here: Embedding a Powerpoint show into a C# application

此解决方案产生了使PowerPoint在另一个窗口中运行的问题,而只是在WPF应用程序中显示其UI。这意味着当重点放在WPF窗口时,PowerPoint演示文稿就没有,并停止播放。关闭窗口时,还会出现PowerPoint崩溃的问题。

This solution created the problem of having PowerPoint run in another window, but just display its UI within the WPF application. This meant that when the WPF window was focused, the PowerPoint presentation was not, and stopped playing. There was also the problem of PowerPoint crashing when the window was closed.

我在这里找到的另一个解决方案是: http://www.codeproject.com/Articles/118676/Embedding-PowerPoint-presentation-player-into- a-WP

Another solution I found was here: http://www.codeproject.com/Articles/118676/Embedding-PowerPoint-presentation-player-into-a-WP

该解决方案很受欢迎,但我发现很难使用。我不知道任何Win32编程或C ++,所以我发现修改非常困难。我设法使它停止显示PowerPoint的第二个副本(原始项目中的预期功能),但是我还没有找到自动打开PowerPoint演示文稿的方法。

The solution was popular, but I found it difficult to work with. I don't know any Win32 programming, OR C++, so I found it extremely hard to modify. I managed to get it to stop displaying a second copy of the PowerPoint (an intended function in the original project), but I've not yet found a way to automatically open the PowerPoint presentation.

所以我需要的是一种自动在后台自动打开PowerPoint演示文稿的方法(我不希望PowerPoint UI在任何时候显示),并允许它自动运行(而不是在应用程序运行时响应输入)。如果我可以将其保留在C#和WPF中,而不必使用Win32和C ++,那就太好了。

So what I need is a way to cleanly open the PowerPoint presentation automatically and in the background (I don't want the PowerPoint UI to be displayed at any point), and to allow it to run automatically (and not respond to input) while the application is running. It would be wonderful if I could keep it within C# and WPF, and not have to deal with Win32 and C++.

这可能吗?在这一点上,我真的很后悔这个项目,仅仅是因为PowerPoint集成的麻烦。

Is this possible? At this point I'm really regretting this project simply because of the PowerPoint integration headaches.

推荐答案

您可以将演示文稿转换为动态视频格式:

You could convert your presentation to a video format on-the-fly:

// not tested as I don't have the Office 2010, but should work
private string GetVideoFromPpt(string filename)
{
    var app = new PowerPoint.Application();
    var presentation = app.Presentations.Open(filename, MsoTriState.msoTrue, MsoTriState.msoTrue, MsoTriState.msoFalse);

    var wmvfile = Guid.NewGuid().ToString() + ".wmv";
    var fullpath = Path.GetTempPath() + filename;

    try
    {
        presentation.CreateVideo(wmvfile);
        presentation.SaveCopyAs(fullpath, PowerPoint.PpSaveAsFileType.ppSaveAsWMV, MsoTriState.msoCTrue);
    }
    catch (COMException ex)
    {
        wmvfile = null;
    }
    finally
    {
        app.Quit();
    }

    return wmvfile;
}

然后您可以使用 MediaElement播放

<MediaElement Name="player" LoadedBehavior="Manual" UnloadedBehavior="Stop" />

public void PlayPresentation(string filename)
{
    var wmvfile = GetVideoFromPpt(filename);
    player.Source = new Uri(wmvfile);
    player.Play();
}

别忘了 File.Delete(wmvfile )播放完视频后!

这篇关于如何在不打开另一个窗口的情况下将PowerPoint演示文稿嵌入到WPF应用程序中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆