#include "define.h" #include #include #include #include #include using namespace Microsoft::WRL; #include #define CHECK_FAILURE(x) \ if (FAILED((x))) \ return x; DECLARE HRESULT put_PreferredColorScheme(void *m_host, COREWEBVIEW2_PREFERRED_COLOR_SCHEME scheme) { wil::com_ptr m_controller(reinterpret_cast(m_host)); wil::com_ptr coreWebView2; CHECK_FAILURE(m_controller->get_CoreWebView2(&coreWebView2)); auto webView2_13 = coreWebView2.try_query(); if (webView2_13) { wil::com_ptr profile; CHECK_FAILURE(webView2_13->get_Profile(&profile)); CHECK_FAILURE(profile->put_PreferredColorScheme(scheme)); } return S_FALSE; } DECLARE void *add_ZoomFactorChanged(void *m_host, void (*signal)(double)) { EventRegistrationToken *m_zoomFactorChangedToken = new EventRegistrationToken; // Register a handler for the ZoomFactorChanged event. // This handler just announces the new level of zoom on the window's title bar. reinterpret_cast(m_host)->add_ZoomFactorChanged( Callback( [signal](ICoreWebView2Controller *sender, IUnknown *args) -> HRESULT { double zoomFactor; sender->get_ZoomFactor(&zoomFactor); signal(zoomFactor); // std::wstring message = L"WebView2APISample (Zoom: " + // std::to_wstring(int(zoomFactor * 100)) + L"%)"; // SetWindowText(m_appWindow->GetMainWindow(), message.c_str()); return S_OK; }) .Get(), m_zoomFactorChangedToken); return m_zoomFactorChangedToken; } DECLARE void remove_ZoomFactorChanged(void *m_host, void *m_zoomFactorChangedToken) { reinterpret_cast(m_host)->remove_ZoomFactorChanged(*reinterpret_cast(m_zoomFactorChangedToken)); delete m_zoomFactorChangedToken; } DECLARE double get_ZoomFactor(void *m_host) { double zoomFactor; reinterpret_cast(m_host)->get_ZoomFactor(&zoomFactor); return zoomFactor; } DECLARE void put_ZoomFactor(void *m_host, double zoomFactor) { reinterpret_cast(m_host)->put_ZoomFactor(zoomFactor); }