home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Windows Gam…ming Gurus (2nd Edition) / Disc2.iso / common / msdev98 / template / atl / addin.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1998-06-16  |  4.6 KB  |  186 lines

  1. [!if=(FileExists, "FALSE")]
  2. // [!CPPName] : Implementation of [!ClassName]
  3.  
  4. #include "stdafx.h"
  5. #include "[!ProjectName].h"
  6. #include "[!HeaderName]"
  7. [!else]
  8. [!AddIncludeFile(TargetFile, "stdafx.h")]
  9. [!AddStringToSymbol(ProjectName.h, ProjectName, ".h")]
  10. [!AddIncludeFile(TargetFile, ProjectName.h)]
  11. [!AddIncludeFile(TargetFile, HeaderName)]
  12. [!endif]
  13. [!crlf]
  14.  
  15. /////////////////////////////////////////////////////////////////////////////
  16. // [!ClassName]
  17. [!crlf]
  18.  
  19. HRESULT [!ClassName]::OnConnection(IApplication* pApp, VARIANT_BOOL bFirstTime, long dwAddInID, VARIANT_BOOL* bOnConnection)
  20. {
  21.     HRESULT hr = S_OK;
  22.     m_spApplication = pApp;
  23.     m_dwAddInID = dwAddInID;
  24.  
  25. [!if=(ApplicationEvents, "TRUE")]
  26. [!crlf]
  27.     // Connect up to application event sink
  28.     AtlAdvise(pApp, GetUnknown(), IID_IApplicationEvents, &m_dwAppEvents);
  29. [!endif]
  30. [!if=(DebuggerEvents, "TRUE")]
  31. [!crlf]
  32.     // Connect up to debugger event sink
  33.     CComPtr<IDispatch> pDebugger;
  34.     hr = m_spApplication->get_Debugger(&pDebugger);
  35.     if (SUCCEEDED(hr))
  36.         AtlAdvise(pDebugger, GetUnknown(), IID_IDebuggerEvents, &m_dwDbgEvents);
  37. [!endif]
  38.  
  39. [!crlf]
  40. [!if=(Toolbar, "TRUE")]
  41.     hr = pApp->SetAddInInfo((long)_Module.GetModuleInstance(), 
  42.         static_cast<[!InterfaceName]*>(this), IDB_TOOLBAR_MEDIUM_[!UpperShortName], IDB_TOOLBAR_LARGE_[!UpperShortName], dwAddInID);
  43. [!else]
  44.     hr = pApp->SetAddInInfo((long)_Module.GetModuleInstance(), 
  45.         static_cast<[!InterfaceName]*>(this), -1, -1, dwAddInID);
  46. [!crlf]
  47. [!endif]
  48.  
  49. [!if=(Toolbar, "TRUE")]
  50. [!if!=(CommandName, "")]
  51.     LPCTSTR szCommand = _T("[!CommandName]");
  52. [!else]
  53.     LPCTSTR szCommand = _T("SampleCommand");
  54. [!endif]
  55.     VARIANT_BOOL bRet;
  56.     if (SUCCEEDED(hr))
  57.     {
  58.         hr = pApp->AddCommand(CComBSTR([!if!=(CommandName, "")]_T("[!CommandName][!else]_T("SampleCommand[!endif]\n[!if!=(ToolbarButton, "")][!ToolbarButton][!else]Sample toolbar button text[!endif]\n[!if!=(StatusBar, "")][!StatusBar][!else]Sample status bar text[!endif]\n[!if!=(ToolTips, "")][!ToolTips][!else]Sample tool tips[!endif]")),CComBSTR([!if!=(CommandName, "")]_T("[!MethodName]")[!else]_T("Sample Method")[!endif]), 0, dwAddInID, &bRet);
  59.     }
  60. [!crlf]
  61.     // Add toolbar buttons only if this is the first time the add-in
  62.     // is being loaded.  Toolbar buttons are automatically remembered
  63.     // by Developer Studio from session to session, so we should only
  64.     // add the toolbar buttons once.
  65.     if (bFirstTime)
  66.     {
  67.         if (SUCCEEDED(hr))
  68.         {
  69.             hr = pApp->AddCommandBarButton(dsGlyph, CComBSTR([!if!=(CommandName, "")]_T("[!CommandName]")[!else]_T("SampleCommand")[!endif]), dwAddInID);
  70.         }
  71.     }
  72. [!crlf]
  73. [!endif]
  74.  
  75.     *bOnConnection = SUCCEEDED(hr) ? VARIANT_TRUE :VARIANT_FALSE;
  76.     return hr;
  77. }
  78. [!crlf]
  79.  
  80.  
  81. HRESULT [!ClassName]::OnDisconnection(VARIANT_BOOL bLastTime)
  82. {
  83. [!if=(ApplicationEvents, "TRUE")]
  84.     AtlUnadvise(m_spApplication, IID_IApplicationEvents, m_dwAppEvents);
  85. [!endif]
  86. [!if=(DebuggerEvents, "TRUE")]
  87.     AtlUnadvise(m_spApplication, IID_IDebuggerEvents, m_dwDbgEvents);
  88. [!endif]
  89.     return S_OK;
  90. }
  91. [!crlf]
  92.  
  93.  
  94. [!if=(ApplicationEvents, "TRUE")]
  95. /////////////////////////////////////////////////////////////////////////////
  96. // Application events
  97.  
  98. HRESULT [!ClassName]::BeforeBuildStart()
  99. {
  100.     return S_OK;
  101. }
  102.  
  103. HRESULT [!ClassName]::BuildFinish(long nNumErrors, long nNumWarnings)
  104. {
  105.     return S_OK;
  106. }
  107.  
  108. HRESULT [!ClassName]::BeforeApplicationShutDown()
  109. {
  110.     return S_OK;
  111. }
  112.  
  113. HRESULT [!ClassName]::DocumentOpen(IDispatch* theDocument)
  114. {
  115.     return S_OK;
  116. }
  117.  
  118. HRESULT [!ClassName]::BeforeDocumentClose(IDispatch* theDocument)
  119. {
  120.     return S_OK;
  121. }
  122.  
  123. HRESULT [!ClassName]::DocumentSave(IDispatch* theDocument)
  124. {
  125.     return S_OK;
  126. }
  127.  
  128. HRESULT [!ClassName]::NewDocument(IDispatch* theDocument)
  129. {
  130.     return S_OK;
  131. }
  132.  
  133. HRESULT [!ClassName]::WindowActivate(IDispatch* theWindow)
  134. {
  135.     return S_OK;
  136. }
  137.  
  138. HRESULT [!ClassName]::WindowDeactivate(IDispatch* theWindow)
  139. {
  140.     return S_OK;
  141. }
  142.  
  143. HRESULT [!ClassName]::WorkspaceOpen()
  144. {
  145.     return S_OK;
  146. }
  147.  
  148. HRESULT [!ClassName]::WorkspaceClose()
  149. {
  150.     return S_OK;
  151. }
  152.  
  153. HRESULT [!ClassName]::NewWorkspace()
  154. {
  155.     return S_OK;
  156. }
  157. [!crlf]
  158. [!endif]
  159.  
  160.  
  161. [!if=(DebuggerEvents, "TRUE")]
  162. /////////////////////////////////////////////////////////////////////////////
  163. // Debugger event
  164.  
  165. HRESULT [!ClassName]::BreakpointHit(IDispatch* pBreakpoint)
  166. {
  167.     return S_OK;
  168. }
  169. [!crlf]
  170. [!endif]
  171.  
  172. [!if=(Toolbar, "TRUE")]
  173. [!if!=(MethodName, "")]
  174. HRESULT [!ClassName]::[!MethodName]()
  175. [!else]
  176. HRESULT [!ClassName]::SampleMethod()
  177. [!endif]
  178. {
  179.     // Replace this with the actual code to execute this command
  180.     // Use m_spApplication to access the Developer Studio Application object
  181.     return S_OK;
  182. }
  183. [!crlf]
  184. [!endif]
  185.  
  186.