html.h
上传用户:zexelpump
上传日期:2007-01-04
资源大小:22k
文件大小:3k
源码类别:

WEB源码(ASP,PHP,...)

开发平台:

Visual C++

  1. /*
  2.     Implement an HTML parser using IE4's IHTMLDocument2 interface.
  3. */
  4. #ifndef __HTML_H__
  5. #define __HTML_H__
  6. #include <windows.h>
  7. #include <string>
  8. // if we are using VC6 or better get this from the stock include
  9. // directory, otherwise get it from the Internet SDK
  10. #if _MSC_VER >= 1200
  11. #pragma warning(disable:4099)   // disable spurious namespace warnings
  12. #include <mshtmdid.h>
  13. #else
  14. #include "./inetsdk/include/mshtmdid.h"
  15. #endif
  16. #import "mshtml.dll" named_guids no_namespace
  17. using namespace std;
  18. #define WM_USER_LOAD_COMPLETE   WM_USER+1
  19. class HTMLParser: public IPropertyNotifySink, IOleClientSite, IDispatch
  20. {
  21.     public:
  22. static HTMLParser *Create(); // forces dynamic allocation
  23.         STDMETHOD_(ULONG, Release)(); 
  24.         BOOL LoadHTMLFile(LPCSTR pcszFile);
  25.         long GetLinkCount();
  26.         BOOL GetLinkURL(long lIndex, string &rstrURL);
  27.         long GetImageCount();
  28.         BOOL GetImageURL(long lIndex, string &rstrURL);
  29. BOOL IsConnected() const { return SUCCEEDED(m_hrConnected); }
  30. protected:
  31. // hidden constructors/destructor to force use of Create/Release
  32.         HTMLParser(); 
  33. HTMLParser(const HTMLParser &); // eliminate compiler synthesized copy ctor
  34.         virtual ~HTMLParser();
  35.  // IUnknown methods
  36.         STDMETHOD(QueryInterface)(REFIID riid, LPVOID* ppv);
  37.         STDMETHOD_(ULONG, AddRef)();
  38.     // IPropertyNotifySink methods
  39.         STDMETHOD(OnChanged)(DISPID dispID);
  40.         STDMETHOD(OnRequestEdit)(DISPID dispID) { return NOERROR; }
  41.     // IOleClientSite methods
  42.         STDMETHOD(SaveObject)(void) 
  43.             { return E_NOTIMPL; }
  44.         STDMETHOD(GetMoniker)(DWORD dwAssign,DWORD dwWhichMoniker, IMoniker** ppmk)
  45. { return E_NOTIMPL; }
  46.      STDMETHOD(GetContainer)(IOleContainer** ppContainer)
  47. { return E_NOTIMPL; }
  48.     STDMETHOD(ShowObject)(void)
  49. { return E_NOTIMPL; }
  50.         STDMETHOD(OnShowWindow)(BOOL fShow)
  51. { return E_NOTIMPL; }
  52.         STDMETHOD(RequestNewObjectLayout)(void)
  53. { return E_NOTIMPL; }
  54.          // IDispatch method
  55.      STDMETHOD(GetTypeInfoCount)(UINT* pctinfo)
  56. { return E_NOTIMPL; }
  57.      STDMETHOD(GetTypeInfo)(UINT iTInfo,
  58.             LCID lcid,
  59.             ITypeInfo** ppTInfo)
  60. { return E_NOTIMPL; }
  61.      STDMETHOD(GetIDsOfNames)(REFIID riid,
  62.             LPOLESTR* rgszNames,
  63.             UINT cNames,
  64.             LCID lcid,
  65.             DISPID* rgDispId)
  66. { return E_NOTIMPL; }
  67.      STDMETHOD(Invoke)(DISPID dispIdMember,
  68.             REFIID riid,
  69.             LCID lcid,
  70.             WORD wFlags,
  71.             DISPPARAMS __RPC_FAR *pDispParams,
  72.             VARIANT __RPC_FAR *pVarResult,
  73.             EXCEPINFO __RPC_FAR *pExcepInfo,
  74.             UINT __RPC_FAR *puArgErr);
  75. // helper functions
  76.         BOOL GetURLFromCollection(IHTMLElementCollection *pCollection, 
  77.                                   REFIID rIID, long lIndex, string &rstrURL);
  78. // member variables
  79.         DWORD   m_dwRef;
  80.         HRESULT  m_hrConnected;
  81.         DWORD    m_dwCookie;
  82.      IHTMLDocument2* m_pMSHTML;
  83.      LPCONNECTIONPOINT m_pCP;
  84.         IHTMLElementCollection *m_pAnchorLinks;
  85.         IHTMLElementCollection *m_pImageLinks;
  86. };
  87. #endif