关于mfc 对powerpoint的操作,控制ppt播放

怎样实现mfc操作ppt文件的打开、播放、关闭等,网络上基本上有了详细的实现方式,比如如下博主们的简介:

转:http://blog.sina.com.cn/s/blog_6163bdeb0100nn1p.html

转:http://www.2cto.com/kf/201505/396898.html

转:http://blog.sina.com.cn/s/blog_4e345ce70100j4m1.html

上述文章都很详细的介绍了mfc通过com接口实现ppt相关操作的实现步骤,我自己也进行了代码实现,请参考:http://download.csdn.net/detail/leighton_52/9277441

但是,实现的过程中我发现了一个问题,那就是上述实现只能对后缀名为.ppt的文件操作,而不可以对.pptx进行操作,随着windows office的不断升级,怎么解决这个问题呢,也变得比较重要了。

我作为技术菜鸟,很抱歉,也无法为你解答,不过如果你只是简单的对文件实施打开,翻页以及关闭的话,我倒是可以提供一个更为简单的实现方法,仅供参考。

 打开ppt 文件:CString sPPTPath;

ShellExecute(NULL,"open",sPPTPath,NULL,NULL,SW_SHOW);

播放ppt 文件:

 keybd_event(0x74,0,0,0);     //74,键盘F5对应的ascii值
 keybd_event(0x74,0,KEYEVENTF_KEYUP,0);

翻页:

keybd_event(38,0,0,0);  (上一页)

keybd_event(38,0,KEYEVENTF_KEYUP,0);

keybd_event(40,0,0,0);    (下一页)
keybd_event(40,0,KEYEVENTF_KEYUP,0);

结束:
 if (CCommonFun::IsRunProcess(_T("POWERPNT.EXE")))
{
 CCommonFun::TerminateProcessEx(_T("POWERPNT.EXE"));
 }


实现原理,是通过系统函数打开ppt文件,然后通过代码控制键盘,对文件进行操作

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);
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值