PPt播放窗口嵌入到MFC窗口中,幻灯片动画不能正确播放,模拟鼠标单击消息

错误内容是:

ppt有两个窗口:一个是ppFrame窗口,还一个是screenClass 窗口(含有几个子窗口,其中有paneClassDc) 是用来相应鼠标消息的

 

当ppt窗口不嵌入到MFC中,按理说  SlideShowView next和preciew应该能播放窗口,播放动画效果,但是实际不能,

 

找getClick   GotoClick函数,也是不能显示动画效果

 

但是嵌入的窗口能正常接受鼠标和摁键消息,所以想单击按钮的时候发送点击鼠标消息,但是找不到相应的窗口,最后是找到了相应的窗口,是paneClassDC,只能是父窗口

ScreenClass嵌入MFC窗口之前,将这个句柄找到,否则找不到,发不出消息

具体见代码

 

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
MFC 显示PPT //启动 PowerPoint: void CMainFrame::OnPowerpointStartpowerpoint() { /// Check if the IDispatch connection exists with PowerPoint, // if not create one. if (m_ppt.m_lpDispatch == NULL) { // Create IDispatch connection to PowerPoint. m_ppt.CreateDispatch("PowerPoint.Application"); }; // Bring the PowerPoint application to the front. m_ppt.Activate(); } void CMainFrame::OnPowerpointStartslideshow() { _Presentation oPresentation; SlideShowSettings oShow; // Attach to the Active Presentation. oPresentation.AttachDispatch(m_ppt.GetActivePresentation()); // Attach to the slide-show settings. oShow.AttachDispatch(oPresentation.GetSlideShowSettings()); // Run the slide show. oShow.Run(); } // 创建幻灯片: void CMainFrame::OnPowerpointCreateslide() { // Connect to the active presentation. There is no error trapping. // If the active presentation the framework traps // the error and displays a message box. _Presentation ActivePresentation(m_ppt.GetActivePresentation()); // Connect to the slides collection. Slides oSlides(ActivePresentation.GetSlides()); // This constant is defined in the PowerPoint Object model. // You can use the Object Browser, with Visual Basic Editor // (VBE), to look up the different constant values. const ppLayoutTitleOnly = 11; // Add a new slide to the presentation. This code adds the new // slide to the end of the presentation. oSlides.Add(oSlides.GetCount() + 1l, ppLayoutTitleOnly); } // 创建演示文稿: void CMainFrame::OnPowerpointCreatepresentation() { Presentations PresCollection; // Make sure there is a dispatch pointer for PowerPoint. if(m_ppt.m_lpDispatch == NULL) { // Display a message indicating that PowerPoint is not running. MessageBox("PowerPoint is not running.", "Start PowerPoint"); } else { // Bring PowerPoint to the front. m_ppt.Activate(); // Attach the presentations collection to the PresCollection // variable. PresCollection.AttachDispatch(m_ppt.GetPresentations()); // Create a new presentation. PresCollection.Add(1);
您可以使用Microsoft.Office.Interop.PowerPoint命名空间的类来实现在WPF窗口播放PPT。具体步骤如下: 1. 添加对Microsoft.Office.Interop.PowerPoint的引用。 2. 在WPF窗口添加一个WindowsFormsHost控件。 3. 在WindowsFormsHost控件添加一个AxHost控件,并将其类型设置为Microsoft.Office.Interop.PowerPoint.Presentation。 4. 在窗口加载事件,使用Microsoft.Office.Interop.PowerPoint.Application类加载PPT文件。 5. 在AxHost控件的CreateControl方法,使用Microsoft.Office.Interop.PowerPoint.SlideShowSettings类设置PPT播放方式。 下面是示例代码: ```C# using System.Windows.Forms.Integration; using Microsoft.Office.Interop.PowerPoint; //添加引用:Microsoft.Office.Core、Microsoft.Office.Interop.PowerPoint //在WPF窗口添加一个WindowsFormsHost控件 WindowsFormsHost host = new WindowsFormsHost(); this.grid.Children.Add(host); //在WindowsFormsHost控件添加一个AxHost控件,并将其类型设置为Microsoft.Office.Interop.PowerPoint.Presentation AxHost axHost = new AxHost(); axHost.Dock = DockStyle.Fill; axHost.CreateControl(); axHost.GetType().InvokeMember("Enable", BindingFlags.InvokeMethod, null, axHost, new object[] { true }); axHost.GetType().InvokeMember("DisplayAlerts", BindingFlags.SetProperty, null, axHost, new object[] { PpAlertLevel.ppAlertsNone }); host.Child = axHost; //在窗口加载事件,使用Microsoft.Office.Interop.PowerPoint.Application类加载PPT文件 private void Window_Loaded(object sender, RoutedEventArgs e) { Application pptApp = new Application(); Presentation pptPresentation = pptApp.Presentations.Open(@"D:\test.pptx", MsoTriState.msoTrue, MsoTriState.msoFalse, MsoTriState.msoFalse); axHost.GetType().InvokeMember("Ocx", BindingFlags.SetProperty, null, axHost, new object[] { pptPresentation }); } //在AxHost控件的CreateControl方法,使用Microsoft.Office.Interop.PowerPoint.SlideShowSettings类设置PPT播放方式 protected override void CreateControl() { base.CreateControl(); if (this.ActiveXInstance != null) { SlideShowSettings slideShowSettings = ((Presentation)this.ActiveXInstance).SlideShowSettings; slideShowSettings.ShowType = PpSlideShowType.ppShowTypeSpeaker; slideShowSettings.Run(); } } ``` 注意:在使用AxHost控件播放PPT时,需要在CreateControl方法设置PPT播放方式。此外,由于AxHost控件是Windows Forms控件,因此需要使用WindowsFormsHost控件将其嵌入到WPF窗口

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值