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

  1. // PipeIt.cpp : Implementation of CPipeIt
  2. #include "stdafx.h"
  3. #include "pipe.h"
  4. #include "PipeIt.h"
  5. #include "resource.h"
  6. #include "dlgFilter.h"
  7.  
  8. /////////////////////////////////////////////////////////////////////////////
  9. // CPipeIt
  10.  
  11. HRESULT CPipeIt::OnConnection(IApplication* pApp, VARIANT_BOOL bFirstTime, long dwAddInID, VARIANT_BOOL* bOnConnection)
  12. {
  13.     HRESULT hr = S_OK;
  14.     CString strCmdFilter;
  15.     CString strCmdNameFilter;
  16.  
  17.     AFX_MANAGE_STATE(AfxGetStaticModuleState());
  18.  
  19.     m_spApplication = pApp;
  20.     m_dwAddInID = dwAddInID;
  21.  
  22.     hr = pApp->SetAddInInfo((long)_Module.GetModuleInstance(), 
  23.         static_cast<IPipeIt*>(this), IDB_TOOLBAR_MEDIUM_PIPEIT, IDB_TOOLBAR_LARGE_PIPEIT, dwAddInID);
  24.     VARIANT_BOOL bRet;
  25.     if (SUCCEEDED(hr))
  26.     {
  27.         strCmdFilter.LoadString(IDS_CMD_FILTER);
  28.         strCmdNameFilter.LoadString(IDS_CMDNAME_FILTER);
  29.         strCmdNameFilter += _T('\n');
  30.         strCmdNameFilter += strCmdFilter;
  31.         hr = pApp->AddCommand(CComBSTR(strCmdNameFilter),CComBSTR(_T("Filter")), 0, dwAddInID, &bRet);
  32.     }
  33.  
  34.     // Add toolbar buttons only if this is the first time the add-in
  35.     // is being loaded.  Toolbar buttons are automatically remembered
  36.     // by Developer Studio from session to session, so we should only
  37.     // add the toolbar buttons once.
  38.     if (bFirstTime)
  39.     {
  40.         if (SUCCEEDED(hr))
  41.         {
  42.             strCmdNameFilter.LoadString(IDS_CMDNAME_FILTER);
  43.             hr = pApp->AddCommandBarButton(dsGlyph, CComBSTR(strCmdNameFilter), dwAddInID);
  44.         }
  45.     }
  46.  
  47.     *bOnConnection = SUCCEEDED(hr) ? VARIANT_TRUE :VARIANT_FALSE;
  48.     return hr;
  49. }
  50.  
  51. HRESULT CPipeIt::OnDisconnection(VARIANT_BOOL bLastTime)
  52. {
  53.     return S_OK;
  54. }
  55.  
  56. HRESULT CPipeIt::Filter()
  57. {
  58.     AFX_MANAGE_STATE(AfxGetStaticModuleState());
  59.     // Replace this with the actual code to execute this command
  60.     // Use m_spApplication to access the Developer Studio Application object
  61.     // TODO: WHAT ABOUT BEGINMODELESS??
  62.     CDlgFilter dlgFilter;
  63.     CComPtr<IDispatch> pDispDoc;
  64.  
  65.     m_spApplication->get_ActiveDocument(&pDispDoc);
  66.     if (pDispDoc) // have a document open. Can reasonably do this...
  67.     {
  68.         dlgFilter.SetApp(m_spApplication);
  69.         dlgFilter.DoModal();
  70.     }
  71.  
  72.     return S_OK;
  73. }
  74.  
  75.