home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Windows Gam…ming Gurus (2nd Edition) / Disc2.iso / msdn_vcb / samples / vc98 / addins / bldrec / commands.h < prev    next >
C/C++ Source or Header  |  1998-04-03  |  4KB  |  108 lines

  1. // Commands.h : header file
  2. //
  3.  
  4. #if !defined(AFX_COMMANDS_H__36FDE876_EA61_11D0_B595_00A0C91BC942__INCLUDED_)
  5. #define AFX_COMMANDS_H__36FDE876_EA61_11D0_B595_00A0C91BC942__INCLUDED_
  6.  
  7. #include "bldrecTypes.h"
  8.  
  9. class CCommands : 
  10.     public CComDualImpl<ICommands, &IID_ICommands, &LIBID_Bldrec>, 
  11.     public CComObjectRoot,
  12.     public CComCoClass<CCommands, &CLSID_Commands>
  13. {
  14. protected:
  15.     IApplication* m_pApplication;
  16.  
  17. public:
  18.     CCommands();
  19.     ~CCommands();
  20.     void SetApplicationObject(IApplication* m_pApplication);
  21.     IApplication* GetApplicationObject() { return m_pApplication; }
  22.     void UnadviseFromEvents();
  23.  
  24.     BEGIN_COM_MAP(CCommands)
  25.         COM_INTERFACE_ENTRY(IDispatch)
  26.         COM_INTERFACE_ENTRY(ICommands)
  27.     END_COM_MAP()
  28.     DECLARE_NOT_AGGREGATABLE(CCommands)
  29.  
  30. protected:
  31.     CString m_strFile;
  32.     // This class template is used as the base class for the Application
  33.     //  event handler object and the Debugger event handler object,
  34.     //  which are declared below.
  35.     template <class IEvents, const IID* piidEvents, const GUID* plibid,
  36.         class XEvents, const CLSID* pClsidEvents>
  37.     class XEventHandler :
  38.         public CComDualImpl<IEvents, piidEvents, plibid>,
  39.         public CComObjectRoot,
  40.         public CComCoClass<XEvents, pClsidEvents>
  41.     {
  42.     public:
  43.         BEGIN_COM_MAP(XEvents)
  44.             COM_INTERFACE_ENTRY(IDispatch)
  45.             COM_INTERFACE_ENTRY_IID(*piidEvents, IEvents)
  46.         END_COM_MAP()
  47.         DECLARE_NOT_AGGREGATABLE(XEvents)
  48.         void Connect(IUnknown* pUnk)
  49.         { VERIFY(SUCCEEDED(AtlAdvise(pUnk, this, *piidEvents, &m_dwAdvise))); }
  50.         void Disconnect(IUnknown* pUnk)
  51.         { AtlUnadvise(pUnk, *piidEvents, m_dwAdvise); }
  52.  
  53.         CCommands* m_pCommands;
  54.  
  55.     protected:
  56.         DWORD m_dwAdvise;
  57.     };
  58.  
  59.     // This object handles events fired by the Application object
  60.     class XApplicationEvents : public XEventHandler<IApplicationEvents, 
  61.         &IID_IApplicationEvents, &LIBID_Bldrec, 
  62.         XApplicationEvents, &CLSID_ApplicationEvents>
  63.     {
  64.     public:
  65.         // IApplicationEvents methods
  66.         STDMETHOD(BeforeBuildStart)(THIS);
  67.         STDMETHOD(BuildFinish)(THIS_ long nNumErrors, long nNumWarnings);
  68.         STDMETHOD(BeforeApplicationShutDown)(THIS);
  69.         STDMETHOD(DocumentOpen)(THIS_ IDispatch * theDocument);
  70.         STDMETHOD(BeforeDocumentClose)(THIS_ IDispatch * theDocument);
  71.         STDMETHOD(DocumentSave)(THIS_ IDispatch * theDocument);
  72.         STDMETHOD(NewDocument)(THIS_ IDispatch * theDocument);
  73.         STDMETHOD(WindowActivate)(THIS_ IDispatch * theWindow);
  74.         STDMETHOD(WindowDeactivate)(THIS_ IDispatch * theWindow);
  75.         STDMETHOD(WorkspaceOpen)(THIS);
  76.         STDMETHOD(WorkspaceClose)(THIS);
  77.         STDMETHOD(NewWorkspace)(THIS);
  78.     };
  79.     typedef CComObject<XApplicationEvents> XApplicationEventsObj;
  80.     XApplicationEventsObj* m_pApplicationEventsObj;
  81.  
  82.     // This object handles events fired by the Application object
  83.     class XDebuggerEvents : public XEventHandler<IDebuggerEvents, 
  84.         &IID_IDebuggerEvents, &LIBID_Bldrec, 
  85.         XDebuggerEvents, &CLSID_DebuggerEvents>
  86.     {
  87.     public:
  88.         // IDebuggerEvents method
  89.         STDMETHOD(BreakpointHit)(THIS_ IDispatch * pBreakpoint);
  90.     };
  91.     typedef CComObject<XDebuggerEvents> XDebuggerEventsObj;
  92.     XDebuggerEventsObj* m_pDebuggerEventsObj;
  93.  
  94. public:
  95.     BOOL SaveFileName();
  96.     CTime m_theLastTime;
  97.     BOOL MarkTime(LPCSTR szItem, BOOL fStart);
  98. // ICommands methods
  99.     STDMETHOD(BldrecCommandMethod)(THIS);
  100. };
  101.  
  102. typedef CComObject<CCommands> CCommandsObj;
  103.  
  104. //{{AFX_INSERT_LOCATION}}
  105. // Microsoft Developer Studio will insert additional declarations immediately before the previous line.
  106.  
  107. #endif // !defined(AFX_COMMANDS_H__36FDE876_EA61_11D0_B595_00A0C91BC942__INCLUDED)
  108.