青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品

How to create an automation project using MFC and a type library

This article was previously published under Q178749

On This Page

Expand all | Collapse all

SUMMARY
This article illustrates, in detail, how to automate component integration with...

This article illustrates, in detail, how to automate component integration with COM-compliant applications such as the Microsoft Office applications.

MORE INFORMATION
The following section illustrates how you can create an MFC project. The example...

The following section illustrates how you can create an MFC project. The example automates Microsoft Excel. You can use the first 8 steps for any project, and modify steps 9 through 15 when you work with another application.

Create an automation project

  1. With Microsoft Developer Studio, start a new "MFC AppWizard (exe)" project named "AutoProject."
  2. In step 1 of the MFC AppWizard, choose "Dialog Based" for the application type and then click Finish.

    The New Project Information dialog box appears and indicates that the Classes to be created include:
          Application: CAutoProjectApp in AutoProject.h and AutoProject.cpp
                        Dialog: CAutoProjectDlg in AutoProject.h and AutoProjectDlg.cpp
                        
    Click OK to create the project.
  3. The Dialog box "IDD_AUTOPROJECT_DIALOG" opens in the Visual Studio design/edit area. Modify it according to the instructions in the next two steps.
  4. Remove the Label control (IDC_STATIC) and the Cancel button (IDCANCEL).
  5. Change the name of the OK button to "IDRUN" and the caption to "Run." Close the AutoProject.rc dialog box design form.
  6. Click ClassWizard on the View menu (or press CTRL+W).
  7. Select the Message Maps tab. Select IDRUN in the Object Ids list box and select "BN_CLICKED" in the Messages list box. Click Add Function and accept the function name "OnRun". Click OK to close the ClassWizard.

    NOTE: This step adds a declaration for the function member "OnRun();" to the header file named AutoProjectDLG.h. This step also adds an empty skeleton message handler function named CAutoProjectDlg::OnRun() to the file named AutoProjectDLG.cpp.
  8. Click ClassWizard on the View menu (or press CTRL+W).
  9. Select the Automation tab. Click Add Class and choose "From a type library." Navigate to select the object library for the application you wish to automate (for this example, if you are automating Excel 97, choose the Microsoft Excel 8.0 Object Library; the default location is C:\Program Files\Microsoft Office\Office\Excel8.olb).

    If you are automating Microsoft Excel 2000, choose Microsoft Excel 9.0 Object Library for which the default location is the C:\Program Files\Microsoft Office\Office\Excel9.olb.

    If you are automating Microsoft Excel 2002 and Microsoft Office Excel 2003, the object library is embedded in the file Excel.exe. The default location for Excel.exe in Office 2002 is C:\program Files\Microsoft Office\Office10\Excel.exe. The default location for Excel.exe in Office 2003 is C:\program Files\Microsoft Office\Office11\Excel.exe. Once you have selected the appropriate object library, click Open. Select all classes in the Confirm Classes list, and then click OK.

    NOTE: The list box in the Confirm Classes dialog box contains all of the IDispatch interfaces (which are virtually identical to classes) in the Microsoft Excel type library. In the lower half of the dialog box you will see that an Implementation file named Excel8.cpp contains generated class wrappers derived from ColeDispatchDriver(), and the appropriate declaration header file is named Excel8.h. (For Excel 2002 and Excel 2003, the files are named Excel.cpp and Excel.h.)
  10. Click OK to close the MFC ClassWizard dialog box.
  11. Add the following code to the CAutoProjectApp::InitInstance() function, which loads and enables the COM services library:
          BOOL CAutoProjectApp::InitInstance()
                        {
                        if(!AfxOleInit())  // Your addition starts here
                        {
                        AfxMessageBox("Could not initialize COM dll");
                        return FALSE;
                        }                 // End of your addition
                        AfxEnableControlContainer();
                        .
                        .
                        .
                        }
                        
  12. Add the following line to the #include statements at the top of the AutoProject.cpp program file:
          #include <afxdisp.h>
                        
  13. Add the include statement for excel8.h after the include statement for stdafx.h at the top of the AutoProjectDlg.cpp program file:
          #include "stdafx.h"
                        #include "excel8.h" // excel.h in the case of Excel 2002 and Excel 2003.
                        
  14. Add automation code to the CAutoProjectDlg::OnRun() so that it appears as shown below:
          void CAutoProjectDlg::OnRun()
                        {
                        _Application app;  // app is the Excel _Application object
                        // Start Excel and get Application object...
                        if(!app.CreateDispatch("Excel.Application"))
                        {
                        AfxMessageBox("Couldn't start Excel.");
                        }
                        else
                        {
                        //Make Excel Visible and display a message
                        app.SetVisible(TRUE);
                        AfxMessageBox ("Excel is Running!");
                        }
                        }
                        
  15. Build and run the project. RESULTS: When you click the Run button in the dialog box, Microsoft Excel will be launched. Activate the Auto_Excel dialog box and dismiss the message box. Microsoft Excel will quit when the CAutoProjectDlg::OnRun() function ends because the application variable will have gone out of scope.

