PIPEIT.CPP
上传用户:bangxh
上传日期:2007-01-31
资源大小:42235k
文件大小:2k
源码类别:

Windows编程

开发平台:

Visual C++

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