WebPage.h 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. #pragma once
  2. #include <atlbase.h>
  3. #include <Mshtml.h>
  4. class CWebPage
  5. {
  6. public:
  7. CWebPage();
  8. virtual ~CWebPage();
  9. bool SetDocument(IDispatch* pDisp);
  10. LPDISPATCH GetHtmlDocument() const;
  11. const CString GetLastError() const;
  12. bool GetJScript(CComPtr<IDispatch>& spDisp);
  13. bool GetJScripts(CComPtr<IHTMLElementCollection>& spColl);
  14. CString ScanJScript(CString& strAText, CStringArray& args);
  15. bool CallJScript(const CString strFunc, CComVariant* pVarResult = NULL);
  16. bool CallJScript(const CString strFunc, const CString strArg1, CComVariant* pVarResult = NULL);
  17. bool CallJScript(const CString strFunc, const CString strArg1, const CString strArg2, CComVariant* pVarResult = NULL);
  18. bool CallJScript(const CString strFunc, const CString strArg1, const CString strArg2, const CString strArg3, CComVariant* pVarResult = NULL);
  19. bool CallJScript(const CString strFunc, const CStringArray& paramArray, CComVariant* pVarResult = NULL);
  20. protected:
  21. void ShowError(LPCSTR lpszText);
  22. protected:
  23. CComPtr<IHTMLDocument2> m_spDoc;
  24. CString m_strError;
  25. };
  26. inline
  27. void CWebPage::ShowError(LPCSTR lpszText)
  28. {
  29. m_strError = CString(lpszText);
  30. }
  31. inline
  32. const CString CWebPage::GetLastError() const
  33. {
  34. return m_strError;
  35. }
  36. inline
  37. LPDISPATCH CWebPage::GetHtmlDocument() const
  38. {
  39. return m_spDoc;
  40. }
  41. CString GetNextToken(CString& strSrc, const CString strDelim, bool bTrim = false, bool bFindOneOf = true);