???? ID: 237554 - ????? ???????: 06 ??????? 2011 - ??????: 3.0

????? C++ 5.0 ?? ????? C++ 6.0 ??? Microsoft ????????? ???? ?? ????? ?? PowerPoint ?? ???????? ???? ?? ??? ???? ????

?????? ??????This article applies to a different operating system than the one you are using. Article content that may not be relevant to you is disabled.
??? ?? ??????? ???? | ??? ?? ??????? ????

??????

?? ???? ????? ???? ?? ?? Microsoft Visual C++ 5.0 ?? ????? C++ 6.0 ??? Microsoft ????????? ???? (MFC) ?? ????? ?? Microsoft PowerPoint ?? ???????? ???? ?? ??? ???? ?????

PowerPoint ?? ???????? ???? ?? ??? ?? ?? ????????? ??? ????? ?? ?? ???? ?????? ?? ????? ?? ??? ?? Microsoft ????????? ???? ?? ????? ?? ?????

???? ???????

??????????, ?????? ????????? ??? ??? ?????? ?? ?????? ?? ??? ???? ??????? ?? ????? ?? ???? ???? ???????, ???? ???????? ??? ?????? ??? ???? SAFEARRAY ?????? ?? ?? ?? ???????? ?? ?? ??? ???? ??? ?????? ?? ?? ????? ??? ????? ??? ????? ?? ???? ?? ????? ????? ??????
  // method 'MyMethod' not emitted because of invalid return type or    parameter type
				
?? ?? Microsoft PowerPoint ?? ??? ???? ???? ?? ??????? ???? ?? ??? ???? ??????? ?? ?????Application::Run?????? wrapped ???? ???? ????? ??????? ?? ?????? ?? ?? ???? ??? ???? SAFEARRAY. ?? ???? ?? ????? ???? application::Run ??? ?? ??? ?? ???? ???InvokeHelper?????? DISPID 0x7e6 ?? ???? ?? ????? ?? ?????????? ?????? ?? ???, ?? ?? ???? ??? ???? OLE/COM ?????? ????? ?? PowerPoint ?????? ??????????

????? ????? ?? ???? ???? ?? application::Run ?? ??? ???? ?? ???? PowerPoint ?? ????? ?? ??? PowerPoint ???????? ?? ???? ??? illustrate ???????

