FilterContent.cpp
上传用户:szled88
上传日期:2015-04-09
资源大小:43957k
文件大小:5k
源码类别:

对话框与窗口

开发平台:

Visual C++

  1. // FilterContent.cpp : implementation file
  2. //
  3. #include "stdafx.h"
  4. #include "styler.h"
  5. #include "FilterContent.h"
  6. #include "FilterDialog.h"
  7. #ifdef _DEBUG
  8. #define new DEBUG_NEW
  9. #undef THIS_FILE
  10. static char THIS_FILE[] = __FILE__;
  11. #endif
  12. /////////////////////////////////////////////////////////////////////////////
  13. // CFilterContent
  14. IMPLEMENT_DYNCREATE(CFilterContent, CCmdTarget)
  15. CFilterContent::CFilterContent()
  16. {
  17. EnableAutomation();
  18. }
  19. CFilterContent::~CFilterContent()
  20. {
  21. }
  22. BEGIN_INTERFACE_MAP(CFilterContent, CCmdTarget)
  23. INTERFACE_PART(CFilterContent, IID_IClassFactory, ClassFactory)
  24. INTERFACE_PART(CFilterContent, IID_IInternetProtocol, InternetProtocol)
  25. INTERFACE_PART(CFilterContent, IID_IInternetProtocolRoot, InternetProtocol)
  26. END_INTERFACE_MAP()
  27. STDMETHODIMP_(ULONG) CFilterContent::XClassFactory::AddRef()
  28. {
  29. METHOD_PROLOGUE(CFilterContent, ClassFactory)
  30. return pThis->ExternalAddRef();
  31. }
  32. STDMETHODIMP_(ULONG)  CFilterContent::XClassFactory::Release()
  33. {                            
  34. METHOD_PROLOGUE(CFilterContent, ClassFactory)
  35. return pThis->ExternalRelease();
  36. }
  37. STDMETHODIMP CFilterContent::XClassFactory::QueryInterface (REFIID riid, void **ppvObj)
  38. {
  39. METHOD_PROLOGUE(CFilterContent, ClassFactory)
  40. HRESULT hr = (HRESULT)pThis->ExternalQueryInterface(&riid, ppvObj);
  41. return hr;
  42. }
  43. STDMETHODIMP CFilterContent::XClassFactory::CreateInstance( 
  44.             /* [unique][in] */ IUnknown __RPC_FAR* /*pUnkOuter*/,
  45.             /* [in] */ REFIID riid,
  46.             /* [iid_is][out] */ void __RPC_FAR *__RPC_FAR *ppvObject)
  47. {
  48. METHOD_PROLOGUE(CFilterContent, ClassFactory)
  49. pThis->InternalQueryInterface(&riid, ppvObject);
  50. pThis->ExternalAddRef();
  51. return S_OK;
  52. }
  53.         
  54. STDMETHODIMP CFilterContent::XClassFactory::LockServer (/* [in] */ BOOL /*fLock*/)
  55. {
  56. return E_NOTIMPL;
  57. }
  58. /////////////////////////////////////////
  59. STDMETHODIMP_(ULONG)  CFilterContent::XInternetProtocol::AddRef()
  60. {
  61. METHOD_PROLOGUE(CFilterContent, InternetProtocol)
  62. return pThis->ExternalAddRef();
  63. }
  64. STDMETHODIMP_(ULONG) CFilterContent::XInternetProtocol::Release()
  65. {                            
  66. METHOD_PROLOGUE(CFilterContent, InternetProtocol)
  67. return pThis->ExternalRelease();
  68. }
  69. STDMETHODIMP CFilterContent::XInternetProtocol::QueryInterface (REFIID riid, void **ppvObj)
  70. {
  71. METHOD_PROLOGUE(CFilterContent, InternetProtocol)
  72. HRESULT hr = (HRESULT)pThis->ExternalQueryInterface(&riid, ppvObj);
  73. return hr;
  74. }
  75. STDMETHODIMP CFilterContent::XInternetProtocol::Start(
  76.         LPCWSTR szUrl,
  77.         IInternetProtocolSink *pIProtSink,
  78.         IInternetBindInfo* /*pIBindInfo*/,
  79.         DWORD /*grfSTI*/,
  80.         HANDLE_PTR /*dwReserved*/)
  81. {
  82. METHOD_PROLOGUE(CFilterContent, InternetProtocol)
  83. if(pIProtSink!=NULL)
  84. {
  85. CString strUrl(szUrl);
  86. for (int i = 0; i < CFilterDialog::m_lstFilter.GetSize(); i++)
  87. {
  88. if (strUrl.Find(CFilterDialog::m_lstFilter[i]) != -1)
  89. {
  90. pIProtSink->AddRef();
  91. pIProtSink->ReportData(BSCF_FIRSTDATANOTIFICATION || BSCF_LASTDATANOTIFICATION || BSCF_DATAFULLYAVAILABLE, 42, 42);
  92. pIProtSink->ReportResult(S_OK, 0, 0);
  93. pIProtSink->Release();
  94. pThis->InternalRelease();
  95. return S_OK;
  96. }
  97. }
  98. }
  99. return INET_E_USE_DEFAULT_PROTOCOLHANDLER;
  100. }
  101. STDMETHODIMP CFilterContent::XInternetProtocol::Continue(PROTOCOLDATA * /*pStateInfo*/)
  102. {
  103. return S_OK;
  104. }
  105. STDMETHODIMP CFilterContent::XInternetProtocol::Abort(HRESULT /*hrReason*/,DWORD /*dwOptions*/)
  106. {
  107. return E_NOTIMPL;
  108. }
  109. STDMETHODIMP CFilterContent::XInternetProtocol::Terminate(DWORD /*dwOptions*/)
  110. {
  111. return  S_OK;
  112. }
  113. STDMETHODIMP CFilterContent::XInternetProtocol::Suspend()
  114. {
  115. return E_NOTIMPL;
  116. }
  117. STDMETHODIMP CFilterContent::XInternetProtocol::Resume()
  118. {
  119. return E_NOTIMPL;
  120. }
  121. STDMETHODIMP CFilterContent::XInternetProtocol::Read(void *pv, ULONG cb, ULONG *pcbRead)
  122. {
  123. BYTE bytePlaceHold[]= {0x47, 0x49, 0x46, 0x38, 0x39, 0x61, 0x01, 0x00,
  124. 0x01, 0x00, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00,
  125. 0xFF, 0xFF, 0xFF, 0x21, 0xF9, 0x04, 0x01, 0x00,
  126. 0x00, 0x00, 0x00, 0x2C, 0x00, 0x00, 0x00, 0x00,
  127. 0x01, 0x00, 0x01, 0x00, 0x00, 0x02, 0x01, 0x44,
  128. 0x00, 0x3B};
  129. try
  130. {
  131. if(cb >= 42 && pv != NULL)
  132. {
  133. MEMCPY_S(pv, bytePlaceHold, 42);
  134. *pcbRead = 42;
  135. }
  136. else
  137. *pcbRead = 0;
  138. }
  139. catch(...)
  140. {
  141. }
  142. return S_FALSE;
  143. }
  144. STDMETHODIMP CFilterContent::XInternetProtocol::Seek(
  145.         LARGE_INTEGER /*dlibMove*/,
  146.         DWORD /*dwOrigin*/,
  147.         ULARGE_INTEGER * /*plibNewPosition*/)
  148. {
  149. return E_NOTIMPL;
  150. }
  151. STDMETHODIMP CFilterContent::XInternetProtocol::LockRequest(DWORD /*dwOptions*/)
  152. {
  153. return S_OK;
  154. }
  155. STDMETHODIMP CFilterContent::XInternetProtocol::UnlockRequest()
  156. {
  157. return S_OK;
  158. }