首页
社区
课程
招聘
根据英文,组合出程序,我英语太烂了!
发表于: 2013-3-7 21:53 6652

根据英文,组合出程序,我英语太烂了!

2013-3-7 21:53
6652
好像是用vc6来操作word或者ppt的
我没看明白,E文不好,希望大家帮助,

原文的地址在这里:http://www.codeproject.com/KB/COM/ole_automation.aspx

Automating MS-Office applications

1.Create a dialog based application and in the App-wizard's step 3 of 6, select the automation checkbox.

2.Create buttons for Start , Run, Close, First Slide, Last Slide, Previous Slide and Next Slide functions and use the following functions accordingly.

3.In your application's InitInstance function , add the following lines.

// Initialize OLE libraries
if (!AfxOleInit())
{
    AfxMessageBox("Failed to initialize OLE");
    return FALSE;
}

4.In your dialog's class , open class-wizard , select the automation tab, select "Add Class" ... "From a type library" and select msppt8.olb from "C:\Program Files\Microsoft Office\Office\"
5.In your header file of your dialog, include the following line.

#include "msppt8.h"

6.Add the following variables in your dialog's header file.

_Application app; // app is the PowerPoint _Application object

Presentations Presentations;
_Presentation Presentation;

SlideShowView View;

SlideShowWindow SlideShowWindow;
SlideShowSettings slideshow;
Slides slides;
_Slide slide;

7.To start PowerPoint, you have to write this code in the Start button's function.

void CPowerPntDlg::OnBtnStart()
{
    // Start PowerPoint and get Application object...
    if(!app.CreateDispatch("Powerpoint.Application"))
    {
        AfxMessageBox("Couldn't start PowerPoint.");
    }
    else // Make PowerPoint visible and display a message
    {
        app.SetVisible(TRUE);
        TRACE("PowerPoint is Running!");
    }
}

8.To open a presentation from the hard disk, add this code in the Open button's function call.

void CPowerPntDlg::OnBtnOpen()
{
    static char BASED_CODE szFilter[] = "PowerPoint Files (*.ppt)|*.ppt||";
    CFileDialog FileDlg(TRUE,"PPT",NULL,OFN_FILEMUSTEXIST|OFN_NONETWORKBUTTON
                |OFN_PATHMUSTEXIST,szFilter);
    FileDlg.DoModal();

    // To get the selected file's path and name
    CString strFileName;
    strFileName = FileDlg.GetPathName();

    if(!strFileName.IsEmpty())
    {
        Presentations = app.GetPresentations();
        Presentation = Presentations.Open(strFileName,0,0,1);
    }
}

9.To close PowerPoint add this code in the Close button's function call.

void CPowerPntDlg::OnBtnClose()
{
    if (CanExit())
        app.Quit();
}

10.To run the slideshow use this code in the Run button's function call

void CPowerPntDlg::OnBtnRun()
{
    Presentations = app.GetActivePresentation();
    slides = Presentation.GetSlides();
    // Show the first slide of the presentation
    slide = slides.Item(COleVariant((long)1));

    //Run the show
    slideshow = Presentation.GetSlideShowSettings();
    slideshow.Run();
}

11.Sometimes, you might want to start all over from the first slide. To go to the first slide you can use this code.

void CPowerPntDlg::OnBtnFirst()
{
    Presentation = app.GetActivePresentation();
    SlideShowWindow = Presentation.GetSlideShowWindow();
    View = SlideShowWindow.GetView();
    View.First();
}

12.And similarly, to go to the last slide

void CPowerPntDlg::OnBtnLast()
{
    Presentation = app.GetActivePresentation();
    SlideShowWindow = Presentation.GetSlideShowWindow();
    View = SlideShowWindow.GetView();
    View.Last();
}

13.Now that you have the slideshow running, you would obviously want to go to the previous slide at some point of time. To do just that, you can use this code.

void CPowerPntDlg::OnBtnPrevious()
{
    Presentation = app.GetActivePresentation();
    SlideShowWindow = Presentation.GetSlideShowWindow();
    View = SlideShowWindow.GetView();
    View.Previous();
}

14.Interested to go to the next slide now ? In that case, this function will help you.

void CPowerPntDlg::OnBtnNext()
{
    Presentation = app.GetActivePresentation();
    SlideShowWindow = Presentation.GetSlideShowWindow();
    View = SlideShowWindow.GetView();
    View.Next();
}

[培训]内核驱动高级班,冲击BAT一流互联网大厂工作,每周日13:00-18:00直播授课

