Popular blog tags

Creating a WebView2 component with MFC c++

Published

https://mariusbancila.ro/blog/2020/01/29/using-microsoft-edge-in-a-native-windows-desktop-app-part-2/

 

WebView2Browser

A c++ web browser built with the Microsoft Edge WebView2 control.

step 1: fork from

https://github.com/MicrosoftEdge/WebView2Browser

 

step 2:change webview2 the user data folder

see:https://github.com/iaspnetcore/WebView2BrowserAppCplusplus/commit/317e687c80d349465db032eac2441e7298e34927

BOOL BrowserWindow::InitInstance(HINSTANCE hInstance, int nCmdShow) 
{
//L"C:\\Users\\Administrator2\\AppData\\Roaming\\Microsoft\\WebView2Browser"
    std::wstring userDataDirectory = GetAppDataDirectory();

 userDataDirectory.append(L"\\User Data2");

    // Create WebView environment for web content requested by the user. All
    // tabs will be created from this environment and kept isolated from the
    // browser UI. This enviroment is created first so the UI can request new
    // tabs when it's ready.
    HRESULT hr = CreateCoreWebView2EnvironmentWithOptions(nullptr, userDataDirectory.c_str(),
        nullptr, Callback<ICoreWebView2CreateCoreWebView2EnvironmentCompletedHandler>(
            [this](HRESULT result, ICoreWebView2Environment* env) -> HRESULT
    {
        RETURN_IF_FAILED(result);

        m_contentEnv = env;
        HRESULT hr = InitUIWebViews();

        if (!SUCCEEDED(hr))
        {
            OutputDebugString(L"UI WebViews environment creation failed\n");
        }

        return hr;
    }).Get());

    if (!SUCCEEDED(hr))
    {
        OutputDebugString(L"Content WebViews environment creation failed\n");
        return FALSE;
    }

    return TRUE;
}

 

HRESULT hresult = m_webView2->Navigate
                             (L"https://ayushshyam.wixsite.com/perdesijaat");

        if (hresult == S_OK)
        {
            TRACE("Web Page Opened Successfully");
            ResizeEverything();
        }

 

Get started with WebView2 in Win32 apps (c++)

https://docs.microsoft.com/en-us/microsoft-edge/webview2/get-started/win32

 

WebView2 Edge Browser step by step in MFC C++ Application

https://www.codeproject.com/Tips/5287858/WebView2-Edge-Browser-in-MFC-Cplusplus-Application

 

Establish the communication between WebView2 and JavaScript by which you can send and receive the message via WebView2

https://www.codeproject.com/Articles/5295819/Send-and-Receive-Message-through-WebView2-to-from