UIWebBrowser.h 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. #ifndef __UIWEBBROWSER_H__
  2. #define __UIWEBBROWSER_H__
  3. #pragma once
  4. #include <MsHTML.h>
  5. #include "Utils/WebBrowserEventHandler.h"
  6. #include <ExDisp.h>
  7. namespace DuiLib
  8. {
  9. class UILIB_API CWebBrowserUI
  10. : public CActiveXUI
  11. , public IDocHostUIHandler
  12. , public IServiceProvider
  13. , public IOleCommandTarget
  14. , public IDispatch
  15. , public ITranslateAccelerator
  16. , public IInternetSecurityManager
  17. {
  18. DECLARE_DUICONTROL(CWebBrowserUI)
  19. public:
  20. /// 构造函数
  21. CWebBrowserUI();
  22. virtual ~CWebBrowserUI();
  23. void SetHomePage(LPCTSTR lpszUrl);
  24. LPCTSTR GetHomePage();
  25. void SetAutoNavigation(bool bAuto = TRUE);
  26. bool IsAutoNavigation();
  27. void SetWebBrowserEventHandler(CWebBrowserEventHandler* pEventHandler);
  28. void Navigate2(LPCTSTR lpszUrl);
  29. void Refresh();
  30. void Refresh2(int Level);
  31. void GoBack();
  32. void GoForward();
  33. void NavigateHomePage();
  34. void NavigateUrl(LPCTSTR lpszUrl);
  35. virtual bool DoCreateControl();
  36. IWebBrowser2* GetWebBrowser2(void);
  37. IDispatch* GetHtmlWindow();
  38. static DISPID FindId(IDispatch *pObj, LPOLESTR pName);
  39. static HRESULT InvokeMethod(IDispatch *pObj, LPOLESTR pMehtod, VARIANT *pVarResult, VARIANT *ps, int cArgs);
  40. static HRESULT GetProperty(IDispatch *pObj, LPOLESTR pName, VARIANT *pValue);
  41. static HRESULT SetProperty(IDispatch *pObj, LPOLESTR pName, VARIANT *pValue);
  42. protected:
  43. IWebBrowser2* m_pWebBrowser2; //浏览器指针
  44. IHTMLWindow2* _pHtmlWnd2;
  45. LONG m_dwRef;
  46. DWORD m_dwCookie;
  47. virtual void ReleaseControl();
  48. HRESULT RegisterEventHandler(BOOL inAdvise);
  49. virtual void SetAttribute(LPCTSTR pstrName, LPCTSTR pstrValue);
  50. CDuiString m_sHomePage; // 默认页面
  51. bool m_bAutoNavi; // 是否启动时打开默认页面
  52. CWebBrowserEventHandler* m_pWebBrowserEventHandler; //浏览器事件处理
  53. // DWebBrowserEvents2
  54. void BeforeNavigate2( IDispatch *pDisp,VARIANT *&url,VARIANT *&Flags,VARIANT *&TargetFrameName,VARIANT *&PostData,VARIANT *&Headers,VARIANT_BOOL *&Cancel );
  55. void NavigateError(IDispatch *pDisp,VARIANT * &url,VARIANT *&TargetFrameName,VARIANT *&StatusCode,VARIANT_BOOL *&Cancel);
  56. void NavigateComplete2(IDispatch *pDisp,VARIANT *&url);
  57. void ProgressChange(LONG nProgress, LONG nProgressMax);
  58. void NewWindow3(IDispatch **pDisp, VARIANT_BOOL *&Cancel, DWORD dwFlags, BSTR bstrUrlContext, BSTR bstrUrl);
  59. void CommandStateChange(long Command,VARIANT_BOOL Enable);
  60. void TitleChange(BSTR bstrTitle);
  61. void DocumentComplete(IDispatch *pDisp,VARIANT *&url);
  62. public:
  63. virtual LPCTSTR GetClass() const;
  64. virtual LPVOID GetInterface( LPCTSTR pstrName );
  65. // IUnknown
  66. STDMETHOD_(ULONG,AddRef)();
  67. STDMETHOD_(ULONG,Release)();
  68. STDMETHOD(QueryInterface)(REFIID riid, LPVOID *ppvObject);
  69. // IDispatch
  70. virtual HRESULT STDMETHODCALLTYPE GetTypeInfoCount( __RPC__out UINT *pctinfo );
  71. virtual HRESULT STDMETHODCALLTYPE GetTypeInfo( UINT iTInfo, LCID lcid, __RPC__deref_out_opt ITypeInfo **ppTInfo );
  72. virtual HRESULT STDMETHODCALLTYPE GetIDsOfNames( __RPC__in REFIID riid, __RPC__in_ecount_full(cNames ) LPOLESTR *rgszNames, UINT cNames, LCID lcid, __RPC__out_ecount_full(cNames) DISPID *rgDispId);
  73. virtual HRESULT STDMETHODCALLTYPE Invoke( DISPID dispIdMember, REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams, VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr );
  74. // IDocHostUIHandler
  75. STDMETHOD(ShowContextMenu)(DWORD dwID, POINT* pptPosition, IUnknown* pCommandTarget, IDispatch* pDispatchObjectHit);
  76. STDMETHOD(GetHostInfo)(DOCHOSTUIINFO* pInfo);
  77. STDMETHOD(ShowUI)(DWORD dwID, IOleInPlaceActiveObject* pActiveObject, IOleCommandTarget* pCommandTarget, IOleInPlaceFrame* pFrame, IOleInPlaceUIWindow* pDoc);
  78. STDMETHOD(HideUI)();
  79. STDMETHOD(UpdateUI)();
  80. STDMETHOD(EnableModeless)(BOOL fEnable);
  81. STDMETHOD(OnDocWindowActivate)(BOOL fActivate);
  82. STDMETHOD(OnFrameWindowActivate)(BOOL fActivate);
  83. STDMETHOD(ResizeBorder)(LPCRECT prcBorder, IOleInPlaceUIWindow* pUIWindow, BOOL fFrameWindow);
  84. STDMETHOD(TranslateAccelerator)(LPMSG lpMsg, const GUID* pguidCmdGroup, DWORD nCmdID); //浏览器消息过滤
  85. STDMETHOD(GetOptionKeyPath)(LPOLESTR* pchKey, DWORD dwReserved);
  86. STDMETHOD(GetDropTarget)(IDropTarget* pDropTarget, IDropTarget** ppDropTarget);
  87. STDMETHOD(GetExternal)(IDispatch** ppDispatch);
  88. STDMETHOD(TranslateUrl)(DWORD dwTranslate, OLECHAR* pchURLIn, OLECHAR** ppchURLOut);
  89. STDMETHOD(FilterDataObject)(IDataObject* pDO, IDataObject** ppDORet);
  90. // IServiceProvider
  91. STDMETHOD(QueryService)(REFGUID guidService, REFIID riid, void** ppvObject);
  92. // IOleCommandTarget
  93. virtual HRESULT STDMETHODCALLTYPE QueryStatus( __RPC__in_opt const GUID *pguidCmdGroup, ULONG cCmds, __RPC__inout_ecount_full(cCmds ) OLECMD prgCmds[ ], __RPC__inout_opt OLECMDTEXT *pCmdText);
  94. virtual HRESULT STDMETHODCALLTYPE Exec( __RPC__in_opt const GUID *pguidCmdGroup, DWORD nCmdID, DWORD nCmdexecopt, __RPC__in_opt VARIANT *pvaIn, __RPC__inout_opt VARIANT *pvaOut );
  95. // IDownloadManager
  96. STDMETHOD(Download)(
  97. /* [in] */ IMoniker *pmk,
  98. /* [in] */ IBindCtx *pbc,
  99. /* [in] */ DWORD dwBindVerb,
  100. /* [in] */ LONG grfBINDF,
  101. /* [in] */ BINDINFO *pBindInfo,
  102. /* [in] */ LPCOLESTR pszHeaders,
  103. /* [in] */ LPCOLESTR pszRedir,
  104. /* [in] */ UINT uiCP);
  105. virtual HRESULT STDMETHODCALLTYPE SetSecuritySite(
  106. /* [unique][in] */ __RPC__in_opt IInternetSecurityMgrSite *pSite){return S_OK;}
  107. virtual HRESULT STDMETHODCALLTYPE GetSecuritySite(
  108. /* [out] */ __RPC__deref_out_opt IInternetSecurityMgrSite **ppSite){return S_OK;}
  109. virtual HRESULT STDMETHODCALLTYPE MapUrlToZone(
  110. /* [in] */ __RPC__in LPCWSTR pwszUrl,
  111. /* [out] */ __RPC__out DWORD *pdwZone,
  112. /* [in] */ DWORD dwFlags) {return S_OK;}
  113. virtual HRESULT STDMETHODCALLTYPE GetSecurityId(
  114. /* [in] */ __RPC__in LPCWSTR pwszUrl,
  115. /* [size_is][out] */ __RPC__out_ecount_full(*pcbSecurityId) BYTE *pbSecurityId,
  116. /* [out][in] */ __RPC__inout DWORD *pcbSecurityId,
  117. /* [in] */ DWORD_PTR dwReserved) {return S_OK;}
  118. virtual HRESULT STDMETHODCALLTYPE ProcessUrlAction(
  119. /* [in] */ __RPC__in LPCWSTR pwszUrl,
  120. /* [in] */ DWORD dwAction,
  121. /* [size_is][out] */ __RPC__out_ecount_full(cbPolicy) BYTE *pPolicy,
  122. /* [in] */ DWORD cbPolicy,
  123. /* [unique][in] */ __RPC__in_opt BYTE *pContext,
  124. /* [in] */ DWORD cbContext,
  125. /* [in] */ DWORD dwFlags,
  126. /* [in] */ DWORD dwReserved)
  127. {
  128. return S_OK;
  129. }
  130. virtual HRESULT STDMETHODCALLTYPE QueryCustomPolicy(
  131. /* [in] */ __RPC__in LPCWSTR pwszUrl,
  132. /* [in] */ __RPC__in REFGUID guidKey,
  133. /* [size_is][size_is][out] */ __RPC__deref_out_ecount_full_opt(*pcbPolicy) BYTE **ppPolicy,
  134. /* [out] */ __RPC__out DWORD *pcbPolicy,
  135. /* [in] */ __RPC__in BYTE *pContext,
  136. /* [in] */ DWORD cbContext,
  137. /* [in] */ DWORD dwReserved) {return S_OK;}
  138. virtual HRESULT STDMETHODCALLTYPE SetZoneMapping(
  139. /* [in] */ DWORD dwZone,
  140. /* [in] */ __RPC__in LPCWSTR lpszPattern,
  141. /* [in] */ DWORD dwFlags) {return S_OK;}
  142. virtual HRESULT STDMETHODCALLTYPE GetZoneMappings(
  143. /* [in] */ DWORD dwZone,
  144. /* [out] */ __RPC__deref_out_opt IEnumString **ppenumString,
  145. /* [in] */ DWORD dwFlags) {return S_OK;}
  146. // ITranslateAccelerator
  147. // Duilib消息分发给WebBrowser
  148. virtual LRESULT TranslateAccelerator( MSG *pMsg );
  149. };
  150. } // namespace DuiLib
  151. #endif // __UIWEBBROWSER_H__