?????? ?? PowerPoint ????????? ????? ?? ??? ???

  1. Microsoft PowerPoint ??????? ????, ?? ??? ????? ???????? ?? ??? ??? ?? ????????? ??????
  2. Visual Basic ?????? ??????? ???? ?? ??? ALT+F11 ?????..
  3. ?????????? ???????? ??,????????? ????????? ??? ?? ??????? ???????? ???? ???? ?? ????
  4. ??????? ??? ????? ??? ???????
       Sub ChangeBackColor()  'Change backcolor of slides 1, 2 and 3
        With ActivePresentation.Slides.Range(Array(1, 2, 3))
            .FollowMasterBackground = msoFalse
            .Background.Fill.ForeColor.SchemeColor = ppAccent2
        End With
       End Sub
    
       Sub ChangeText(vArray As Variant)
        'Add a text box to each slide and use the text from the
        'array passed into this procedure
        Dim s As Slide
        For i = 1 To ActivePresentation.Slides.Count
            With ActivePresentation.Slides(i).Shapes.AddTextbox( _
                            msoTextOrientationHorizontal, 186#, 54#, 336#, 36#)
                .TextFrame.TextRange.Text = vArray(i - 1)
                .TextFrame.TextRange.Font.Size = 60
            End With
        Next
       End Sub
    						
  5. ????????? ?? ?? ?????, ?? ???? ??? ??? PowerPoint ?? ??? ??? ??????:
    • PowerPoint 2007 ???, C:\Pres.pptm ???? ??? ????? ??? ?? ????? ???? ????????? ?? ???? ?????? ????? ????????? (*.pptm) ?? ??? ??? ???????
    • PowerPoint 2003 ??? ?? PowerPoint ?? ????? ????????? ???, ????????? ?? ?????? ??? ????????? ?? ??? ??? (*. ppt) C:\Pres.ppt ???? ??? ????? ??? ?? ????? ?????

MFC ????????? ????? ?? ??? ???

  1. ??? ??? MFC ????? ????? ?????? ????????? ??? ?????AutoPPT.
  2. ??????????? (?? CTRL + W ?????), ???? ??????? ?? ??? ????, ?? ???? ??? ????? ????? ?? ???? ????:
    1. ????? ?????????????? ?? ????? ????..
    2. ????? ????,????? ???????? ????-????? ????, ?? ???? ????????? ????????? ??.
    3. PowerPoint ????????? ?? ?????? ?????, ?? ??? PowerPoint ?????? ????????? ??? ??????:
      • PowerPoint 2007, ?? ??? ??????Msppt.olb.
      • PowerPoint 2003 ?? ??? ??????Msppt.olb.
      • PowerPoint 2002, ?? ??? ??????Msppt.olb.
      • PowerPoint 2000, ?? ??? ??????Msppt9.olb.
      • PowerPoint 97 ?? ??? ??????Msppt8.olb.
  3. ?????? ID IDD_AUTOPPT_DIALOG ?? ??? ????? ????? ?? ??? ????? ????? ????? ??? ?? ??? ??????, ?? ???? ??? ?? ??? ?? ??? ?????? ?? ??? ????? ??? ???????
       _Application	oApp;
       if(!oApp.CreateDispatch("Powerpoint.Application"))
       {
            AfxMessageBox("Could not get Powerpoint application.");
            return;
       }
       oApp.SetVisible(TRUE);
    
    
       //Get the Presentations collection and open a presentation
       Presentations oPresSet(oApp.GetPresentations());
       CString strFilename;
       //For PowerPoint 2007, change the file name to "c:\\pres.pptm"
       strFilename = "c:\\pres.ppt";
       _Presentation oPres(oPresSet.Open(strFilename, // Filename
                                         true,        // Readonly
                                         false,       // Untitled
                                         true         // WithWindow
                          ));
    		
       //*************** How to Run PowerPoint Macros *********************
    
       // Run "ChangeBackColor" macro in the presentation -- note that the
       // "ChangeBackColor" macro requires no arguments
    
       {
           COleVariant vOpt((long)DISP_E_PARAMNOTFOUND, VT_ERROR);
           static BYTE parms[] = 
                VTS_BSTR  VTS_VARIANT;
           LPCTSTR lpszMacroName = "Pres.ppt!ChangeBackColor";
    
           oApp.InvokeHelper(0x7e6, DISPATCH_METHOD, VT_EMPTY, NULL,  parms,
                             lpszMacroName, //Macro Name
                             &vOpt          //No arguments, for example, ignore
                            );
       }
    			
    
       // Run "ChangeText" macro in the presentation;
       // The macro requires three arguments -- the first two are strings
       // and the last one is a long	
    		
       {
    
            COleSafeArray saArgs;  //Create a 1-dimensional array with three 
                                   //elements
    
            DWORD numElements[1];
            numElements[0]= 3;	
            saArgs.Create(VT_VARIANT, 1, numElements);	
            long index[1];
            VARIANT v;
    
            index[0]=0;		//Fill 1st element
            CString sName("ABC");
            VariantInit(&v);
            v.vt= VT_BSTR;
            v.bstrVal = sName.AllocSysString();
            saArgs.PutElement(index, &v);
            SysFreeString(v.bstrVal);
            VariantClear(&v);
    
            index[0]=1;		//Fill 2nd element
            CString sCompany("XYZ");
            VariantInit(&v);
            v.vt= VT_BSTR;
            v.bstrVal = sCompany.AllocSysString();
            saArgs.PutElement(index, &v);
            SysFreeString(v.bstrVal);
            VariantClear(&v);
    
            index[0]=2;		//Fill 3rd element
            VariantInit(&v);
            v.vt = VT_I4;
            v.lVal=123;
            saArgs.PutElement(index, &v);
            VariantClear(&v);
    
            static BYTE parms[] = 
                 VTS_BSTR  VTS_VARIANT;
            LPCTSTR lpszMacroName = "Pres.ppt!ChangeText";
            oApp.InvokeHelper(0x7e6, DISPATCH_METHOD, VT_EMPTY, NULL, parms,
                              lpszMacroName,   //Macro Name
                              (VARIANT*)saArgs //Array of macro parameters 
                             );
    
            saArgs.Detach();
       }
    
    						
    ???:??? ?? PowerPoint 2002 ?????? ????????? ??? ???? wrapped, ????? ???? ?? ??? ??? ???? ?? ??? ?? ???????? ???? (false) ???????
  4. ??????? ????? ??? PowerPoint ?? ??? ?????? ????? ??? ?????
    #include "msppt8.h" // use msppt9.h for 2000 or msppt.h for 2002, 2003, and 2007
    					
  5. ??? ?? ????? ?????? ?? ???? ??? ??????CAutoPPTApp::InitInstance()?????? ?? ??? ???? ???..
         AfxOleInit();
    						
  6. ?????? ???? ?? ?????? ??????? ??? ?? ????? ?? ??? ????? ????? ??? ????? ' ??? ?? ??? ????? ??? ???? ???? ???, ?? ??? PowerPoint ????? ??? ??? ?? ????????? ??? ???????? ?????? ??? ?? ???????? ?????

??????

For more information about automating PowerPoint using Visual C++, please see the following article in the Microsoft Knowledge Base:
180616  (http://support.microsoft.com/kb/180616/ ) How to use MFC to create and show a PowerPoint presentation

???? ???? ???? ??:
  • Microsoft Office PowerPoint 2007
  • Microsoft Office PowerPoint 2003
  • Microsoft PowerPoint 2002 Standard Edition
  • Microsoft PowerPoint 2000 Standard Edition
  • Microsoft PowerPoint 97 Standard Edition
  • Microsoft Visual C++ 5.0 Professional Edition
??????: 
kbexpertiseinter kbautomation kbhowto kbmt KB237554 KbMthi
???? ?????? ???????????? ?????? ????????
??????????: ?? ???? ?? ???? ??????? ?? ????? ?? Microsoft ????-?????? ?????????? ?????? ?????? ???? ??? ??. Microsoft ???? ??? ????-???????? ?? ????-???????? ????? ?????? ?? ???? ???????? ???? ?? ???? ????? ????? ??? ?? ??? ?????? ?? ???? ???? ???? ??? ????? ??. ???????, ????-???????? ???? ????? ???? ???? ???? ???. ?????, ????????, ?????-???? ?? ??????? ?? ???????? ?? ???? ???, ???? ?? ??? ?????? ???? ???? ??? ????? ??? ?? ???? ??. Microsoft ??????? ??? ???? ?? ?????? ?? ??????????, ????????? ?? ??? ?????? ?? ???? ????? ?? ???? ???????? ?? ??? ???? ????? ?? ??? ????????? ???? ??. Microsoft ????-?????? ?????????? ?? ????? ?????? ?? ?? ??? ??.
?????????? ?? ??????? ????????? ??????? ??:237554  (http://support.microsoft.com/kb/237554/en-us/ )