如何獲取PPT一幀影片結束事件
uj5u.com熱心網友回復:
樓主做出來了沒有?我現在也需要這個功能,求樓主共享一下uj5u.com熱心網友回復:
使用 Application 物件的事件請參閱 特性
若要為 Application 物件的事件創建事件句柄,需要完成以下三個步驟:
在類模塊中宣告一個物件變數以回應事件。
撰寫特定的事件程序。
在另一模塊中初始化宣告的物件。
宣告物件變數
在為 Application 物件的事件撰寫程序之前,必須新建一個類模塊,然后宣告一個具有事件的 Application 型別的物件。例如,假設已新建一個類模塊且其名稱為 EventClassModule。該新類模塊包含以下代碼。
Public WithEvents App As Application
撰寫事件程序
宣告具有事件的新物件之后,該物件就會出現在類模塊的“物件”串列中,然后就可以為此新物件撰寫事件程序。(當在“物件”串列中選擇新物件時,“程序”串列中就會列出該物件的有效事件。)從“程序”串列中選擇一個事件;就會在類模塊中添加一個空程序。
Private Sub App_NewPresentation()
End Sub
初始化宣告的變數
在程序運行之前,必須將類模塊中宣告的物件(本示例中為 App)與 Application 物件相連。用戶可以在任意模塊中使用以下代碼實作此處理程序。
Dim X As New EventClassModule
Sub InitializeApp()
Set X.App = Application
End Sub
運行 InitializeApp 程序。當運行此程序后,類模塊中的 App 物件就會指向 Microsoft PowerPoint 的 Application 物件,然后當事件發生時,類模塊中的事件程序就會運行。
全部顯示
SlideShowEnd 事件
請參閱 應用于 示例 特性
本事件幻燈片放映結束后——即最后一個 SlideShowNextSlide 事件后發生。
Private Sub application_SlideShowEnd(ByVal Pres As Presentation)
application Application 型別的物件,在類模塊中宣告,自身具有事件。有關使用 Application 物件的事件的詳細資訊,請參閱使用 Application 物件的事件。
Pres 當發生此事件時關閉演示文稿。
說明
如果 SlideShowBegin 事件已發生,則 SlideShowEnd 事件總發生在幻燈片放映結束之前。用戶可使用 SlideShowEnd 事件將 SlideShowBegin 事件中發生的任何屬性設定和變數初始值恢復到最初的設定。
示例
本示例在幻燈片放映結束時關閉從第一張到第四張幻燈片的條目效果和自動定時換片幻燈片放映切換效果。本示例也將幻燈片設定為手動換片。
Private Sub App_SlideShowEnd(ByVal Pres As Presentation)
With Pres.Slides.Range(Array(1, 4)) _
.SlideShowTransition
.EntryEffect = ppEffectNone
.AdvanceOnTime = msoFalse
End With
With Pres.SlideShowSettings
.AdvanceMode = ppSlideShowManualAdvance
End With
End Sub
uj5u.com熱心網友回復:
全部顯示
SlideShowNextSlide 事件
請參閱 應用于 示例 特性
切換到下一張幻燈片立刻發生此事件。對于第一張幻燈片,此事件緊跟在 SlideShowBegin 事件之后發生。
Private Sub application_SlideShowNextSlide(ByVal Wn As SlideShowWindow)
application Application 型別的物件,在類模塊中宣告,自身具有事件。有關使用 Application 物件的事件的詳細資訊,請參閱使用 Application 物件的事件。
Wn 活動幻燈片放映視窗。
示例
本示例確定了發生 SlideShowNextSlide 事件后幻燈片的位置。如果下一張幻燈片是第三張幻燈片,則本示例將滑鼠指標的型別更改為筆形且顏色更改為紅色。
Private Sub App_SlideShowNextSlide(ByVal Wn As SlideShowWindow)
Dim Showpos As Integer
Showpos = Wn.View.CurrentShowPosition + 1
If Showpos = 3 Then
With ActivePresentation.SlideShowSettings.Run.View
.PointerColor.RGB = RGB(255, 0, 0)
.PointerType = ppSlideShowPointerPen
End With
Else
With ActivePresentation.SlideShowSettings.Run.View
.PointerColor.RGB = RGB(0, 0, 0)
.PointerType = ppSlideShowPointerArrow
End With
End If
End Sub
本示例將全域計數器變數的值設定為 0。然后計算此事件后幻燈片上的形狀個數,確定哪些形狀具有影片,并用每個形狀的影片順序和編號填充全域陣列。
注意 本示例中創建的陣列還用于 SlideShowNextBuild 事件示例中。
Private Sub App_SlideShowNextSlide(ByVal Wn As SlideShowWindow)
Dim i as Integer, j as Integer, numShapes As Integer
Dim objSld As Slide
Set objSld = ActivePresentation.Slides _
(ActivePresentation.SlideShowWindow.View _
.CurrentShowPosition + 1)
With objSld.Shapes
numShapes = .Count
If numShapes > 0 Then
j = 1
ReDim shpAnimArray(1 To 2, 1 To numShapes)
For i = 1 To numShapes
If .Item(i).AnimationSettings.Animate Then
shpAnimArray(1, j) = _
.Item(i).AnimationSettings.AnimationOrder
shpAnimArray(2, j) = i
j = j + 1
End If
Next
End If
End With
End Sub
uj5u.com熱心網友回復:
HOW TO: Handle PowerPoint Events by Using Visual C++ .NET and MFCKnowledge Base
HOW TO: Handle PowerPoint Events by Using Visual C++ .NET and MFC
PSS ID Number: Q309309
Article Last Modified on 09-25-2002
--------------------------------------------------------------------------------
The information in this article applies to:
Microsoft Visual C++ .NET (2002)
Microsoft PowerPoint 2000
Microsoft PowerPoint 2002
--------------------------------------------------------------------------------
For a Microsoft Visual C# .NET version of this article, see Q308825 .
For a Microsoft Visual Basic .NET version of this article, see Q308330 .
IN THIS TASK
SUMMARY
PowerPoint Events
Create a C++ Application to Handle PowerPoint Events
Test the Application
REFERENCES
Summary
This step-by-step article describes how to automate PowerPoint and handle events by using Visual C++ .NET.
back to the top
PowerPoint Events
PowerPoint fires events in response to user actions or in response to some methods that are called through Automation. The Application object in the PowerPoint object model fires these events on its outgoing interface, EApplication.
To view this interface and its methods, you can use the OLE/COM Object Viewer, as follows:
On the Tools menu in Visual Studio .NET, select OLE/COM Object Viewer.
Expand the node for Type Libraries and select Microsoft PowerPoint Object Library in the list.
On the Object menu, select View to open the library in the ITypeLib Viewer.
Expand the node for coclass Application and select EApplication.
Note that EApplication is derived from IDispatch and is not the dispinterface that is commonly used as a source interface. If the source interface is a dispinterface, you can determine the dispatch identifiers (DISPIDs) for its methods by using the OLE/COM Object Viewer. However, because EApplication is not a dispinterface, you cannot determine the DISPIDs for PowerPoint events by examining the type library.
The following table lists DISPIDs for the events that the PowerPoint 2000 and PowerPoint 2002 object models expose:
DISPID Method Name PowerPoint 2002 Only
2001 WindowSelectionChange
2002 WindowBeforeRightClick
2003 WindowBeforeDoubleClick
2004 PresentationClose
2005 PresentationSave
2006 PresentationOpen
2007 NewPresentation
2008 PresentationNewSlide
2009 WindowActivate
2010 WindowDeactivate
2011 SlideShowBegin
2012 SlideShowNextBuild
2013 SlideShowNextSlide
2014 SlideShowEnd
2015 PresentationPrint
2016 SlideSelectionChanged x
2017 ColorSchemeChanged x
2018 PresentationBeforeSave x
2019 SlideShowNextClick x
uj5u.com熱心網友回復:
You can sink a PowerPoint event in your C++ application by calling IConnectionPointContainer::FindConnectionPoint to find the connection point for the desired event interface, and then IConnectionPoint::Advise with the IUnknown interface of your implementation for that event.back to the top
Create a C++ Application to Handle PowerPoint Events
Create a new dialog box-based application by using the Microsoft Foundation Classes (MFC) Application Wizard in Visual C++ .NET. Name your project PPTEventsDemo, and then accept the default settings. The dialog box is created by default, along with the corresponding Ppteventsdemodlg.cpp and Ppteventsdemodlg.h files.
Add three buttons to your dialog box, and then name the buttons Launch PowerPoint, Establish Connection Point and Register Sink, and UnRegister Sink and Do Clean Up, respectively. Add a list box to the dialog box. The list box displays the names of the events as they occur.
In the Project explorer window in Class View, right-click PPTEventsDemo, point to Add, and then click Add Class. In the Add Class dialog box, select MFC class from TypeLibrary and then click Open. This starts the Add Class from TypeLib wizard.
Select Microsoft PowerPoint 10.0 object library (for PowerPoint 2002) or Microsoft PowerPoint 9.0 object library (for PowerPoint 2000) from the Available TypeLibraries drop-down list. The Interfaces list box displays all of the interfaces that the type library exposes. Select _Application and then click the > button. Accept the defaults and then click Finish. This generates the CApplication wrapper class, which is derived from COleDispatchDriver. The implementation and definition of this class is available in the Capplication.h file.
In Visual Studio .NET, click Resource View on the View menu to show the PPTEventsDemo dialog box. Double-click Launch PowerPoint to show the Code View window for Ppteventsdemodlg.cpp, where an empty event handler has been inserted for the Click event of that button. Add the following code to the handler for the Launch PowerPoint button:
if(!pptapp.CreateDispatch("Powerpoint.Application"))
{
AfxMessageBox("Could not create Powerpoint object.");
return;
}
pptapp.put_Visible((long) 1);
uj5u.com熱心網友回復:
Add the following code to the handler for the Establish Connection Point and Register Sink button:///*********************** Start of code to get connection point **************
// Declare the events that you want to catch.
//
// Look for the coclass for Application in the Msppt9.olb typelib,
// then look for the word "source." The EApplication interface
// is the next search target. When you find it, you will see the
// following GUID for the event interface.
// 914934C2-5A91-11CF-8700-00AA0060263B
static const GUID IID_IEApplication =
{0x914934C2,0x5A91,0x11CF, {0x87,0x00,0x00,0xAA,0x00,0x60,0x26,0x3b}};
// Steps for setting up events.
// 1. Get the IConnectionPointContainer interface of the server.
// 2. Call IConnectionPointContainer::FindConnectionPoint()
// to find the event that you want to catch.
// 3. Call IConnectionPoint::Advise() with the IUnknown
// interface of your implementation of the events.
HRESULT hr;
// Get the (PPT) IConnectionPointContainer interface of the server.
IConnectionPointContainer *pConnPtContainer;
hr = pptapp.m_lpDispatch->QueryInterface(
IID_IConnectionPointContainer,
(void **)&pConnPtContainer
);
if(FAILED(hr)) AfxMessageBox("Couldn't get IConnectionPointContainer interface.");
ASSERT(!FAILED(hr));
// Find a connection point for the events that you are interested in.
hr = pConnPtContainer->FindConnectionPoint(
IID_IEApplication,
&m_pConnectionPoint
);
if(FAILED(hr)) AfxMessageBox("Couldn't find connection point via event GUID.");
ASSERT(!FAILED(hr));
//Instantiate the sink object.
m_sink = new CMyPPTEventsHandler();
//Update the list box when you obtain the events in the event handler.
m_sink->m_pListBox = m_listBox;
// Get the IUnknown interface of your event implementation.
LPUNKNOWN pUnk = NULL;
pUnk = m_sink->GetInterface(&IID_IUnknown);
ASSERT(pUnk);
// Setup advisory connection.
hr = m_pConnectionPoint->Advise(pUnk, &m_sink->cookie);
ASSERT(!FAILED(hr));
// Release the IConnectionPointContainer interface.
pConnPtContainer->Release();
// *********************** End of code to get connection point ******************
Add the following code to a handler for the UnRegister Sink and Do Clean Up button:
//Use the cookie to unregister the sink.
m_pConnectionPoint->Unadvise(m_sink->cookie);
m_pConnectionPoint->Release();
//Detach the application object from the server.
pptapp.DetachDispatch();
Add the following code to the bottom of the constructor in the CPPTEventsDemoDlg class:
m_pConnectionPoint = NULL;
pptapp = NULL;
Before you return from CPPTEventsDemoDlg::OnInitDialog, add the following line of code:
//Get the MFC class pointer for the list box on the dialog box.
m_listBox = (CListBox*) GetDlgItem(IDC_LIST1);
Be sure that you place the following #include statements at the beginning of the Ppteventsdemodlg.cpp file:
#include "stdafx.h"
#include "CApplication.h"
#include "MyPPTEventsHandler.h"
#include "PPTEventsDemo.h"
#include "PPTEventsDemoDlg.h"
Forward declare the following classes in the Ppteventsdemodlg.h file:
class CMyPPTEventsHandler;
class CApplication;
Add the following declarations as private members to CPPTEventsDemoDlg:
IConnectionPoint* m_pConnectionPoint;
CApplication pptapp;
CMyPPTEventsHandler* m_sink;
CListBox* m_listBox;
In Class View in Project Explorer, right-click PPTEventsDemo, point to Add, and then click Add Class. In the AddClass dialog box, select MFC class under Templates, and then click Open. Type CMyPPTEventsHandler for the class name, select CCmdTarget for the base class, and then select Automation. For other fields, accept the defaults. Click Finish.
This creates a new CMyPPTEventsHandler MFC class that is derived from CCmdTarget. This class is defined in the Myppteventshandler.h file and is implemented in Myppteventshandler.cpp. This is the Event Handler class that contains methods that are called in response to the PowerPoint events.
uj5u.com熱心網友回復:
頂頂頂 技術高uj5u.com熱心網友回復:
In the Myppteventshandler.h file, forward declare the following class:class CPresentation;
In the Myppteventshandler.h file, add the following members to the public declarations in the CMyPPTEventsHandler class:
DWORD cookie;
CListBox* m_pListBox;
Add the following methods to the protected declarations in the CMyPPTEventsHandler class:
void WindowSelectionChange(LPDISPATCH Pres);
void WindowBeforeRightClick(LPDISPATCH Pres, VARIANT_BOOL* Cancel);
void WindowBeforeDoubleClick(LPDISPATCH Pres, VARIANT_BOOL* Cancel);
void PresentationClose ( LPDISPATCH Pres);
void PresentationSave( LPDISPATCH Pres);
void PresentationOpen( LPDISPATCH Pres);
void NewPresentation( LPDISPATCH Pres);
void PresentationNewSlide( LPDISPATCH Pres);
void WindowActivate( LPDISPATCH Pres,LPDISPATCH Wn);
void WindowDeactivate(LPDISPATCH Pres, LPDISPATCH Wn);
void SlideShowBegin(LPDISPATCH Wn);
void SlideShowNextBuild( LPDISPATCH Wn);
void SlideShowNextSlide( LPDISPATCH Wn);
void SlideShowEnd( LPDISPATCH Pres);
void PresentationPrint(LPDISPATCH Pres);
void SlideSelectionChanged(LPDISPATCH SldRange);
void ColorSchemeChanged(LPDISPATCH SldRange);
void PresentationBeforeSave(LPDISPATCH Pres, VARIANT_BOOL * Cancel);
void SlideShowNextClick(LPDISPATCH Wn, LPDISPATCH nEffect);
void PresentationPrint(LPDISPATCH Pres);
These are the PowerPoint event handlers.
NOTE: The following 4 event handlers are not available in PowerPoint 2000, and are not called if the client has PowerPoint 2000:
void SlideSelectionChanged(LPDISPATCH SldRange);
void ColorSchemeChanged(LPDISPATCH SldRange);
void PresentationBeforeSave(LPDISPATCH Pres, VARIANT_BOOL * Cancel);
void SlideShowNextClick(LPDISPATCH Wn, LPDISPATCH nEffect);
Replace the entire contents of Myppteventshandler.cpp with the following:
// MyPPTEventsHandler.cpp : implementation file.
//
#include "stdafx.h"
#include "PPTEventsDemo.h"
#include "MyPPTEventsHandler.h"
// CMyPPTEventsHandler.
IMPLEMENT_DYNAMIC(CMyPPTEventsHandler, CCmdTarget)
CMyPPTEventsHandler::CMyPPTEventsHandler()
{
EnableAutomation();
}
CMyPPTEventsHandler::~CMyPPTEventsHandler()
{
}
void CMyPPTEventsHandler::OnFinalRelease()
{
// When the last reference for an Automation object is released,
// OnFinalRelease is called. The base class automatically
// deletes the object. Add additional cleanup required for your
// object before you call the base class.
CCmdTarget::OnFinalRelease();
}
BEGIN_MESSAGE_MAP(CMyPPTEventsHandler, CCmdTarget)
END_MESSAGE_MAP()
BEGIN_DISPATCH_MAP(CMyPPTEventsHandler, CCmdTarget)
DISP_FUNCTION_ID(CMyPPTEventsHandler,"WindowSelectionChange",2001,WindowSelectionChange,VT_EMPTY, VTS_DISPATCH)
DISP_FUNCTION_ID(CMyPPTEventsHandler , "WindowBeforeRightClick", 2002 ,WindowBeforeRightClick, VT_EMPTY , VTS_DISPATCH VTS_BOOL)
DISP_FUNCTION_ID(CMyPPTEventsHandler , "WindowBeforeDoubleClick", 2003 ,WindowBeforeDoubleClick, VT_EMPTY, VTS_DISPATCH VTS_BOOL)
DISP_FUNCTION_ID(CMyPPTEventsHandler,"PresentationClose",2004,PresentationClose,VT_EMPTY, VTS_DISPATCH)
DISP_FUNCTION_ID(CMyPPTEventsHandler,"PresentationSave",2005,PresentationSave,VT_EMPTY, VTS_DISPATCH)
DISP_FUNCTION_ID(CMyPPTEventsHandler,"PresentationOpen",2006,PresentationOpen,VT_EMPTY, VTS_DISPATCH)
DISP_FUNCTION_ID(CMyPPTEventsHandler,"NewPresentation",2007,NewPresentation,VT_EMPTY, VTS_DISPATCH)
DISP_FUNCTION_ID(CMyPPTEventsHandler,"PresentationNewSlide",2008,PresentationNewSlide,VT_EMPTY, VTS_DISPATCH)
DISP_FUNCTION_ID(CMyPPTEventsHandler,"WindowActivate",2009,WindowActivate,VT_EMPTY, VTS_DISPATCH VTS_DISPATCH)
DISP_FUNCTION_ID(CMyPPTEventsHandler,"WindowDeactivate",2010,WindowDeactivate,VT_EMPTY, VTS_DISPATCH VTS_DISPATCH)
DISP_FUNCTION_ID(CMyPPTEventsHandler,"SlideShowBegin",2011,SlideShowBegin,VT_EMPTY, VTS_DISPATCH )
DISP_FUNCTION_ID(CMyPPTEventsHandler,"SlideShowNextBuild",2012,SlideShowNextBuild,VT_EMPTY, VTS_DISPATCH )
DISP_FUNCTION_ID(CMyPPTEventsHandler,"SlideShowNextSlide",2013,SlideShowNextSlide,VT_EMPTY, VTS_DISPATCH )
DISP_FUNCTION_ID(CMyPPTEventsHandler,"SlideShowEnd",2014,SlideShowEnd,VT_EMPTY, VTS_DISPATCH )
DISP_FUNCTION_ID(CMyPPTEventsHandler,"PresentationPrint",2015,PresentationPrint,VT_EMPTY, VTS_DISPATCH )
DISP_FUNCTION_ID(CMyPPTEventsHandler,"SlideSelectionChanged",2016,SlideSelectionChanged,VT_EMPTY, VTS_DISPATCH )
DISP_FUNCTION_ID(CMyPPTEventsHandler,"ColorSchemeChanged",2017,ColorSchemeChanged,VT_EMPTY, VTS_DISPATCH )
DISP_FUNCTION_ID(CMyPPTEventsHandler,"PresentationBeforeSave",2018,PresentationBeforeSave,VT_EMPTY, VTS_DISPATCH VTS_BOOL)
DISP_FUNCTION_ID(CMyPPTEventsHandler,"SlideShowNextClick",2019,SlideShowNextClick,VT_EMPTY, VTS_DISPATCH VTS_DISPATCH )
END_DISPATCH_MAP()
//The GUUID is different from the one originally generated by Class Wizard. This GUUID is the same as the one for the EApplication outgoing event interface.
static const IID IID_IMyPPTEventsHandler =
{0x914934C2,0x5A91,0x11CF, {0x87,0x00,0x00,0xAA,0x00,0x60,0x26,0x3b}};
BEGIN_INTERFACE_MAP(CMyPPTEventsHandler, CCmdTarget)
INTERFACE_PART(CMyPPTEventsHandler, IID_IMyPPTEventsHandler, Dispatch)
END_INTERFACE_MAP()
// CMyPPTEventsHandler message handlers.
void CMyPPTEventsHandler::WindowSelectionChange(LPDISPATCH Pres)
{
m_pListBox->AddString("WindowSelectionChange");
return ;
}
void CMyPPTEventsHandler::WindowBeforeRightClick(LPDISPATCH Pres, VARIANT_BOOL* Cancel)
{
m_pListBox->AddString("WindowBeforeRightClick");
return ;
}
void CMyPPTEventsHandler::WindowBeforeDoubleClick(LPDISPATCH Pres, VARIANT_BOOL* Cancel)
{
m_pListBox->AddString("WindowBeforeDoubleClick");
return;
}
void CMyPPTEventsHandler::PresentationClose ( LPDISPATCH Pres)
{
m_pListBox->AddString("PresentationClose");
return ;
}
void CMyPPTEventsHandler::PresentationSave( LPDISPATCH Pres)
{
m_pListBox->AddString("PresentationSave");
return ;
}
void CMyPPTEventsHandler::PresentationOpen( LPDISPATCH Pres)
{
m_pListBox->AddString("PresentationOpen");
return ;
}
void CMyPPTEventsHandler::NewPresentation( LPDISPATCH Pres)
{
m_pListBox->AddString("NewPresentation");
return ;
}
void CMyPPTEventsHandler::PresentationNewSlide( LPDISPATCH Pres)
{
m_pListBox->AddString("PresentationNewSlide");
return ;
}
void CMyPPTEventsHandler::WindowActivate( LPDISPATCH Pres,LPDISPATCH Wn)
{
m_pListBox->AddString("WindowActivate");
return ;
}
void CMyPPTEventsHandler::WindowDeactivate(LPDISPATCH Pres, LPDISPATCH Wn)
{
m_pListBox->AddString("WindowDeactivate");
return ;
}
void CMyPPTEventsHandler::SlideShowBegin(LPDISPATCH Wn)
{
m_pListBox->AddString("SlideShowBegin");
return;
}
void CMyPPTEventsHandler::SlideShowNextBuild( LPDISPATCH Wn)
{
m_pListBox->AddString("SlideShowNextBuild");
return ;
}
void CMyPPTEventsHandler::SlideShowNextSlide( LPDISPATCH Wn)
{
m_pListBox->AddString("SlideShowNextSlide");
return ;
}
void CMyPPTEventsHandler::SlideShowEnd( LPDISPATCH Pres)
{
m_pListBox->AddString("SlideShowEnd");
return;
}
void CMyPPTEventsHandler::PresentationPrint(LPDISPATCH Pres)
{
m_pListBox->AddString("PresentationPrint");
return;
}
//The following events are not available for PowerPoint 2000.
void CMyPPTEventsHandler::SlideSelectionChanged(LPDISPATCH SldRange)
{
m_pListBox->AddString("SlideSelectionChanged");
return ;
}
void CMyPPTEventsHandler::ColorSchemeChanged(LPDISPATCH SldRange)
{
m_pListBox->AddString("ColorSchemeChanged");
return ;
}
void CMyPPTEventsHandler::PresentationBeforeSave(LPDISPATCH Pres, VARIANT_BOOL * Cancel)
{
m_pListBox->AddString("PresentationBeforeSave");
return;
}
void CMyPPTEventsHandler::SlideShowNextClick(LPDISPATCH Wn, LPDISPATCH nEffect)
{
m_pListBox->AddString("SlideShowNextClick");
return ;
}
uj5u.com熱心網友回復:
Note that the value of the IID_IMyPPTEventsHandler static constant is changed from the value that the Class Wizard originally generated. The value is changed to the following:static const IID IID_IMyPPTEventsHandler =
{0x914934C2,0x5A91,0x11CF, {0x87,0x00,0x00,0xAA,0x00,0x60,0x26,0x3b}};
This is the GUID for the EApplication outgoing event interface for the PowerPoint Application class. Also, note that the dispatch map for this class maps the DISPIDs of the events to the event handler methods.
In the Ppteventsdemo.cpp file, add the following #include statement
#include "CApplication.h"
before the following:
#include "PPTEventsDemoDlg.h"
Add the following lines of code at the top of the InitInstance method of the Ppteventsdemoapp.cpp file:
if(!AfxOleInit())
{
AfxMessageBox("Unable to initialize COM");
return FALSE;
}
back to the top
Test the Application
Press F5 to build and run the program. The dialog box appears.
Click Launch PowerPoint. PowerPoint starts and becomes visible.
Click Establish Connection Point and Register Sink to set up the event sinks.
Create a new presentation in PowerPoint. The WindowActivate, NewPresentation, PresentationNewSlide, SlideSelectionChange, and WindowSelectionChange events fire.
Start the slide show and play it through the end. The SlideShowBegin, SlideShowNextSlide, and SlideShowEnd events fire.
Save the presentation. The PresentationBeforeSave and PresentationSave events fire.
Close the presentation. The PresentationClose event fires, and the events that were triggered by PowerPoint 2002 and handled by the program appear in the list box.
NOTE: These are the events that PowerPoint 2002 fires. You may not see some of these events in PowerPoint 2000.
Click UnRegister Sink and Do Clean Up to disconnect the event sinks.
Close the dialog box.
back to the top
References
For additional information, click the article numbers below to view the articles in the Microsoft Knowledge Base:
Q254009 INFO: PowerPoint 2000 Event Demonstration Available for Download
Q308336 HOWTO: Use Automation to Create and Show a PowerPoint Presentation with Visual C++ .NET and MFC
For more information on Office Automation, see the following Microsoft Office Development support site:
Office Development Support Center
http://support.microsoft.com/support/officedev
back to the top
Additional query words: Power Point NET events C++ MFC connection powerpoint
Keywords: kbAutomation _IK11561 kbGrpDSO kbHOWTOmaster
Issue Type: kbhowto
Technology: kbVCsearch kbAudDeveloper kbPowerPtSearch kbPowerPt2000 kbPowerPt2002 kbZNotKeyword2 kbPowerPt2000Search kbPowerPt2002Search kbVCNET
uj5u.com熱心網友回復:
MSDN上的東西太爛了,只有VB的,要用VC獲取office的事件,只能使用上面的方式,VB的例子完全不能用。uj5u.com熱心網友回復:
很有用,學習了uj5u.com熱心網友回復:


IID號和事件的CLSID號可以用VC帶的ole/com object viewer察看。
uj5u.com熱心網友回復:
其實說白了就是要自己定義一個事件處理類,然后掛接到事件連接點上,事件連接點上需要監聽EApplication類的CLSID(uuid(914934C2-5A91-11CF-8700-00AA0060263B),)對應的事件。就這么簡單。uj5u.com熱心網友回復:
https://support.microsoft.com/zh-cn/kb/309294或者參考這個看看,這是針對WORD的,其實都差不多。
uj5u.com熱心網友回復:
@liuquancai1,非常感謝你的回答,解決了小弟的問題,我找PPT的guid一直沒找到正確的,最后直接使用你代碼中的,居然就找到連接點了,非常感謝。牛b轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/109600.html