收藏
免费 0
支持
分享
最新回复 (18)
雪    币: 71
活跃值: (10)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
2
大家帮忙啊

尤其是英语好的朋友们!
2013-3-8 11:13
0
雪    币: 71
活跃值: (10)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
3
顶上去
e文高手帮忙啊
2013-3-9 12:38
0
雪    币: 196
活跃值: (135)
能力值: ( LV10,RANK:170 )
在线值:
发帖
回帖
粉丝
4
1. 创建一个基于对话框的应用程序,并且在向导中选中"automation"筛选框.
2. 添加如下按钮 "Start", "Run", "Close", "First Slide", "Last Slide", Previous Slide"
    "Next Slide"及相应的响应函数命名见下面的
3. 在InitInstance函数添加如下代码
// Initialize OLE libraries
if (!AfxOleInit())
{
    AfxMessageBox("Failed to initialize OLE");
    return FALSE;
}

4. 在对话框中-->Class wizard-->Automation Tab--> Add Class...-->From a type library 定位到Office安装目录下选择msppt8.olb

5.在对话框头文件中添加如下代码:
#include "msppt8.h"

6.在对话框头文件中添加如下变量
_Application app; // app is the PowerPoint _Application object
Presentations Presentations;
_Presentation Presentation;

SlideShowView View;

SlideShowWindow SlideShowWindow;
SlideShowSettings slideshow;
Slides slides;
_Slide slide;

下面就是在各按钮的响应函数中添加相应代码,注意:多了一个Open按钮.
7.To start PowerPoint, you have to write this code in the Start button's function.

void CPowerPntDlg::OnBtnStart()
{
    // Start PowerPoint and get Application object...
    if(!app.CreateDispatch("Powerpoint.Application"))
    {
        AfxMessageBox("Couldn't start PowerPoint.");
    }
    else // Make PowerPoint visible and display a message
    {
        app.SetVisible(TRUE);
        TRACE("PowerPoint is Running!");
    }
}

8.To open a presentation from the hard disk, add this code in the Open button's function call.

void CPowerPntDlg::OnBtnOpen()
{
    static char BASED_CODE szFilter[] = "PowerPoint Files (*.ppt)|*.ppt||";
    CFileDialog FileDlg(TRUE,"PPT",NULL,OFN_FILEMUSTEXIST|OFN_NONETWORKBUTTON
                |OFN_PATHMUSTEXIST,szFilter);
    FileDlg.DoModal();

    // To get the selected file's path and name
    CString strFileName;
    strFileName = FileDlg.GetPathName();

    if(!strFileName.IsEmpty())
    {
        Presentations = app.GetPresentations();
        Presentation = Presentations.Open(strFileName,0,0,1);
    }
}

9.To close PowerPoint add this code in the Close button's function call.

void CPowerPntDlg::OnBtnClose()
{
    if (CanExit())
        app.Quit();
}

10.To run the slideshow use this code in the Run button's function call

void CPowerPntDlg::OnBtnRun()
{
    Presentations = app.GetActivePresentation();
    slides = Presentation.GetSlides();
    // Show the first slide of the presentation
    slide = slides.Item(COleVariant((long)1));

    //Run the show
    slideshow = Presentation.GetSlideShowSettings();
    slideshow.Run();
}

11.Sometimes, you might want to start all over from the first slide. To go to the first slide you can use this code.

void CPowerPntDlg::OnBtnFirst()
{
    Presentation = app.GetActivePresentation();
    SlideShowWindow = Presentation.GetSlideShowWindow();
    View = SlideShowWindow.GetView();
    View.First();
}

12.And similarly, to go to the last slide

void CPowerPntDlg::OnBtnLast()
{
    Presentation = app.GetActivePresentation();
    SlideShowWindow = Presentation.GetSlideShowWindow();
    View = SlideShowWindow.GetView();
    View.Last();
}

13.Now that you have the slideshow running, you would obviously want to go to the previous slide at some point of time. To do just that, you can use this code.

void CPowerPntDlg::OnBtnPrevious()
{
    Presentation = app.GetActivePresentation();
    SlideShowWindow = Presentation.GetSlideShowWindow();
    View = SlideShowWindow.GetView();
    View.Previous();
}

14.Interested to go to the next slide now ? In that case, this function will help you.

