// MWebBrowser.cpp --- simple Win32 Web Browser // Copyright (C) 2019 Katayama Hirofumi MZ // This file is public domain software. #ifndef MWEB_BROWSER_HPP_ #define MWEB_BROWSER_HPP_ 13 // Version 13 #define INITGUID #include #include #include #include class MWebBrowser : public IOleClientSite, public IOleInPlaceSite, public IStorage, public IServiceProvider, public IHttpSecurity, public IDocHostUIHandler { public: static MWebBrowser *Create(HWND hwndParent); RECT PixelToHIMETRIC(const RECT& rc); HWND GetControlWindow(); HWND GetIEServerWindow(); void MoveWindow(const RECT& rc); void GoHome(); void GoBack(); void GoForward(); void Stop(); void StopDownload(); void Refresh(); HRESULT Navigate(const WCHAR *url = L"about:blank"); HRESULT Navigate2(const WCHAR *url, DWORD dwFlags = 0); void Print(BOOL bBang = FALSE); void PrintPreview(); void PageSetup(); void Destroy(); BOOL TranslateAccelerator(LPMSG pMsg); IWebBrowser2 *GetIWebBrowser2(); IHTMLDocument2 *GetIHTMLDocument2(); void AllowInsecure(BOOL bAllow); HRESULT Quit(); HRESULT get_Application(IDispatch **ppApplication) const; HRESULT get_LocationURL(BSTR *bstrURL) const; HRESULT get_mimeType(BSTR *bstrMIME) const; HRESULT put_Silent(VARIANT_BOOL bSilent); BOOL is_busy() const; HRESULT ZoomUp(); HRESULT ZoomDown(); HRESULT Zoom100(); HRESULT ZoomPercents(LONG percents); // IUnknown interface STDMETHODIMP QueryInterface(REFIID riid, void **ppvObj); STDMETHODIMP_(ULONG) AddRef(); STDMETHODIMP_(ULONG) Release(); // IOleWindow interface STDMETHODIMP GetWindow(HWND *phwnd); STDMETHODIMP ContextSensitiveHelp(BOOL fEnterMode); // IOleInPlaceSite interface STDMETHODIMP CanInPlaceActivate(); STDMETHODIMP OnInPlaceActivate(); STDMETHODIMP OnUIActivate(); STDMETHODIMP GetWindowContext( IOleInPlaceFrame **ppFrame, IOleInPlaceUIWindow **ppDoc, LPRECT lprcPosRect, LPRECT lprcClipRect, LPOLEINPLACEFRAMEINFO lpFrameInfo); STDMETHODIMP Scroll(SIZE scrollExtant); STDMETHODIMP OnUIDeactivate(BOOL fUndoable); STDMETHODIMP OnInPlaceDeactivate(); STDMETHODIMP DiscardUndoState(); STDMETHODIMP DeactivateAndUndo(); STDMETHODIMP OnPosRectChange(LPCRECT lprcPosRect); // IOleClientSite interface STDMETHODIMP SaveObject(); STDMETHODIMP GetMoniker( DWORD dwAssign, DWORD dwWhichMoniker, IMoniker **ppmk); STDMETHODIMP GetContainer(IOleContainer **ppContainer); STDMETHODIMP ShowObject(); STDMETHODIMP OnShowWindow(BOOL fShow); STDMETHODIMP RequestNewObjectLayout(); // IStorage interface STDMETHODIMP CreateStream( const OLECHAR *pwcsName, DWORD grfMode, DWORD reserved1, DWORD reserved2, IStream **ppstm); STDMETHODIMP OpenStream( const OLECHAR *pwcsName, void *reserved1, DWORD grfMode, DWORD reserved2, IStream **ppstm); STDMETHODIMP CreateStorage( const OLECHAR *pwcsName, DWORD grfMode, DWORD reserved1, DWORD reserved2, IStorage **ppstg); STDMETHODIMP OpenStorage( const OLECHAR *pwcsName, IStorage *pstgPriority, DWORD grfMode, SNB snbExclude, DWORD reserved, IStorage **ppstg); STDMETHODIMP CopyTo( DWORD ciidExclude, const IID *rgiidExclude, SNB snbExclude, IStorage *pstgDest); STDMETHODIMP MoveElementTo( const OLECHAR *pwcsName, IStorage *pstgDest, const OLECHAR *pwcsNewName, DWORD grfFlags); STDMETHODIMP Commit(DWORD grfCommitFlags); STDMETHODIMP Revert(); STDMETHODIMP EnumElements( DWORD reserved1, void *reserved2, DWORD reserved3, IEnumSTATSTG **ppenum); STDMETHODIMP DestroyElement(const OLECHAR *pwcsName); STDMETHODIMP RenameElement( const OLECHAR *pwcsOldName, const OLECHAR *pwcsNewName); STDMETHODIMP SetElementTimes( const OLECHAR *pwcsName, const FILETIME *pctime, const FILETIME *patime, const FILETIME *pmtime); STDMETHODIMP SetClass(REFCLSID clsid); STDMETHODIMP SetStateBits(DWORD grfStateBits, DWORD grfMask); STDMETHODIMP Stat(STATSTG *pstatstg, DWORD grfStatFlag); // IServiceProvider interface STDMETHODIMP QueryService( REFGUID guidService, REFIID riid, void **ppvObject); // IWindowForBindingUI interface STDMETHODIMP GetWindow(REFGUID rguidReason, HWND *phwnd); // IHttpSecurity interface STDMETHODIMP OnSecurityProblem(DWORD dwProblem); // IDocHostUIHandler interface STDMETHODIMP ShowContextMenu( DWORD dwID, POINT *ppt, IUnknown *pcmdtReserved, IDispatch *pdispReserved); STDMETHODIMP GetHostInfo(DOCHOSTUIINFO *pInfo); STDMETHODIMP ShowUI( DWORD dwID, IOleInPlaceActiveObject *pActiveObject, IOleCommandTarget *pCommandTarget, IOleInPlaceFrame *pFrame, IOleInPlaceUIWindow *pDoc); STDMETHODIMP HideUI(); STDMETHODIMP UpdateUI(); STDMETHODIMP EnableModeless(BOOL fEnable); STDMETHODIMP OnDocWindowActivate(BOOL fActivate); STDMETHODIMP OnFrameWindowActivate(BOOL fActivate); STDMETHODIMP ResizeBorder( LPCRECT prcBorder, IOleInPlaceUIWindow *pUIWindow, BOOL fRameWindow); STDMETHODIMP TranslateAccelerator( LPMSG lpMsg, const GUID *pguidCmdGroup, DWORD nCmdID); STDMETHODIMP GetOptionKeyPath(LPOLESTR *pchKey, DWORD dw); STDMETHODIMP GetDropTarget( IDropTarget *pDropTarget, IDropTarget **ppDropTarget); STDMETHODIMP GetExternal(IDispatch **ppDispatch); STDMETHODIMP TranslateUrl( DWORD dwTranslate, OLECHAR *pchURLIn, OLECHAR **ppchURLOut); STDMETHODIMP FilterDataObject(IDataObject *pDO, IDataObject **ppDORet); protected: LONG m_nRefCount; HWND m_hwndParent; HWND m_hwndCtrl; HWND m_hwndIEServer; IWebBrowser2 *m_web_browser2; IOleObject *m_ole_object; IOleInPlaceObject *m_ole_inplace_object; IDocHostUIHandler *m_pDocHostUIHandler; RECT m_rc; HRESULT m_hr; BOOL m_bAllowInsecure; LONG m_nZoomPercents; MWebBrowser(HWND hwndParent); virtual ~MWebBrowser(); HRESULT CreateBrowser(HWND hwndParent); BOOL IsCreated() const; private: MWebBrowser(const MWebBrowser&); MWebBrowser& operator=(const MWebBrowser&); }; #endif // ndef MWEB_BROWSER_HPP_