Capturing the event
-
Hey everybody, I put a post out about my word automation not working. I haven't been able to get past the Link Error so I tried something different. Now, I have this function which puts a button (with a bitmap) onto MS Word. As you can see, I create it dynamically. Now, what I was wondering, how can I capture the event when this button is pressed? I am trying to do an Advise but it doesn't seem to be doing what I want it to do??? I have pasted the header file for the event sink and the actual function which does the Advise. Any ideas? Anything come to mind? Do you think I am making this too complicated and have a better way to go at it? Just let me know, I am knew to COM/ATL/OLE development... ====================================================================== header file wordeventsink.h: #if !defined(AFX_WORDEVENTSINK_H__F45A8330_C1E9_11D2_A0C4_0080C7F3B56B__INCLUDED_) #define AFX_WORDEVENTSINK_H__F45A8330_C1E9_11D2_A0C4_0080C7F3B56B__INCLUDED_ /*----------------------------------------------------------------------------*/ #if _MSC_VER > 1000 #pragma once #endif // _MSC_VER > 1000 /*----------------------------------------------------------------------------*/ //#pragma warning (disable:4146) //#import "mso97.dll" //#pragma warning (default:4146) //#import "vbeext1.olb" //#import "msword8.olb" rename("ExitWindows", "WordExitWindows") #pragma warning (disable:4146) #import "C:\Program Files\Common Files\Microsoft Shared\Office10\mso.dll" #pragma warning (default:4146) #import "C:\Program Files\Common Files\Microsoft Shared\VBA\VBA6\vbe6ext.olb" #import "C:\Program Files\Microsoft Office\Office10\MSWORD.olb" rename("ExitWindows", "WordExitWindows") #include "ConnectionAdvisor.h" class CTestDlg; /*----------------------------------------------------------------------------*/ const IID IID_IWordAppEventSink = __uuidof(Word::ApplicationEvents); const IID IID_IWordDocEventSink = __uuidof(Word::DocumentEvents); const IID IID_IPSISaveExit = __uuidof(Office::_CommandBarButtonEvents); /*----------------------------------------------------------------------------*/ class CWordEventSink : public CCmdTarget { DECLARE_DYNCREATE(CWordEventSink) public: CWordEventSink(); virtual ~CWordEventSink(); BOOL Advise(IUnknown* pSource, REFIID iid); BOOL Unadvise(REFIID iid); void SetLauncher(CTestDlg* pWordLauncher); // ClassWizard generated virtual function overrides //{{AFX_VIRTUAL(CWordEventSink) public: virtual void OnFinalRelease(); //}}AFX_V
-
Hey everybody, I put a post out about my word automation not working. I haven't been able to get past the Link Error so I tried something different. Now, I have this function which puts a button (with a bitmap) onto MS Word. As you can see, I create it dynamically. Now, what I was wondering, how can I capture the event when this button is pressed? I am trying to do an Advise but it doesn't seem to be doing what I want it to do??? I have pasted the header file for the event sink and the actual function which does the Advise. Any ideas? Anything come to mind? Do you think I am making this too complicated and have a better way to go at it? Just let me know, I am knew to COM/ATL/OLE development... ====================================================================== header file wordeventsink.h: #if !defined(AFX_WORDEVENTSINK_H__F45A8330_C1E9_11D2_A0C4_0080C7F3B56B__INCLUDED_) #define AFX_WORDEVENTSINK_H__F45A8330_C1E9_11D2_A0C4_0080C7F3B56B__INCLUDED_ /*----------------------------------------------------------------------------*/ #if _MSC_VER > 1000 #pragma once #endif // _MSC_VER > 1000 /*----------------------------------------------------------------------------*/ //#pragma warning (disable:4146) //#import "mso97.dll" //#pragma warning (default:4146) //#import "vbeext1.olb" //#import "msword8.olb" rename("ExitWindows", "WordExitWindows") #pragma warning (disable:4146) #import "C:\Program Files\Common Files\Microsoft Shared\Office10\mso.dll" #pragma warning (default:4146) #import "C:\Program Files\Common Files\Microsoft Shared\VBA\VBA6\vbe6ext.olb" #import "C:\Program Files\Microsoft Office\Office10\MSWORD.olb" rename("ExitWindows", "WordExitWindows") #include "ConnectionAdvisor.h" class CTestDlg; /*----------------------------------------------------------------------------*/ const IID IID_IWordAppEventSink = __uuidof(Word::ApplicationEvents); const IID IID_IWordDocEventSink = __uuidof(Word::DocumentEvents); const IID IID_IPSISaveExit = __uuidof(Office::_CommandBarButtonEvents); /*----------------------------------------------------------------------------*/ class CWordEventSink : public CCmdTarget { DECLARE_DYNCREATE(CWordEventSink) public: CWordEventSink(); virtual ~CWordEventSink(); BOOL Advise(IUnknown* pSource, REFIID iid); BOOL Unadvise(REFIID iid); void SetLauncher(CTestDlg* pWordLauncher); // ClassWizard generated virtual function overrides //{{AFX_VIRTUAL(CWordEventSink) public: virtual void OnFinalRelease(); //}}AFX_V
You have to advise the button events (_CommandBarButtonEvents) from m_pButton and add event handlers to the sink map. Hth, Ramu