)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY $<1:${CMAKE_FINAL_OUTPUT_DIRECTORY}>)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY $<1:${CMAKE_FINAL_OUTPUT_DIRECTORY}>)
-add_library(winsharedutils MODULE otsu.cpp cinterface.cpp clipboard.cpp lnk.cpp dllmain.cpp levenshtein.cpp muteprocess.cpp sapi_dll.cpp simplemecab.cpp WebBrowser.cpp icon.cpp)
+add_library(winsharedutils MODULE otsu.cpp cinterface.cpp clipboard.cpp lnk.cpp dllmain.cpp levenshtein.cpp muteprocess.cpp sapi_dll.cpp simplemecab.cpp SimpleBrowser.cpp MWebBrowser.cpp icon.cpp)
if(${CMAKE_SIZEOF_VOID_P} EQUAL 8)
set_target_properties(winsharedutils PROPERTIES OUTPUT_NAME "winsharedutils64")
diff --git a/plugins/winsharedutils/MWebBrowser.cpp b/plugins/winsharedutils/MWebBrowser.cpp
new file mode 100644
index 00000000..7b5be724
--- /dev/null
+++ b/plugins/winsharedutils/MWebBrowser.cpp
@@ -0,0 +1,989 @@
+// MWebBrowser.cpp --- simple Win32 Web Browser
+// Copyright (C) 2019 Katayama Hirofumi MZ
+// This file is public domain software.
+
+#include "MWebBrowser.hpp"
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+
+/*static*/ MWebBrowser *
+MWebBrowser::Create(HWND hwndParent)
+{
+ MWebBrowser *pBrowser = new MWebBrowser(hwndParent);
+ if (!pBrowser->IsCreated())
+ {
+ pBrowser->Release();
+ pBrowser = NULL;
+ }
+ return pBrowser;
+}
+
+MWebBrowser::MWebBrowser(HWND hwndParent) :
+ m_nRefCount(0),
+ m_hwndParent(NULL),
+ m_hwndCtrl(NULL),
+ m_hwndIEServer(NULL),
+ m_web_browser2(NULL),
+ m_ole_object(NULL),
+ m_ole_inplace_object(NULL),
+ m_pDocHostUIHandler(NULL),
+ m_hr(S_OK),
+ m_bAllowInsecure(FALSE),
+ m_nZoomPercents(100)
+{
+ ::SetRectEmpty(&m_rc);
+
+ m_hr = CreateBrowser(hwndParent);
+}
+
+BOOL MWebBrowser::IsCreated() const
+{
+ return m_hr == S_OK;
+}
+
+MWebBrowser::~MWebBrowser()
+{
+ if (m_pDocHostUIHandler)
+ {
+ m_pDocHostUIHandler->Release();
+ m_pDocHostUIHandler = NULL;
+ }
+ if (m_ole_object)
+ {
+ m_ole_object->Release();
+ m_ole_object = NULL;
+ }
+ if (m_ole_inplace_object)
+ {
+ m_ole_inplace_object->Release();
+ m_ole_inplace_object = NULL;
+ }
+ if (m_web_browser2)
+ {
+ m_web_browser2->Release();
+ m_web_browser2 = NULL;
+ }
+}
+
+IWebBrowser2 *MWebBrowser::GetIWebBrowser2()
+{
+ return m_web_browser2;
+}
+
+IHTMLDocument2 *MWebBrowser::GetIHTMLDocument2()
+{
+ IDispatch *pDisp;
+ m_web_browser2->get_Document(&pDisp);
+ if (pDisp)
+ {
+ return static_cast(pDisp);
+ }
+ return NULL;
+}
+
+HWND MWebBrowser::GetControlWindow()
+{
+ if (::IsWindow(m_hwndCtrl))
+ return m_hwndCtrl;
+
+ if (!m_ole_inplace_object)
+ return NULL;
+
+ m_ole_inplace_object->GetWindow(&m_hwndCtrl);
+ return m_hwndCtrl;
+}
+
+HWND MWebBrowser::GetIEServerWindow()
+{
+ if (::IsWindow(m_hwndIEServer))
+ return m_hwndIEServer;
+
+ HWND hwnd = ::GetWindow(m_hwndParent, GW_CHILD);
+ while (hwnd)
+ {
+ WCHAR szClass[64];
+ ::GetClassNameW(hwnd, szClass, 64);
+ if (lstrcmpiW(szClass, L"Internet Explorer_Server") == 0)
+ {
+ m_hwndIEServer = hwnd;
+ return hwnd;
+ }
+ hwnd = ::GetWindow(hwnd, GW_CHILD);
+ }
+
+ return NULL;
+}
+
+HRESULT MWebBrowser::CreateBrowser(HWND hwndParent)
+{
+ m_hwndParent = hwndParent;
+
+ HRESULT hr;
+ hr = ::OleCreate(CLSID_WebBrowser, IID_IOleObject, OLERENDER_DRAW, NULL,
+ this, this, (void **)&m_ole_object);
+ if (FAILED(hr))
+ {
+ assert(0);
+ return hr;
+ }
+
+ if (m_pDocHostUIHandler)
+ {
+ m_pDocHostUIHandler->Release();
+ m_pDocHostUIHandler = NULL;
+ }
+ m_ole_object->QueryInterface(&m_pDocHostUIHandler);
+
+ hr = m_ole_object->SetClientSite(this);
+ if (FAILED(hr))
+ {
+ assert(0);
+ return hr;
+ }
+
+ hr = ::OleSetContainedObject(m_ole_object, TRUE);
+ if (FAILED(hr))
+ {
+ assert(0);
+ return hr;
+ }
+
+ RECT rc;
+ ::SetRectEmpty(&rc);
+ hr = m_ole_object->DoVerb(OLEIVERB_INPLACEACTIVATE, NULL, this, 0,
+ m_hwndParent, &rc);
+ if (FAILED(hr))
+ {
+ assert(0);
+ return hr;
+ }
+
+ hr = m_ole_object->QueryInterface(&m_web_browser2);
+ if (FAILED(hr))
+ {
+ assert(0);
+ return hr;
+ }
+
+ HWND hwnd = GetControlWindow();
+
+ DWORD exstyle = GetWindowLong(hwnd, GWL_EXSTYLE);
+ SetWindowLong(hwnd, GWL_EXSTYLE, exstyle | WS_EX_CLIENTEDGE);
+
+ ShowWindow(hwnd, SW_SHOWNORMAL);
+
+ Release();
+
+ return S_OK;
+}
+
+void MWebBrowser::Destroy()
+{
+ if (m_web_browser2)
+ m_web_browser2->Quit();
+
+ m_hwndParent = NULL;
+ m_hwndCtrl = NULL;
+ m_hwndIEServer = NULL;
+}
+
+RECT MWebBrowser::PixelToHIMETRIC(const RECT& rc)
+{
+ HDC hDC = ::GetDC(NULL);
+ INT nPixelsPerInchX = ::GetDeviceCaps(hDC, LOGPIXELSX);
+ INT nPixelsPerInchY = ::GetDeviceCaps(hDC, LOGPIXELSY);
+ RECT ret;
+ ret.left = MulDiv(rc.left, 2540, nPixelsPerInchX);
+ ret.top = MulDiv(rc.top, 2540, nPixelsPerInchY);
+ ret.right = MulDiv(rc.right, 2540, nPixelsPerInchX);
+ ret.bottom = MulDiv(rc.bottom, 2540, nPixelsPerInchY);
+ ::ReleaseDC(NULL, hDC);
+ return ret;
+}
+
+void MWebBrowser::MoveWindow(const RECT& rc)
+{
+ m_rc = rc;
+
+ SIZEL siz;
+ RECT rcHIMETRIC = PixelToHIMETRIC(rc);
+ siz.cx = rcHIMETRIC.right - rcHIMETRIC.left;
+ siz.cy = rcHIMETRIC.bottom - rcHIMETRIC.top;
+ m_ole_object->SetExtent(DVASPECT_CONTENT, &siz);
+
+ if (m_ole_inplace_object)
+ {
+ m_ole_inplace_object->SetObjectRects(&m_rc, &m_rc);
+ }
+}
+
+void MWebBrowser::GoHome()
+{
+ if (m_web_browser2)
+ m_web_browser2->GoHome();
+}
+
+void MWebBrowser::GoBack()
+{
+ if (m_web_browser2)
+ m_web_browser2->GoBack();
+}
+
+void MWebBrowser::GoForward()
+{
+ if (m_web_browser2)
+ m_web_browser2->GoForward();
+}
+
+void MWebBrowser::Stop()
+{
+ if (m_web_browser2)
+ m_web_browser2->Stop();
+}
+
+void MWebBrowser::StopDownload()
+{
+ if (!m_web_browser2)
+ return;
+
+ IDispatch *pDisp;
+ m_web_browser2->get_Document(&pDisp);
+ if (pDisp)
+ {
+ IOleCommandTarget *pCmdTarget = NULL;
+ pDisp->QueryInterface(&pCmdTarget);
+ if (pCmdTarget)
+ {
+ OLECMDEXECOPT option = OLECMDEXECOPT_DONTPROMPTUSER;
+ pCmdTarget->Exec(NULL, OLECMDID_STOPDOWNLOAD, option, NULL, NULL);
+ pCmdTarget->Release();
+ }
+ pDisp->Release();
+ }
+}
+
+void MWebBrowser::Refresh()
+{
+ if (m_web_browser2)
+ m_web_browser2->Refresh();
+}
+
+HRESULT MWebBrowser::Navigate(const WCHAR *url)
+{
+ HRESULT hr = E_FAIL;
+ if (m_web_browser2)
+ {
+ bstr_t bstrURL(url);
+ variant_t flags(0);
+ hr = m_web_browser2->Navigate(bstrURL, &flags, 0, 0, 0);
+ }
+ return hr;
+}
+
+HRESULT MWebBrowser::Navigate2(const WCHAR *url, DWORD dwFlags)
+{
+ HRESULT hr = E_FAIL;
+ if (!m_web_browser2)
+ {
+ return hr;
+ }
+ VARIANT var1, var2, varEmpty;
+
+ VariantInit(&var1);
+ VariantInit(&var2);
+ VariantInit(&varEmpty);
+
+ V_VT(&var1) = VT_BSTR;
+ V_BSTR(&var1) = SysAllocString(url);
+
+ V_VT(&var2) = VT_I4;
+ V_I4(&var2) = dwFlags;
+
+ V_VT(&varEmpty) = VT_EMPTY;
+
+ hr = m_web_browser2->Navigate2(&var1, &var2, &varEmpty, &varEmpty, &varEmpty);
+
+ VariantClear(&var1);
+ VariantClear(&var2);
+ VariantClear(&varEmpty);
+
+ return hr;
+}
+
+void MWebBrowser::Print(BOOL bBang)
+{
+ if (!m_web_browser2)
+ return;
+
+ IDispatch *pDisp;
+ m_web_browser2->get_Document(&pDisp);
+ if (pDisp)
+ {
+ IOleCommandTarget *pCmdTarget = NULL;
+ pDisp->QueryInterface(&pCmdTarget);
+ if (pCmdTarget)
+ {
+ OLECMDEXECOPT option;
+ if (bBang)
+ option = OLECMDEXECOPT_DONTPROMPTUSER;
+ else
+ option = OLECMDEXECOPT_PROMPTUSER;
+ pCmdTarget->Exec(NULL, OLECMDID_PRINT, option, NULL, NULL);
+ pCmdTarget->Release();
+ }
+ pDisp->Release();
+ }
+}
+
+void MWebBrowser::PrintPreview()
+{
+ if (!m_web_browser2)
+ return;
+
+ IDispatch *pDisp;
+ m_web_browser2->get_Document(&pDisp);
+ if (pDisp)
+ {
+ IOleCommandTarget *pCmdTarget = NULL;
+ pDisp->QueryInterface(&pCmdTarget);
+ if (pCmdTarget)
+ {
+ OLECMDEXECOPT option = OLECMDEXECOPT_DONTPROMPTUSER;
+ pCmdTarget->Exec(NULL, OLECMDID_PRINTPREVIEW, option, NULL, NULL);
+ pCmdTarget->Release();
+ }
+ pDisp->Release();
+ }
+}
+
+void MWebBrowser::PageSetup()
+{
+ if (!m_web_browser2)
+ return;
+
+ IDispatch *pDisp;
+ m_web_browser2->get_Document(&pDisp);
+ if (pDisp)
+ {
+ IOleCommandTarget *pCmdTarget = NULL;
+ pDisp->QueryInterface(&pCmdTarget);
+ if (pCmdTarget)
+ {
+ OLECMDEXECOPT option = OLECMDEXECOPT_DONTPROMPTUSER;
+ pCmdTarget->Exec(NULL, OLECMDID_PAGESETUP, option, NULL, NULL);
+ pCmdTarget->Release();
+ }
+ pDisp->Release();
+ }
+}
+
+BOOL MWebBrowser::TranslateAccelerator(LPMSG pMsg)
+{
+ if (!m_web_browser2)
+ return FALSE;
+
+ IOleInPlaceActiveObject *pOIPAO = NULL;
+ HRESULT hr = m_web_browser2->QueryInterface(&pOIPAO);
+ if (SUCCEEDED(hr))
+ {
+ hr = pOIPAO->TranslateAccelerator(pMsg);
+ pOIPAO->Release();
+ return hr == S_OK;
+ }
+ return FALSE;
+}
+
+HRESULT MWebBrowser::get_LocationURL(BSTR *bstrURL) const
+{
+ if (!m_web_browser2)
+ {
+ *bstrURL = NULL;
+ return E_FAIL;
+ }
+
+ return m_web_browser2->get_LocationURL(bstrURL);
+}
+
+HRESULT MWebBrowser::get_mimeType(BSTR *bstrMIME) const
+{
+ if (!m_web_browser2)
+ {
+ *bstrMIME = NULL;
+ return E_FAIL;
+ }
+
+ HRESULT hr = E_FAIL;
+ IDispatch *pDisp;
+ m_web_browser2->get_Document(&pDisp);
+ if (pDisp)
+ {
+ IHTMLDocument2 *pDocument = static_cast(pDisp);
+ hr = pDocument->get_mimeType(bstrMIME);
+ pDisp->Release();
+ }
+
+ return hr;
+}
+
+BOOL MWebBrowser::is_busy() const
+{
+ if (!m_web_browser2)
+ {
+ return FALSE;
+ }
+
+ VARIANT_BOOL b = FALSE;
+ m_web_browser2->get_Busy(&b);
+ return b;
+}
+
+HRESULT MWebBrowser::get_Application(IDispatch **ppApplication) const
+{
+ *ppApplication = NULL;
+ if (!m_web_browser2)
+ return E_NOINTERFACE;
+
+ return m_web_browser2->get_Application(ppApplication);
+}
+
+void MWebBrowser::AllowInsecure(BOOL bAllow)
+{
+ m_bAllowInsecure = bAllow;
+}
+
+HRESULT MWebBrowser::put_Silent(VARIANT_BOOL bSilent)
+{
+ if (!m_web_browser2)
+ return E_NOINTERFACE;
+ return m_web_browser2->put_Silent(bSilent);
+}
+
+HRESULT MWebBrowser::ZoomUp()
+{
+ LONG percents = m_nZoomPercents;
+ if (percents >= 300)
+ return E_FAIL;
+
+ if (percents < 100)
+ {
+ percents += 10;
+ }
+ else
+ {
+ percents += 50;
+ }
+
+ return ZoomPercents(percents);
+}
+
+HRESULT MWebBrowser::ZoomDown()
+{
+ LONG percents = m_nZoomPercents;
+ if (percents <= 50)
+ return E_FAIL;
+
+ if (percents > 100)
+ {
+ percents -= 50;
+ }
+ else
+ {
+ percents -= 10;
+ }
+
+ return ZoomPercents(percents);
+}
+
+HRESULT MWebBrowser::Zoom100()
+{
+ return ZoomPercents(100);
+}
+
+HRESULT MWebBrowser::ZoomPercents(LONG percents)
+{
+ VARIANT zoom;
+ VariantInit(&zoom);
+ V_VT(&zoom) = VT_I4;
+ V_I4(&zoom) = percents;
+
+ OLECMDEXECOPT option = OLECMDEXECOPT_DONTPROMPTUSER;
+ HRESULT hr = m_web_browser2->ExecWB(OLECMDID_OPTICAL_ZOOM, option, &zoom, NULL);
+ if (SUCCEEDED(hr))
+ {
+ m_nZoomPercents = percents;
+ }
+ return hr;
+}
+
+// IUnknown interface
+
+STDMETHODIMP MWebBrowser::QueryInterface(REFIID riid, void **ppvObj)
+{
+ if (riid == __uuidof(IUnknown))
+ {
+ *ppvObj = static_cast(this);
+ }
+ else if (riid == __uuidof(IOleInPlaceSite))
+ {
+ *ppvObj = static_cast(this);
+ }
+ else if (riid == __uuidof(IServiceProvider))
+ {
+ *ppvObj = static_cast(this);
+ }
+ else if (riid == __uuidof(IDocHostUIHandler))
+ {
+ *ppvObj = static_cast(this);
+ }
+ else
+ {
+ return E_NOINTERFACE;
+ }
+
+ AddRef();
+ return S_OK;
+}
+
+STDMETHODIMP_(ULONG) MWebBrowser::AddRef()
+{
+ m_nRefCount++;
+ return m_nRefCount;
+}
+
+STDMETHODIMP_(ULONG) MWebBrowser::Release()
+{
+ --m_nRefCount;
+ if (m_nRefCount != 0)
+ return m_nRefCount;
+
+ delete this;
+ return 0;
+}
+
+// IOleWindow interface
+
+STDMETHODIMP MWebBrowser::GetWindow(HWND *phwnd)
+{
+ *phwnd = m_hwndParent;
+ return S_OK;
+}
+
+STDMETHODIMP MWebBrowser::ContextSensitiveHelp(BOOL fEnterMode)
+{
+ return E_NOTIMPL;
+}
+
+// IOleInPlaceSite interface
+
+STDMETHODIMP MWebBrowser::CanInPlaceActivate()
+{
+ return S_OK;
+}
+
+STDMETHODIMP MWebBrowser::OnInPlaceActivate()
+{
+ ::OleLockRunning(m_ole_object, TRUE, FALSE);
+ m_ole_object->QueryInterface(&m_ole_inplace_object);
+ m_ole_inplace_object->SetObjectRects(&m_rc, &m_rc);
+ return S_OK;
+}
+
+STDMETHODIMP MWebBrowser::OnUIActivate()
+{
+ return S_OK;
+}
+
+STDMETHODIMP MWebBrowser::GetWindowContext(
+ IOleInPlaceFrame **ppFrame,
+ IOleInPlaceUIWindow **ppDoc,
+ LPRECT lprcPosRect,
+ LPRECT lprcClipRect,
+ LPOLEINPLACEFRAMEINFO lpFrameInfo)
+{
+ *ppFrame = NULL;
+ *ppDoc = NULL;
+ *lprcPosRect = m_rc;
+ *lprcClipRect = *lprcPosRect;
+
+ lpFrameInfo->fMDIApp = FALSE;
+ lpFrameInfo->hwndFrame = m_hwndParent;
+ lpFrameInfo->haccel = NULL;
+ lpFrameInfo->cAccelEntries = 0;
+
+ return S_OK;
+}
+
+STDMETHODIMP MWebBrowser::Scroll(SIZE scrollExtant)
+{
+ return E_NOTIMPL;
+}
+
+STDMETHODIMP MWebBrowser::OnUIDeactivate(BOOL fUndoable)
+{
+ return S_OK;
+}
+
+STDMETHODIMP MWebBrowser::OnInPlaceDeactivate()
+{
+ m_hwndCtrl = NULL;
+ m_ole_inplace_object = NULL;
+ return S_OK;
+}
+
+STDMETHODIMP MWebBrowser::DiscardUndoState()
+{
+ return E_NOTIMPL;
+}
+
+STDMETHODIMP MWebBrowser::DeactivateAndUndo()
+{
+ return E_NOTIMPL;
+}
+
+STDMETHODIMP MWebBrowser::OnPosRectChange(LPCRECT lprcPosRect)
+{
+ return E_NOTIMPL;
+}
+
+// IOleClientSite interface
+
+STDMETHODIMP MWebBrowser::SaveObject()
+{
+ return E_NOTIMPL;
+}
+
+STDMETHODIMP MWebBrowser::GetMoniker(
+ DWORD dwAssign,
+ DWORD dwWhichMoniker,
+ IMoniker **ppmk)
+{
+ if (dwAssign == OLEGETMONIKER_ONLYIFTHERE &&
+ dwWhichMoniker == OLEWHICHMK_CONTAINER)
+ {
+ return E_FAIL;
+ }
+
+ return E_NOTIMPL;
+}
+
+STDMETHODIMP MWebBrowser::GetContainer(IOleContainer **ppContainer)
+{
+ return E_NOINTERFACE;
+}
+
+STDMETHODIMP MWebBrowser::ShowObject()
+{
+ return S_OK;
+}
+
+STDMETHODIMP MWebBrowser::OnShowWindow(BOOL fShow)
+{
+ return S_OK;
+}
+
+STDMETHODIMP MWebBrowser::RequestNewObjectLayout()
+{
+ return E_NOTIMPL;
+}
+
+// IStorage interface
+
+STDMETHODIMP MWebBrowser::CreateStream(
+ const OLECHAR *pwcsName,
+ DWORD grfMode,
+ DWORD reserved1,
+ DWORD reserved2,
+ IStream **ppstm)
+{
+ return E_NOTIMPL;
+}
+
+STDMETHODIMP MWebBrowser::OpenStream(
+ const OLECHAR *pwcsName,
+ void *reserved1,
+ DWORD grfMode,
+ DWORD reserved2,
+ IStream **ppstm)
+{
+ return E_NOTIMPL;
+}
+
+STDMETHODIMP MWebBrowser::CreateStorage(
+ const OLECHAR *pwcsName,
+ DWORD grfMode,
+ DWORD reserved1,
+ DWORD reserved2,
+ IStorage **ppstg)
+{
+ return E_NOTIMPL;
+}
+
+STDMETHODIMP MWebBrowser::OpenStorage(
+ const OLECHAR *pwcsName,
+ IStorage *pstgPriority,
+ DWORD grfMode,
+ SNB snbExclude,
+ DWORD reserved,
+ IStorage **ppstg)
+{
+ return E_NOTIMPL;
+}
+
+STDMETHODIMP MWebBrowser::CopyTo(
+ DWORD ciidExclude,
+ const IID *rgiidExclude,
+ SNB snbExclude,
+ IStorage *pstgDest)
+{
+ return E_NOTIMPL;
+}
+
+STDMETHODIMP MWebBrowser::MoveElementTo(
+ const OLECHAR *pwcsName,
+ IStorage *pstgDest,
+ const OLECHAR *pwcsNewName,
+ DWORD grfFlags)
+{
+ return E_NOTIMPL;
+}
+
+STDMETHODIMP MWebBrowser::Commit(DWORD grfCommitFlags)
+{
+ return E_NOTIMPL;
+}
+
+STDMETHODIMP MWebBrowser::Revert()
+{
+ return E_NOTIMPL;
+}
+
+STDMETHODIMP MWebBrowser::EnumElements(
+ DWORD reserved1,
+ void *reserved2,
+ DWORD reserved3,
+ IEnumSTATSTG **ppenum)
+{
+ return E_NOTIMPL;
+}
+
+STDMETHODIMP MWebBrowser::DestroyElement(
+ const OLECHAR *pwcsName)
+{
+ return E_NOTIMPL;
+}
+
+STDMETHODIMP MWebBrowser::RenameElement(
+ const OLECHAR *pwcsOldName,
+ const OLECHAR *pwcsNewName)
+{
+ return E_NOTIMPL;
+}
+
+STDMETHODIMP MWebBrowser::SetElementTimes(
+ const OLECHAR *pwcsName,
+ const FILETIME *pctime,
+ const FILETIME *patime,
+ const FILETIME *pmtime)
+{
+ return E_NOTIMPL;
+}
+
+STDMETHODIMP MWebBrowser::SetClass(REFCLSID clsid)
+{
+ return S_OK;
+}
+
+STDMETHODIMP MWebBrowser::SetStateBits(DWORD grfStateBits, DWORD grfMask)
+{
+ return E_NOTIMPL;
+}
+
+STDMETHODIMP MWebBrowser::Stat(STATSTG *pstatstg, DWORD grfStatFlag)
+{
+ return E_NOTIMPL;
+}
+
+// IServiceProvider interface
+
+STDMETHODIMP MWebBrowser::QueryService(
+ REFGUID guidService,
+ REFIID riid,
+ void **ppvObject)
+{
+ *ppvObject = NULL;
+
+ if (riid == __uuidof(IWindowForBindingUI) ||
+ riid == __uuidof(IHttpSecurity))
+ {
+ *ppvObject = static_cast(this);
+ }
+ else
+ {
+ return E_NOTIMPL;
+ }
+
+ AddRef();
+ return S_OK;
+}
+
+// IWindowForBindingUI interface
+
+STDMETHODIMP MWebBrowser::GetWindow(REFGUID rguidReason, HWND *phwnd)
+{
+ *phwnd = m_hwndParent;
+ return S_OK;
+}
+
+
+STDMETHODIMP MWebBrowser::OnSecurityProblem(DWORD dwProblem)
+{
+ printf("MWebBrowser::OnSecurityProblem\n");
+
+ BSTR url = NULL;
+ get_LocationURL(&url);
+ if (url)
+ {
+ SysFreeString(url);
+ }
+
+
+ {
+ return S_OK;
+ }
+
+ {
+ return S_OK;
+ }
+
+ return E_ABORT;
+}
+
+// IDocHostUIHandler interface
+
+STDMETHODIMP MWebBrowser::ShowContextMenu(
+ DWORD dwID,
+ POINT *ppt,
+ IUnknown *pcmdtReserved,
+ IDispatch *pdispReserved)
+{
+ return S_FALSE;
+}
+
+STDMETHODIMP MWebBrowser::GetHostInfo(DOCHOSTUIINFO *pInfo)
+{
+ if (m_pDocHostUIHandler)
+ return m_pDocHostUIHandler->GetHostInfo(pInfo);
+ return E_NOTIMPL;
+}
+
+STDMETHODIMP MWebBrowser::ShowUI(
+ DWORD dwID,
+ IOleInPlaceActiveObject *pActiveObject,
+ IOleCommandTarget *pCommandTarget,
+ IOleInPlaceFrame *pFrame,
+ IOleInPlaceUIWindow *pDoc)
+{
+ if (m_pDocHostUIHandler)
+ return m_pDocHostUIHandler->ShowUI(dwID, pActiveObject, pCommandTarget, pFrame, pDoc);
+ return E_NOTIMPL;
+}
+
+STDMETHODIMP MWebBrowser::HideUI()
+{
+ if (m_pDocHostUIHandler)
+ return m_pDocHostUIHandler->HideUI();
+ return E_NOTIMPL;
+}
+
+STDMETHODIMP MWebBrowser::UpdateUI()
+{
+ if (m_pDocHostUIHandler)
+ return m_pDocHostUIHandler->UpdateUI();
+ return E_NOTIMPL;
+}
+
+STDMETHODIMP MWebBrowser::EnableModeless(BOOL fEnable)
+{
+ if (m_pDocHostUIHandler)
+ return m_pDocHostUIHandler->EnableModeless(fEnable);
+ return E_NOTIMPL;
+}
+
+STDMETHODIMP MWebBrowser::OnDocWindowActivate(BOOL fActivate)
+{
+ if (m_pDocHostUIHandler)
+ return m_pDocHostUIHandler->OnDocWindowActivate(fActivate);
+ return E_NOTIMPL;
+}
+
+STDMETHODIMP MWebBrowser::OnFrameWindowActivate(BOOL fActivate)
+{
+ if (m_pDocHostUIHandler)
+ return m_pDocHostUIHandler->OnFrameWindowActivate(fActivate);
+ return E_NOTIMPL;
+}
+
+STDMETHODIMP MWebBrowser::ResizeBorder(
+ LPCRECT prcBorder,
+ IOleInPlaceUIWindow *pUIWindow,
+ BOOL fRameWindow)
+{
+ if (m_pDocHostUIHandler)
+ return m_pDocHostUIHandler->ResizeBorder(prcBorder, pUIWindow, fRameWindow);
+ return E_NOTIMPL;
+}
+
+STDMETHODIMP MWebBrowser::TranslateAccelerator(
+ LPMSG lpMsg,
+ const GUID *pguidCmdGroup,
+ DWORD nCmdID)
+{
+ return S_FALSE;
+}
+
+STDMETHODIMP MWebBrowser::GetOptionKeyPath(LPOLESTR *pchKey, DWORD dw)
+{
+ return S_FALSE;
+}
+
+STDMETHODIMP MWebBrowser::GetDropTarget(
+ IDropTarget *pDropTarget,
+ IDropTarget **ppDropTarget)
+{
+ *ppDropTarget = NULL;
+ return E_NOTIMPL;
+}
+
+STDMETHODIMP MWebBrowser::GetExternal(IDispatch **ppDispatch)
+{
+ *ppDispatch = NULL;
+ return E_NOTIMPL;
+}
+
+STDMETHODIMP MWebBrowser::TranslateUrl(
+ DWORD dwTranslate,
+ OLECHAR *pchURLIn,
+ OLECHAR **ppchURLOut)
+{
+ *ppchURLOut = NULL;
+ return S_FALSE;
+}
+
+STDMETHODIMP MWebBrowser::FilterDataObject(IDataObject *pDO, IDataObject **ppDORet)
+{
+ *ppDORet = NULL;
+ return S_FALSE;
+}
+
+HRESULT MWebBrowser::Quit()
+{
+ if (!m_web_browser2)
+ return E_NOINTERFACE;
+
+ return m_web_browser2->Quit();
+}
diff --git a/plugins/winsharedutils/MWebBrowser.hpp b/plugins/winsharedutils/MWebBrowser.hpp
new file mode 100644
index 00000000..1de4e403
--- /dev/null
+++ b/plugins/winsharedutils/MWebBrowser.hpp
@@ -0,0 +1,225 @@
+// 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_
diff --git a/plugins/winsharedutils/SimpleBrowser.cpp b/plugins/winsharedutils/SimpleBrowser.cpp
new file mode 100644
index 00000000..43039660
--- /dev/null
+++ b/plugins/winsharedutils/SimpleBrowser.cpp
@@ -0,0 +1,102 @@
+// SimpleBrowser.cpp --- simple Win32 browser
+// Copyright (C) 2019 Katayama Hirofumi MZ
+// This file is public domain software.
+
+#define _CRT_SECURE_NO_WARNINGS
+// SimpleBrowser.cpp --- simple Win32 browser
+// Copyright (C) 2019 Katayama Hirofumi MZ
+// This file is public domain software.
+
+#define _CRT_SECURE_NO_WARNINGS
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include "MWebBrowser.hpp"
+
+
+BOOL DoSetBrowserEmulation(DWORD dwValue)
+{
+ static const TCHAR s_szFeatureControl[] =
+ TEXT("SOFTWARE\\Microsoft\\Internet Explorer\\Main\\FeatureControl");
+
+ TCHAR szPath[MAX_PATH], *pchFileName;
+ GetModuleFileName(NULL, szPath, ARRAYSIZE(szPath));
+ pchFileName = PathFindFileName(szPath);
+
+ BOOL bOK = FALSE;
+ HKEY hkeyControl = NULL;
+ RegOpenKeyEx(HKEY_CURRENT_USER, s_szFeatureControl, 0, KEY_ALL_ACCESS, &hkeyControl);
+ if (hkeyControl)
+ {
+ HKEY hkeyEmulation = NULL;
+ RegCreateKeyEx(hkeyControl, TEXT("FEATURE_BROWSER_EMULATION"), 0, NULL, 0,
+ KEY_ALL_ACCESS, NULL, &hkeyEmulation, NULL);
+ if (hkeyEmulation)
+ {
+ if (dwValue)
+ {
+ DWORD value = dwValue, size = sizeof(value);
+ LONG result = RegSetValueEx(hkeyEmulation, pchFileName, 0,
+ REG_DWORD, (LPBYTE)&value, size);
+ bOK = (result == ERROR_SUCCESS);
+ }
+ else
+ {
+ RegDeleteValue(hkeyEmulation, pchFileName);
+ bOK = TRUE;
+ }
+
+ RegCloseKey(hkeyEmulation);
+ }
+
+ RegCloseKey(hkeyControl);
+ }
+
+ return bOK;
+}
+extern "C" __declspec(dllexport) void* html_new( HWND parent) {
+ DoSetBrowserEmulation(1);
+ auto s_pWebBrowser = MWebBrowser::Create(parent);
+ if (!s_pWebBrowser)
+ return NULL;
+
+ s_pWebBrowser->put_Silent(VARIANT_TRUE);
+
+ s_pWebBrowser->AllowInsecure(TRUE);
+
+ return s_pWebBrowser;
+}
+
+extern "C" __declspec(dllexport) void html_navigate(void* web, wchar_t* path) {
+ if(!web)return;
+ auto ww =static_cast(web);
+ ww->Navigate2(path);
+}
+extern "C" __declspec(dllexport) void html_resize(void* web,int x,int y,int w, int h) {
+ if(!web)return;
+ auto ww = static_cast(web);
+ RECT r;
+ r.left = x;
+ r.top = y;
+ r.right = x + w;
+ r.bottom = y + h;
+ ww->MoveWindow(r);
+}
+extern "C" __declspec(dllexport) void html_release(void* web) {
+ if(!web)return;
+ auto ww = static_cast(web);
+ ww->Destroy();
+ ww->Release();
+}
\ No newline at end of file
diff --git a/plugins/winsharedutils/WebBrowser.cpp b/plugins/winsharedutils/WebBrowser.cpp
deleted file mode 100644
index 5cd7fbf1..00000000
--- a/plugins/winsharedutils/WebBrowser.cpp
+++ /dev/null
@@ -1,653 +0,0 @@
-
-#include
-#include
-#include
-#include
-#include
-
-#include
-#include
-using namespace std;
-
-class WebBrowser :
- public IOleClientSite,
- public IOleInPlaceSite,
- public IStorage
-{
-
-public:
-
- WebBrowser(HWND hWndParent);
-
- bool CreateBrowser();
-
- RECT PixelToHiMetric(const RECT& _rc);
-
- virtual void SetRect(const RECT& _rc);
-
- // ----- Control methods -----
-
- void GoBack();
-
- void GoForward();
-
- void Refresh();
-
- void Navigate(wstring szUrl);
-
- // ----- IUnknown -----
-
- virtual HRESULT STDMETHODCALLTYPE QueryInterface(REFIID riid,
- void** ppvObject) override;
-
- virtual ULONG STDMETHODCALLTYPE AddRef(void);
-
- virtual ULONG STDMETHODCALLTYPE Release(void);
-
- // ---------- IOleWindow ----------
-
- virtual HRESULT STDMETHODCALLTYPE GetWindow(
- __RPC__deref_out_opt HWND* phwnd) override;
-
- virtual HRESULT STDMETHODCALLTYPE ContextSensitiveHelp(
- BOOL fEnterMode) override;
-
- // ---------- IOleInPlaceSite ----------
-
- virtual HRESULT STDMETHODCALLTYPE CanInPlaceActivate(void) override;
-
- virtual HRESULT STDMETHODCALLTYPE OnInPlaceActivate(void) override;
-
- virtual HRESULT STDMETHODCALLTYPE OnUIActivate(void) override;
-
- virtual HRESULT STDMETHODCALLTYPE GetWindowContext(
- __RPC__deref_out_opt IOleInPlaceFrame** ppFrame,
- __RPC__deref_out_opt IOleInPlaceUIWindow** ppDoc,
- __RPC__out LPRECT lprcPosRect,
- __RPC__out LPRECT lprcClipRect,
- __RPC__inout LPOLEINPLACEFRAMEINFO lpFrameInfo) override;
-
- virtual HRESULT STDMETHODCALLTYPE Scroll(
- SIZE scrollExtant) override;
-
- virtual HRESULT STDMETHODCALLTYPE OnUIDeactivate(
- BOOL fUndoable) override;
-
- virtual HWND GetControlWindow();
-
- virtual HRESULT STDMETHODCALLTYPE OnInPlaceDeactivate(void) override;
-
- virtual HRESULT STDMETHODCALLTYPE DiscardUndoState(void) override;
-
- virtual HRESULT STDMETHODCALLTYPE DeactivateAndUndo(void) override;
-
- virtual HRESULT STDMETHODCALLTYPE OnPosRectChange(
- __RPC__in LPCRECT lprcPosRect) override;
-
- // ---------- IOleClientSite ----------
-
- virtual HRESULT STDMETHODCALLTYPE SaveObject(void) override;
-
- virtual HRESULT STDMETHODCALLTYPE GetMoniker(
- DWORD dwAssign,
- DWORD dwWhichMoniker,
- __RPC__deref_out_opt IMoniker** ppmk) override;
-
- virtual HRESULT STDMETHODCALLTYPE GetContainer(
- __RPC__deref_out_opt IOleContainer** ppContainer) override;
-
- virtual HRESULT STDMETHODCALLTYPE ShowObject(void) override;
- virtual HRESULT STDMETHODCALLTYPE OnShowWindow(
- BOOL fShow) override;
-
- virtual HRESULT STDMETHODCALLTYPE RequestNewObjectLayout(void) override;
-
- // ----- IStorage -----
-
- virtual HRESULT STDMETHODCALLTYPE CreateStream(
- __RPC__in_string const OLECHAR* pwcsName,
- DWORD grfMode,
- DWORD reserved1,
- DWORD reserved2,
- __RPC__deref_out_opt IStream** ppstm) override;
-
- virtual HRESULT STDMETHODCALLTYPE OpenStream(
- const OLECHAR* pwcsName,
- void* reserved1,
- DWORD grfMode,
- DWORD reserved2,
- IStream** ppstm) override;
-
- virtual HRESULT STDMETHODCALLTYPE CreateStorage(
- __RPC__in_string const OLECHAR* pwcsName,
- DWORD grfMode,
- DWORD reserved1,
- DWORD reserved2,
- __RPC__deref_out_opt IStorage** ppstg) override;
-
- virtual HRESULT STDMETHODCALLTYPE OpenStorage(
- __RPC__in_opt_string const OLECHAR* pwcsName,
- __RPC__in_opt IStorage* pstgPriority,
- DWORD grfMode,
- __RPC__deref_opt_in_opt SNB snbExclude,
- DWORD reserved,
- __RPC__deref_out_opt IStorage** ppstg) override;
-
- virtual HRESULT STDMETHODCALLTYPE CopyTo(
- DWORD ciidExclude,
- const IID* rgiidExclude,
- __RPC__in_opt SNB snbExclude,
- IStorage* pstgDest) override;
-
- virtual HRESULT STDMETHODCALLTYPE MoveElementTo(
- __RPC__in_string const OLECHAR* pwcsName,
- __RPC__in_opt IStorage* pstgDest,
- __RPC__in_string const OLECHAR* pwcsNewName,
- DWORD grfFlags) override;
-
- virtual HRESULT STDMETHODCALLTYPE Commit(
- DWORD grfCommitFlags) override;
-
- virtual HRESULT STDMETHODCALLTYPE Revert(void) override;
-
- virtual HRESULT STDMETHODCALLTYPE EnumElements(
- DWORD reserved1,
- void* reserved2,
- DWORD reserved3,
- IEnumSTATSTG** ppenum) override;
-
- virtual HRESULT STDMETHODCALLTYPE DestroyElement(
- __RPC__in_string const OLECHAR* pwcsName) override;
-
- virtual HRESULT STDMETHODCALLTYPE RenameElement(
- __RPC__in_string const OLECHAR* pwcsOldName,
- __RPC__in_string const OLECHAR* pwcsNewName) override;
-
- virtual HRESULT STDMETHODCALLTYPE SetElementTimes(
- __RPC__in_opt_string const OLECHAR* pwcsName,
- __RPC__in_opt const FILETIME* pctime,
- __RPC__in_opt const FILETIME* patime,
- __RPC__in_opt const FILETIME* pmtime) override;
-
- virtual HRESULT STDMETHODCALLTYPE SetClass(
- __RPC__in REFCLSID clsid) override;
- virtual HRESULT STDMETHODCALLTYPE SetStateBits(
- DWORD grfStateBits,
- DWORD grfMask) override;
-
- virtual HRESULT STDMETHODCALLTYPE Stat(
- __RPC__out STATSTG* pstatstg,
- DWORD grfStatFlag) override;
-
-protected:
-
- IOleObject* oleObject;
- IOleInPlaceObject* oleInPlaceObject;
-
- IWebBrowser2* webBrowser2;
-
- LONG iComRefCount;
-
- RECT rObject;
-
- HWND hWndParent;
- HWND hWndControl;
-
-};
-WebBrowser::WebBrowser(HWND _hWndParent)
-{
- iComRefCount = 0;
- ::SetRect(&rObject, -300, -300, 300, 300);
- hWndParent = _hWndParent;
-
- if (CreateBrowser() == FALSE)
- {
- return;
- }
-
- ShowWindow(GetControlWindow(), SW_SHOW);
- this->webBrowser2->put_Silent(VARIANT_TRUE);//免错误提示
-
- this->Navigate(_T("about:blank"));
-}
-
-bool WebBrowser::CreateBrowser()
-{
- HRESULT hr;
- hr = ::OleCreate(CLSID_WebBrowser,
- IID_IOleObject, OLERENDER_DRAW, 0, this, this,
- (void**)&oleObject);
-
- if (FAILED(hr))
- {
- MessageBox(NULL, _T("Cannot create oleObject CLSID_WebBrowser"),
- _T("Error"),
- MB_ICONERROR);
- return FALSE;
- }
-
- hr = oleObject->SetClientSite(this);
- hr = OleSetContainedObject(oleObject, TRUE);
-
- RECT posRect;
- ::SetRect(&posRect, -300, -300, 300, 300);
- hr = oleObject->DoVerb(OLEIVERB_INPLACEACTIVATE,
- NULL, this, -1, hWndParent, &posRect);
- if (FAILED(hr))
- {
- MessageBox(NULL, _T("oleObject->DoVerb() failed"),
- _T("Error"),
- MB_ICONERROR);
- return FALSE;
- }
-
- hr = oleObject->QueryInterface(&webBrowser2);
- if (FAILED(hr))
- {
- MessageBox(NULL, _T("oleObject->QueryInterface(&webBrowser2) failed"),
- _T("Error"),
- MB_ICONERROR);
- return FALSE;
- }
-
- return TRUE;
-}
-
-RECT WebBrowser::PixelToHiMetric(const RECT& _rc)
-{
- static bool s_initialized = false;
- static int s_pixelsPerInchX, s_pixelsPerInchY;
- if (!s_initialized)
- {
- HDC hdc = ::GetDC(0);
- s_pixelsPerInchX = ::GetDeviceCaps(hdc, LOGPIXELSX);
- s_pixelsPerInchY = ::GetDeviceCaps(hdc, LOGPIXELSY);
- ::ReleaseDC(0, hdc);
- s_initialized = true;
- }
-
- RECT rc;
- rc.left = MulDiv(2540, _rc.left, s_pixelsPerInchX);
- rc.top = MulDiv(2540, _rc.top, s_pixelsPerInchY);
- rc.right = MulDiv(2540, _rc.right, s_pixelsPerInchX);
- rc.bottom = MulDiv(2540, _rc.bottom, s_pixelsPerInchY);
- return rc;
-}
-
-void WebBrowser::SetRect(const RECT& _rc)
-{
- rObject = _rc;
-
- {
- RECT hiMetricRect = PixelToHiMetric(rObject);
- SIZEL sz;
- sz.cx = hiMetricRect.right - hiMetricRect.left;
- sz.cy = hiMetricRect.bottom - hiMetricRect.top;
- oleObject->SetExtent(DVASPECT_CONTENT, &sz);
- }
-
- if (oleInPlaceObject != 0)
- {
- oleInPlaceObject->SetObjectRects(&rObject, &rObject);
- }
-}
-
-// ----- Control methods -----
-
-void WebBrowser::GoBack()
-{
- this->webBrowser2->GoBack();
-}
-
-void WebBrowser::GoForward()
-{
- this->webBrowser2->GoForward();
-}
-
-void WebBrowser::Refresh()
-{
- this->webBrowser2->Refresh();
-}
-
-void WebBrowser::Navigate(wstring szUrl)
-{
- bstr_t url(szUrl.c_str());
- variant_t flags(0x02u); //navNoHistory
- VARIANT url2;
- url2.vt = VT_BSTR;
- //url2.bstrVal =const_cast( LR"(C:\dataH\LunaTranslator_x86\cache\vndb\04472259b1e767bf451ac93d320450ef.html)");
- url2.bstrVal = const_cast (szUrl.c_str());
- this->webBrowser2->Navigate2(&url2, nullptr, nullptr, nullptr, nullptr);
- // this->webBrowser2->Navigate(url, &flags, 0, 0, 0); //仅支持在线网页
-}
-
-// ----- IUnknown -----
-
-HRESULT STDMETHODCALLTYPE WebBrowser::QueryInterface(REFIID riid,
- void** ppvObject)
-{
- if (riid == __uuidof(IUnknown))
- {
- (*ppvObject) = static_cast(this);
- }
- else if (riid == __uuidof(IOleInPlaceSite))
- {
- (*ppvObject) = static_cast(this);
- }
- else
- {
- return E_NOINTERFACE;
- }
-
- AddRef();
- return S_OK;
-}
-
-ULONG STDMETHODCALLTYPE WebBrowser::AddRef(void)
-{
- iComRefCount++;
- return iComRefCount;
-}
-
-ULONG STDMETHODCALLTYPE WebBrowser::Release(void)
-{
- iComRefCount--;
- return iComRefCount;
-}
-
-// ---------- IOleWindow ----------
-
-HRESULT STDMETHODCALLTYPE WebBrowser::GetWindow(
- __RPC__deref_out_opt HWND* phwnd)
-{
- (*phwnd) = hWndParent;
- return S_OK;
-}
-
-HRESULT STDMETHODCALLTYPE WebBrowser::ContextSensitiveHelp(
- BOOL fEnterMode)
-{
- return E_NOTIMPL;
-}
-
-// ---------- IOleInPlaceSite ----------
-
-HRESULT STDMETHODCALLTYPE WebBrowser::CanInPlaceActivate(void)
-{
- return S_OK;
-}
-
-HRESULT STDMETHODCALLTYPE WebBrowser::OnInPlaceActivate(void)
-{
- OleLockRunning(oleObject, TRUE, FALSE);
- oleObject->QueryInterface(&oleInPlaceObject);
- oleInPlaceObject->SetObjectRects(&rObject, &rObject);
-
- return S_OK;
-
-}
-
-HRESULT STDMETHODCALLTYPE WebBrowser::OnUIActivate(void)
-{
- return S_OK;
-}
-
-HRESULT STDMETHODCALLTYPE WebBrowser::GetWindowContext(
- __RPC__deref_out_opt IOleInPlaceFrame** ppFrame,
- __RPC__deref_out_opt IOleInPlaceUIWindow** ppDoc,
- __RPC__out LPRECT lprcPosRect,
- __RPC__out LPRECT lprcClipRect,
- __RPC__inout LPOLEINPLACEFRAMEINFO lpFrameInfo)
-{
- HWND hwnd = hWndParent;
-
- (*ppFrame) = NULL;
- (*ppDoc) = NULL;
- (*lprcPosRect).left = rObject.left;
- (*lprcPosRect).top = rObject.top;
- (*lprcPosRect).right = rObject.right;
- (*lprcPosRect).bottom = rObject.bottom;
- *lprcClipRect = *lprcPosRect;
-
- lpFrameInfo->fMDIApp = false;
- lpFrameInfo->hwndFrame = hwnd;
- lpFrameInfo->haccel = NULL;
- lpFrameInfo->cAccelEntries = 0;
-
- return S_OK;
-}
-
-HRESULT STDMETHODCALLTYPE WebBrowser::Scroll(
- SIZE scrollExtant)
-{
- return E_NOTIMPL;
-}
-
-HRESULT STDMETHODCALLTYPE WebBrowser::OnUIDeactivate(
- BOOL fUndoable)
-{
- return S_OK;
-}
-
-HWND WebBrowser::GetControlWindow()
-{
- if (hWndControl != 0)
- return hWndControl;
-
- if (oleInPlaceObject == 0)
- return 0;
-
- oleInPlaceObject->GetWindow(&hWndControl);
- return hWndControl;
-}
-
-HRESULT STDMETHODCALLTYPE WebBrowser::OnInPlaceDeactivate(void)
-{
- hWndControl = 0;
- oleInPlaceObject = 0;
-
- return S_OK;
-}
-
-HRESULT STDMETHODCALLTYPE WebBrowser::DiscardUndoState(void)
-{
- return E_NOTIMPL;
-}
-
-HRESULT STDMETHODCALLTYPE WebBrowser::DeactivateAndUndo(void)
-{
- return E_NOTIMPL;
-}
-
-HRESULT STDMETHODCALLTYPE WebBrowser::OnPosRectChange(
- __RPC__in LPCRECT lprcPosRect)
-{
- return E_NOTIMPL;
-}
-
-// ---------- IOleClientSite ----------
-
-HRESULT STDMETHODCALLTYPE WebBrowser::SaveObject(void)
-{
- return E_NOTIMPL;
-}
-
-HRESULT STDMETHODCALLTYPE WebBrowser::GetMoniker(
- DWORD dwAssign,
- DWORD dwWhichMoniker,
- __RPC__deref_out_opt IMoniker** ppmk)
-{
- if ((dwAssign == OLEGETMONIKER_ONLYIFTHERE) &&
- (dwWhichMoniker == OLEWHICHMK_CONTAINER))
- return E_FAIL;
-
- return E_NOTIMPL;
-}
-
-HRESULT STDMETHODCALLTYPE WebBrowser::GetContainer(
- __RPC__deref_out_opt IOleContainer** ppContainer)
-{
- return E_NOINTERFACE;
-}
-
-HRESULT STDMETHODCALLTYPE WebBrowser::ShowObject(void)
-{
- return S_OK;
-}
-
-HRESULT STDMETHODCALLTYPE WebBrowser::OnShowWindow(
- BOOL fShow)
-{
- return S_OK;
-}
-
-HRESULT STDMETHODCALLTYPE WebBrowser::RequestNewObjectLayout(void)
-{
- return E_NOTIMPL;
-}
-
-// ----- IStorage -----
-
-HRESULT STDMETHODCALLTYPE WebBrowser::CreateStream(
- __RPC__in_string const OLECHAR* pwcsName,
- DWORD grfMode,
- DWORD reserved1,
- DWORD reserved2,
- __RPC__deref_out_opt IStream** ppstm)
-{
- return E_NOTIMPL;
-}
-
-HRESULT STDMETHODCALLTYPE WebBrowser::OpenStream(
- const OLECHAR* pwcsName,
- void* reserved1,
- DWORD grfMode,
- DWORD reserved2,
- IStream** ppstm)
-{
- return E_NOTIMPL;
-}
-
-HRESULT STDMETHODCALLTYPE WebBrowser::CreateStorage(
- __RPC__in_string const OLECHAR* pwcsName,
- DWORD grfMode,
- DWORD reserved1,
- DWORD reserved2,
- __RPC__deref_out_opt IStorage** ppstg)
-{
- return E_NOTIMPL;
-}
-
-HRESULT STDMETHODCALLTYPE WebBrowser::OpenStorage(
- __RPC__in_opt_string const OLECHAR* pwcsName,
- __RPC__in_opt IStorage* pstgPriority,
- DWORD grfMode,
- __RPC__deref_opt_in_opt SNB snbExclude,
- DWORD reserved,
- __RPC__deref_out_opt IStorage** ppstg)
-{
- return E_NOTIMPL;
-}
-
-HRESULT STDMETHODCALLTYPE WebBrowser::CopyTo(
- DWORD ciidExclude,
- const IID* rgiidExclude,
- __RPC__in_opt SNB snbExclude,
- IStorage* pstgDest)
-{
- return E_NOTIMPL;
-}
-
-HRESULT STDMETHODCALLTYPE WebBrowser::MoveElementTo(
- __RPC__in_string const OLECHAR* pwcsName,
- __RPC__in_opt IStorage* pstgDest,
- __RPC__in_string const OLECHAR* pwcsNewName,
- DWORD grfFlags)
-{
- return E_NOTIMPL;
-}
-
-HRESULT STDMETHODCALLTYPE WebBrowser::Commit(
- DWORD grfCommitFlags)
-{
- return E_NOTIMPL;
-}
-
-HRESULT STDMETHODCALLTYPE WebBrowser::Revert(void)
-{
- return E_NOTIMPL;
-}
-
-HRESULT STDMETHODCALLTYPE WebBrowser::EnumElements(
- DWORD reserved1,
- void* reserved2,
- DWORD reserved3,
- IEnumSTATSTG** ppenum)
-{
- return E_NOTIMPL;
-}
-
-HRESULT STDMETHODCALLTYPE WebBrowser::DestroyElement(
- __RPC__in_string const OLECHAR* pwcsName)
-{
- return E_NOTIMPL;
-}
-
-HRESULT STDMETHODCALLTYPE WebBrowser::RenameElement(
- __RPC__in_string const OLECHAR* pwcsOldName,
- __RPC__in_string const OLECHAR* pwcsNewName)
-{
- return E_NOTIMPL;
-}
-
-HRESULT STDMETHODCALLTYPE WebBrowser::SetElementTimes(
- __RPC__in_opt_string const OLECHAR* pwcsName,
- __RPC__in_opt const FILETIME* pctime,
- __RPC__in_opt const FILETIME* patime,
- __RPC__in_opt const FILETIME* pmtime)
-{
- return E_NOTIMPL;
-}
-
-HRESULT STDMETHODCALLTYPE WebBrowser::SetClass(
- __RPC__in REFCLSID clsid)
-{
- return S_OK;
-}
-
-HRESULT STDMETHODCALLTYPE WebBrowser::SetStateBits(
- DWORD grfStateBits,
- DWORD grfMask)
-{
- return E_NOTIMPL;
-}
-
-HRESULT STDMETHODCALLTYPE WebBrowser::Stat(
- __RPC__out STATSTG* pstatstg,
- DWORD grfStatFlag)
-{
- return E_NOTIMPL;
-}
-
-
-extern "C" __declspec(dllexport) void* html_new( HWND parent) {
- auto web = new WebBrowser(parent);
- return web;
-}
-
-extern "C" __declspec(dllexport) void html_navigate(void* web, wchar_t* path) {
- auto w = static_cast(web);
- w->Navigate(path);
-}
-extern "C" __declspec(dllexport) void html_resize(void* web,int x,int y,int w, int h) {
- auto ww = static_cast(web);
- RECT r;
- r.left = x;
- r.top = y;
- r.right = x + w;
- r.bottom = y + h;
- ww->SetRect(r);
-}
-extern "C" __declspec(dllexport) void html_release(void* web) {
- delete web;
-}
\ No newline at end of file
diff --git a/plugins/winsharedutils/dllmain.cpp b/plugins/winsharedutils/dllmain.cpp
index a21ed7d0..7bffdf17 100644
--- a/plugins/winsharedutils/dllmain.cpp
+++ b/plugins/winsharedutils/dllmain.cpp
@@ -1,5 +1,4 @@
-// dllmain.cpp : 定义 DLL 应用程序的入口点。
-#include "pch.h"
+
#include"define.h"
BOOL APIENTRY DllMain( HMODULE hModule,
DWORD ul_reason_for_call,