Additional Notes

Once you have added the classes from a type library to your project (as you did in step 9 above), you will notice that many classes have been added to the project. In ClassView, you can double-click a class to see the member functions of that class and then double-click the member function to view the definition of that function in the Excel8.cpp implementation file.

You need to go to the definition of a member function if you wish to verify a return type or if you need to change a function's implementation. Any time you change a function definition, remember to change the declaration in the Excel8.h file. When doing so, be sure that you change the correct function declaration; sometimes, the same name is given to member functions of multiple classes--GetApplication() is one such example.

Although the steps above illustrate how to automate Microsoft Excel, you can apply the same ideas to automating other applications. The list below contains the file names for the type libraries of the Microsoft Office applications:
   Application                           Type Library
                --------------------------------------------------
                Microsoft Access 97                   Msacc8.olb
                Microsoft Jet Database 3.5            DAO350.dll
                Microsoft Binder 97                   Msbdr8.olb
                Microsoft Excel 97                    Excel8.olb
                Microsoft Graph 97                    Graph8.olb
                Microsoft Office 97                   Mso97.dll
                Microsoft Outlook 97                  Msoutl97.olb
                Microsoft PowerPoint 97               Msppt8.olb
                Microsoft Word 97                     Msword8.olb
                Microsoft Access 2000                 Msacc9.olb
                Microsoft Jet Database 3.51           DAO360.dll
                Microsoft Binder 2000                 Msbdr9.olb
                Microsoft Excel 2000                  Excel9.olb
                Microsoft Graph 2000                  Graph9.olb
                Microsoft Office 2000                 Mso9.dll
                Microsoft Outlook 2000                Msoutl9.olb
                Microsoft PowerPoint 2000             Msppt9.olb
                Microsoft Word 2000                   Msword9.olb
                Microsoft Access 2002                 Msacc.olb
                Microsoft Excel 2002                  Excel.exe
                Microsoft Graph 2002                  Graph.exe
                Microsoft Office 2002                 MSO.dll
                Microsoft Outlook 2002                MSOutl.olb
                Microsoft PowerPoint 2002             MSPpt.olb
                Microsoft Word 2002                   MSWord.olb
                Microsoft Office Access 2003          Msacc.olb
                Microsoft Office Excel 2003           Excel.exe
                Microsoft Graph 2003                  Graph.exe
                Microsoft Office 2003                 MSO.dll
                Microsoft Office Outlook 2003         MSOutl.olb
                Microsoft Office PowerPoint 2003      MSPpt.olb
                Microsoft Office Word 2003            MSWord.olb
                
NOTE: The default location for these type libraries is C:\Program Files\Microsoft Office\Office (for Office 2002 the path is C:\...\Office10 and for Office 2003 the path is C:\...\Office11), except for Dao350.dll or Dao360.dll, and Microsoft Office 10(MSO.dll). The default location for Dao350.dll/Dao360.dll is C:\Program Files\Common Files\Microsoft Shared\Dao. The default location for MSO.dll is C:\Program Files\Common Files\Microsoft Shared\Office10 for Office 2002 and C:\Program Files\Common Files\Microsoft Shared\Office11 for Office 2003.