void CPowerPntDlg::OnBtnNext()
{
    Presentation = app.GetActivePresentation();
    SlideShowWindow = Presentation.GetSlideShowWindow();
    View = SlideShowWindow.GetView();
    View.Next();
}
2013-3-9 13:47
0
雪    币: 15
活跃值: (15)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
5
好吧,有部分我还是参考了在线翻译的
Introduction
介绍
本教程帮助您了解自动化(技术)的基本知识。用这个代码你可以用你的应用程序控制PowerPoint。您能够打开PowerPoint编程,打开任何演示文稿,去你想去的任何幻灯片,运行幻灯片等。
Steps to follow
要遵循(跟随)的步骤
跟随下面给出的步骤,你可以(后面我也没看明白,逐字)使自动化,word,excel,或者任何MS应用程序。
1.创建一个基于对话框的应用程序,在应用程序向导的第3步,选择自动化复选框(automation checkbox)。
2.为开始、运行、关闭、第一张幻灯片、最后一张幻灯片、前一张幻灯片、下一张幻灯片函数创建按钮,并使用以下相应的函数。
3.在你的应用程序的InitInstance函数中,添加以下几行。
//初始化OLE库
if (!AfxOleInit())
{
    AfxMessageBox("初始化OLE库失败");
    return FALSE;
}

4.在你的对话框类中,打开类向导,选择自动化选项(automation tab),选择“添加类(Add Class)” ... “从类型库(From a type library)”,然后从"C:\Program Files\Microsoft Office\Office\"选择msppt8.olb
5.在你的对话框的头文件中,添加下面这行代码。
#include "msppt8.h"

6.在你的对话框的头文件中添加下列变量。
_Application app; // app is the PowerPoint _Application object
                            // app是PowerPoint _Application对象

Presentations Presentations;
_Presentation Presentation;

SlideShowView View;

SlideShowWindow SlideShowWindow;
SlideShowSettings slideshow;
Slides slides; 
_Slide slide;

7.为了启动PowerPoint ,你必须在“开始”按钮的函数中写下面这段代码。
void CPowerPntDlg::OnBtnStart()
{
    // Start PowerPoint and get Application object...
    // 启动PowerPoint ,然后获取应用程序对象...
    if(!app.CreateDispatch("Powerpoint.Application"))
    {
        AfxMessageBox("Couldn't start PowerPoint.");
    }
    else // Make PowerPoint visible and display a message,让PowerPoint可见,并显示一条消息
    {
        app.SetVisible(TRUE);
        TRACE("PowerPoint 正在运行!");
    }
}

