ImageProcessBHO.h
上传用户:pass2008
上传日期:2021-07-05
资源大小:3299k
文件大小:3k
源码类别:
Internet/IE编程
开发平台:
Visual C++
- // ImageProcessBHO.h : CImageProcessBHO 的声明
- #pragma once
- #include "resource.h" // 主符号
- #include "ImageProcess.h"
- #include <shlguid.h>
- #include <exdispid.h>
- #include <mshtml.h>
- #include "ImgProcUnit.h"
- #if defined(_WIN32_WCE) && !defined(_CE_DCOM) && !defined(_CE_ALLOW_SINGLE_THREADED_OBJECTS_IN_MTA)
- #error "Windows CE 平台(如不提供完全 DCOM 支持的 Windows Mobile 平台)上无法正确支持单线程 COM 对象。定义 _CE_ALLOW_SINGLE_THREADED_OBJECTS_IN_MTA 可强制 ATL 支持创建单线程 COM 对象实现并允许使用其单线程 COM 对象实现。rgs 文件中的线程模型已被设置为“Free”,原因是该模型是非 DCOM Windows CE 平台支持的唯一线程模型。"
- #endif
- // CImageProcessBHO
- class ATL_NO_VTABLE CImageProcessBHO :
- public CComObjectRootEx<CComSingleThreadModel>,
- public CComCoClass<CImageProcessBHO, &CLSID_ImageProcessBHO>,
- public IObjectWithSiteImpl<CImageProcessBHO>,
- public IDispatchImpl<IImageProcessBHO, &IID_IImageProcessBHO, &LIBID_ImageProcessLib, /*wMajor =*/ 1, /*wMinor =*/ 0>,
- public IDispEventImpl<1, CImageProcessBHO, &DIID_DWebBrowserEvents2, &LIBID_SHDocVw, 1, 1>
- {
- public:
- CImageProcessBHO()
- {
- m_bNavigatedToLocalHTML = FALSE;
- //m_bInputNewURL = FALSE;
- }
- DECLARE_REGISTRY_RESOURCEID(IDR_IMAGEPROCESSBHO)
- DECLARE_NOT_AGGREGATABLE(CImageProcessBHO)
- BEGIN_COM_MAP(CImageProcessBHO)
- COM_INTERFACE_ENTRY(IImageProcessBHO)
- COM_INTERFACE_ENTRY(IDispatch)
- COM_INTERFACE_ENTRY(IObjectWithSite)
- END_COM_MAP()
- BEGIN_SINK_MAP(CImageProcessBHO)
- SINK_ENTRY_EX(1, DIID_DWebBrowserEvents2, DISPID_DOCUMENTCOMPLETE, OnDocumentComplete)
- END_SINK_MAP()
- DECLARE_PROTECT_FINAL_CONSTRUCT()
- HRESULT FinalConstruct()
- {
- return S_OK;
- }
- void FinalRelease()
- {
- //退出前清理工作
- for (int i=0; i<imageNames.GetCount(); i++)
- {
- ::DeleteFile(imageNames.GetAt(i));
- }
- ::DeleteFile(localStockedPath);
- }
- public:
- STDMETHOD(SetSite)(IUnknown* pUnkSite);
- void STDMETHODCALLTYPE OnDocumentComplete(IDispatch* pDisp, VARIANT* pvarURL);
- private:
- CComPtr<IWebBrowser2> m_spWebBrowser;
- BOOL m_fAdvised;
- CStringArray imageOuterHTML;
- CStringArray imageLinks; //图像URL集合
- CString predomainURL; //前次域名URL
- CString domainURL; //域名URL
- CStringArray imageNames; //处理后的图片名集合
- BOOL m_bNavigatedToLocalHTML;
- //BOOL m_bInputNewURL;
- CString localStockedPath; //本地保存的HTML文件路径,C盘根目录下
- void RetrieveImagesLinks(IHTMLDocument2* pDocument);
- void JointImagesURL();
- void ModifyOriHTMLPicLinks(LPCTSTR htmlPath);
- CString GetImgSrc(CString& linkInfo, CString& strImgSrc);
- BOOL simpleMatch(CString& imgSrc, CString& strHttp); //匹配成功返回TRUE,失败返回FALSE
- void synFullURLPath(int index, CString& subStrLink);
- BOOL elimInvalidPrefixSymbols(CString& strPrefix);
- //void replaceIExplorerImgOuterHTML(CString& strOtHTML, LPCTSTR imgPath);
- };
- OBJECT_ENTRY_AUTO(__uuidof(ImageProcessBHO), CImageProcessBHO)