REFERENCES
This article presents a specific approach to building a dialog-box project. If y...

This article presents a specific approach to building a dialog-box project. If you would like to see more general documentation about the process of building a VC++ project in the Microsoft Developer Studio environment, there is an excellent tutorial you can access by using Visual Studio InfoView. To access the tutorial, click Search on the Help menu. Click the index tab and type the following:
working with projects
Click List Topics. Select the topic "Home Page: Working With Projects" and click Display. For more information about the automation of Office applications, click the following article number to view the article in the Microsoft Knowledge Base:
222101  (http://support.microsoft.com/kb/222101/ ) How to find and use Office object model documentation

APPLIES TO
  • Microsoft Foundation Class Library 4.2, when used with:
    • Microsoft Visual C++ 5.0 Standard Edition
    • Microsoft Visual C++ 6.0 Service Pack 5
  • Microsoft Office XP Developer Edition
  • Microsoft Office 2000 Developer Edition

posted on 2010-04-17 07:55 wrh 閱讀(1265) 評論(0)  編輯 收藏 引用


只有注冊用戶登錄后才能發表評論。
網站導航: 博客園   IT新聞   BlogJava   博問   Chat2DB   管理


導航

<2011年8月>
31123456
78910111213
14151617181920
21222324252627
28293031123
45678910

統計

常用鏈接

留言簿(19)

隨筆檔案

文章檔案

收藏夾

搜索

最新評論

閱讀排行榜

評論排行榜

青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品
  • <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>
            亚洲性线免费观看视频成熟| 国产精品国产三级国产aⅴ无密码 国产精品国产三级国产aⅴ入口 | 亚洲一二三级电影| 欧美激情亚洲自拍| 麻豆成人在线| 免费日韩av| 亚洲国产视频直播| 欧美搞黄网站| 欧美激情影音先锋| 亚洲日本va在线观看| 日韩视频在线观看| 亚洲欧美精品| 久久免费精品日本久久中文字幕| 久久免费视频一区| 欧美激情中文不卡| 国产精品成人一区二区三区吃奶| 国产精品区一区| 国产精品腿扒开做爽爽爽挤奶网站| 国产欧美综合一区二区三区| 国产精品视频99| 一区二区三区欧美在线| 国产精品99久久不卡二区| 日韩一级黄色片| 亚洲欧美日韩精品| 久久夜色精品亚洲噜噜国产mv| 免费中文字幕日韩欧美| 欧美日韩在线高清| 国自产拍偷拍福利精品免费一| 亚洲福利视频三区| 亚洲婷婷免费| 久久久水蜜桃| 亚洲美女性视频| 欧美亚洲免费| 欧美日韩国产一区| 国产自产v一区二区三区c| 91久久极品少妇xxxxⅹ软件| 亚洲一级特黄| 蜜臀a∨国产成人精品| 在线一区二区三区做爰视频网站| 欧美一区二区三区视频免费| 欧美国产一区二区在线观看| 国产伦精品一区二区三区视频黑人| 亚洲高清色综合| 欧美一级在线播放| 亚洲日本va午夜在线影院| 欧美一区高清| 国产精品久久久久99| 亚洲欧洲三级电影| 久久躁日日躁aaaaxxxx| 亚洲图片欧洲图片日韩av| 麻豆av一区二区三区| 国产日韩欧美自拍| 国产视频在线一区二区| 在线视频亚洲一区| 亚洲国产欧美久久| 久久久久青草大香线综合精品| 国产精品视频免费| 亚洲小说春色综合另类电影| 亚洲高清久久久| 久久一区国产| 在线免费高清一区二区三区| 久久蜜桃香蕉精品一区二区三区| 亚洲一区二区三区在线观看视频| 欧美人体xx| 一个人看的www久久| 亚洲日本va午夜在线电影| 欧美精品亚洲精品| 亚洲美女诱惑| 亚洲欧洲在线一区| 欧美日韩久久久久久| 一本一本a久久| 一本色道久久综合亚洲精品高清| 欧美日韩精品系列| 亚洲午夜羞羞片| 亚洲午夜极品| 国产在线精品二区| 麻豆精品精华液| 欧美伊人久久久久久久久影院| 欧美视频专区一二在线观看| 妖精成人www高清在线观看| 欧美激情第二页| 欧美成人免费全部| 夜夜嗨av一区二区三区网站四季av| 亚洲欧洲日韩女同| 欧美日韩蜜桃| 亚洲毛片在线| 亚洲午夜精品一区二区| 国产精品网站一区| 欧美有码视频| 亚欧美中日韩视频| 精品二区久久| 在线视频亚洲欧美| 欧美一区二区三区精品| 国内精品久久久久伊人av| 久久久亚洲影院你懂的| 久久精品亚洲精品| 在线免费观看欧美| 亚洲丝袜av一区| 国产精品一区在线观看| 久久精品主播| 久久久久久综合网天天| 亚洲激情不卡| 亚洲无线一线二线三线区别av| 午夜精品久久久| 一区精品久久| 91久久精品www人人做人人爽| 欧美精品播放| 亚洲女人天堂成人av在线| 一区二区三区毛片| 国产日韩精品在线| 欧美激情在线观看| 国产精品黄色| 久久亚洲精品伦理| 国产精品区二区三区日本| 久久尤物视频| 欧美日韩一区二区高清| 久久精品导航| 欧美国产精品劲爆| 美女视频黄免费的久久| 欧美日韩亚洲一区三区| 欧美综合77777色婷婷| 老鸭窝91久久精品色噜噜导演| 一本一本a久久| 欧美 日韩 国产一区二区在线视频| 亚洲靠逼com| 亚洲视频国产视频| 亚洲国产精品va| 亚洲尤物精选| 亚洲一区二区三区精品在线 | 欧美大秀在线观看| 亚洲一区国产视频| 欧美国产日韩a欧美在线观看| 国产精品99久久久久久白浆小说| 久久精品最新地址| 新片速递亚洲合集欧美合集| 免费av成人在线| 欧美在线视频一区| 国产精品在线看| 久久电影一区| 亚洲一区在线播放| 欧美日韩免费一区| 亚洲人线精品午夜| 伊人成人在线视频| 亚洲一区二区免费在线| 亚洲精品一区二区三区av| 亚洲综合国产精品| 一本一本久久a久久精品综合妖精| 久久精品国产视频| 欧美一区二区三区精品| 欧美日韩精品免费观看视频| 欧美日精品一区视频| 亚洲色图自拍| 亚洲一区二区免费看| 亚洲天堂男人| 亚洲综合大片69999| 欧美人成在线视频| 最新国产乱人伦偷精品免费网站| 伊人久久亚洲美女图片| 欧美一区二区免费| 久久九九99| 亚洲黄色尤物视频| 欧美精品国产一区| 亚洲美女网站| 国产精品视频导航| 久久伊人亚洲| 欧美激情国产日韩| 亚洲精品久久久久久久久久久久| 久久九九热免费视频| 久久都是精品| 在线电影院国产精品| 麻豆精品视频在线观看| 欧美激情影音先锋| 一区二区免费看| 国产情人节一区| 久久久久久久久蜜桃| 男人的天堂亚洲在线| 国产视频欧美| 久久久噜噜噜久久中文字免| 欧美成人在线影院| 亚洲三级网站| 欧美日韩在线精品| 99国产成+人+综合+亚洲欧美| 亚洲图片激情小说| 国产欧美一区二区三区久久人妖| 久久久久久**毛片大全| 欧美一区二区三区日韩视频| 国产精品夫妻自拍| 欧美一区二区三区日韩| 欧美黑人多人双交| 在线一区日本视频| 国产日韩精品综合网站| 欧美一区激情视频在线观看| 欧美成人按摩| 亚洲一区二区在线| 在线成人激情黄色| 国产精品女人网站| 蜜臀va亚洲va欧美va天堂| 亚洲一二三区精品| 免费在线观看日韩欧美| 亚洲欧美日韩精品久久久|