Bra*_*eau 9 c# wpf integration winapi powerpoint
目前我在C#中有一个WPF应用程序,但我发现找到任何有用的方法将PowerPoint演示文稿嵌入到我的窗口中是非常困难的.
我在这里找到了一个解决方案:将Powerpoint节目嵌入到C#应用程序中
此解决方案产生了在另一个窗口中运行PowerPoint的问题,但只是在WPF应用程序中显示其UI.这意味着当WPF窗口被聚焦时,PowerPoint演示文稿没有,并且停止播放.当窗口关闭时,还存在PowerPoint崩溃的问题.
我找到的另一个解决方案是:http://www.codeproject.com/Articles/118676/Embedding-PowerPoint-presentation-player-into-a-WP
解决方案很受欢迎,但我发现它很难处理.我不知道任何Win32编程,或者是C++,所以我发现它很难修改.我设法让它停止显示PowerPoint的第二个副本(原始项目中的预期功能),但我还没有找到一种方法来自动打开PowerPoint演示文稿.
所以我需要的是一种自动和在后台干净地打开PowerPoint演示文稿的方法(我不希望在任何时候显示PowerPoint UI),并允许它自动运行(而不是响应输入)应用程序正在运行.如果我能将它保存在C#和WPF中,并且不必处理Win32和C++,那将是非常好的.
这可能吗?在这一点上,我真的后悔这个项目只是因为PowerPoint集成的麻烦.
Jou*_*usi 11
您可以即时将演示文稿转换为视频格式:
// 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;
}
Run Code Online (Sandbox Code Playgroud)
然后你会玩它MediaElement:
<MediaElement Name="player" LoadedBehavior="Manual" UnloadedBehavior="Stop" />
public void PlayPresentation(string filename)
{
var wmvfile = GetVideoFromPpt(filename);
player.Source = new Uri(wmvfile);
player.Play();
}
Run Code Online (Sandbox Code Playgroud)
File.Delete(wmvfile)当你完成视频播放时别忘了!
| 归档时间: |
|
| 查看次数: |
9976 次 |
| 最近记录: |