home *** CD-ROM | disk | FTP | other *** search
/ Supercompiler 1997 / SUPERCOMPILER97.iso / MS_VC.50 / SharedIDE / TEMPLATE / ATL / ADDIN.CPP next >
Encoding:
C/C++ Source or Header  |  1996-12-19  |  4.3 KB  |  179 lines

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