8.为了从硬盘打开演示文稿,打开按钮的函数调用(Open button's function call)中添加此代码。
void CPowerPntDlg::OnBtnOpen()
{
    static char BASED_CODE szFilter[] = "PowerPoint Files (*.ppt)|*.ppt||";
    CFileDialog FileDlg(TRUE,"PPT",NULL,OFN_FILEMUSTEXIST|OFN_NONETWORKBUTTON
                |OFN_PATHMUSTEXIST,szFilter);
    FileDlg.DoModal();

    // To get the selected file's path and name
    // 为了得到所选文件的路径和名称
    CString strFileName;
    strFileName = FileDlg.GetPathName();

    if(!strFileName.IsEmpty())
    {
        Presentations = app.GetPresentations();
        Presentation = Presentations.Open(strFileName,0,0,1);
    }
}

9.为了关闭PowerPoint,在“关闭”按钮的函数调用中添加这个代码。
void CPowerPntDlg::OnBtnClose() 
{
    if (CanExit())
        app.Quit();
}

10.为了运行幻灯片,在运行按钮的函数调用中使用此代码
void CPowerPntDlg::OnBtnRun() 
{
    Presentations = app.GetActivePresentation();
    slides = Presentation.GetSlides(); 
    // Show the first slide of the presentation 
    // 显示第一张幻灯片的演示文稿
    slide = slides.Item(COleVariant((long)1)); 

    //Run the show 
    // 运行。。show?就是显示吧。。
    slideshow = Presentation.GetSlideShowSettings(); 
    slideshow.Run();
}

11.有时候,你可能会想从第一张幻灯片一切重新开始。要到第一张幻灯片,您可以使用此代码。
void CPowerPntDlg::OnBtnFirst() 
{
    Presentation = app.GetActivePresentation();
    SlideShowWindow = Presentation.GetSlideShowWindow();
    View = SlideShowWindow.GetView();
    View.First();
}

12.同样,去到最后一张幻灯片
void CPowerPntDlg::OnBtnLast() 
{
    Presentation = app.GetActivePresentation();
    SlideShowWindow = Presentation.GetSlideShowWindow();
    View = SlideShowWindow.GetView();
    View.Last();
}

13.现在你已经运行了幻灯片,你显然想要在某个时间点去到先前一张幻灯片。要做到这一点,你可以使用此代码。
void CPowerPntDlg::OnBtnPrevious() 
{
    Presentation = app.GetActivePresentation();
    SlideShowWindow = Presentation.GetSlideShowWindow();
    View = SlideShowWindow.GetView();
    View.Previous();
}

14.有兴趣去到下一张幻灯片吗?在那种情况下,这个函数将帮助您。
void CPowerPntDlg::OnBtnNext() 
{
    Presentation = app.GetActivePresentation();
    SlideShowWindow = Presentation.GetSlideShowWindow();
    View = SlideShowWindow.GetView();
    View.Next();
}

Conclusion
结论
似乎没什么用,还有下面似乎是说该文章没有许可,请作者联系之类的
2013-3-9 20:17
0
雪    币: 15
活跃值: (15)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
6
当然不是全手工了,还是有几行软件翻译的。好吧。吃饭去。就我翻译完了,分全给我吧。
2013-3-9 20:26
0
雪    币: 71
活跃值: (10)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
7
首先感谢两位的翻译,但是我做到一个地方,就不知道怎么做了:
就是第6条:
_Application app; // app is the PowerPoint _Application object
                            // app是PowerPoint _Application对象

Presentations Presentations;
_Presentation Presentation;

SlideShowView View;

SlideShowWindow SlideShowWindow;
SlideShowSettings slideshow;
Slides slides;
_Slide slide;
2013-3-10 14:04
0
雪    币: 71
活跃值: (10)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
8
lzDlg.cpp
C:\Program Files\Microsoft Visual Studio\MyProjects\lz\lzDlg.cpp(91) : error C2146: syntax error : missing ';' before identifier 'app'
C:\Program Files\Microsoft Visual Studio\MyProjects\lz\lzDlg.cpp(91) : error C2501: 'Application' : missing storage-class or type specifiers
C:\Program Files\Microsoft Visual Studio\MyProjects\lz\lzDlg.cpp(91) : fatal error C1004: unexpected end of file found
Error executing cl.exe.

lz.exe - 3 error(s), 0 warning(s)
编译的时候提示错误

好像丢了分号了
但是我有分号;啊
2013-3-10 14:23
0
雪    币: 15
活跃值: (15)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
9
好吧。你是初学C++么?建议看看教程。因为我不是专门玩C++的
首先文中说的是,在对话框头文件中添加
#include "msppt8.h"
你是在哪里添加?
创建MFC应用程序,下一步,选择基于对话框,下一步,下一步,选择自动化,下一步,完成
我命名为123,那么打开123.cpp,可以看到2010版本已经帮我们做好了第三步,只是有点点不同
打开类向导,选择CMy123DlgAutoProxy,”添加类“的箭头,类型库中的类,选择office的文件路径,找到msppt.olb或者msppt8.olb,选择》全部拉过来,完成。
对话框头文件,123dlg.h中,#include "msppt8.h"。然后没然后了,我的VS2010崩溃了。最近经常死掉
2013-3-10 15:09
0
雪    币: 2362
活跃值: (10)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
10
闲的蛋疼的人不少啊
2013-3-10 15:36
0
雪    币: 71
活跃值: (10)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
11
看来这分真要给你了

但是有个问题,这个类的名字怎么填?

我刚学c++
上传的附件:
2013-3-10 17:18
0
雪    币: 71
活跃值: (10)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
12
还有,按照你的做,就崩溃了

我用的是vc6.0
2013-3-10 18:40
0
雪    币: 71
活跃值: (10)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
13
顶上去,

求得大家帮助

谢谢
2013-3-11 21:09
0
雪    币: 71
活跃值: (10)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
14
up

尽管英语不好
2013-3-12 21:28
0
雪    币: 71
活跃值: (10)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
15
up again

3q
2013-3-15 12:01
0
雪    币: 15
活跃值: (15)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
16
帮你顶一下。
我是玩VB和delphi的,C++我只用来写驱动,其他乱七八糟的我不是很熟悉。所以不是很清楚。你发的那张图片是不是还应该有第四行?
2013-3-16 12:37
0
雪    币: 15
活跃值: (15)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
17
up,我是学生。所以星期六日才能回复你哦。
2013-3-17 15:00
0
雪    币: 71
活跃值: (10)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
18
第四行?
什么第四行?
没理解你的意思啊
2013-3-17 17:26
0
雪    币: 15
活跃值: (15)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
19
你发的那张图。。。
2013-3-23 22:12
0
游客
登录 | 注册 方可回帖
返回
//