Skip to content

Commit

Permalink
Add MessageBox when runtime not installed
Browse files Browse the repository at this point in the history
  • Loading branch information
rgwood committed Jan 31, 2022
1 parent 103db96 commit a9a59c2
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 6 deletions.
2 changes: 1 addition & 1 deletion MinimalWebView.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<OutputType>WinExe</OutputType>
<TargetFramework>net6.0-windows</TargetFramework>
<ApplicationManifest>app.manifest</ApplicationManifest>
<Version>0.4.2</Version>
<Version>0.4.3</Version>
<ImplicitUsings>true</ImplicitUsings>
</PropertyGroup>

Expand Down
4 changes: 3 additions & 1 deletion NativeMethods.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,6 @@ WM_SIZE
WM_CLOSE
WM_USER

AllocConsole
AllocConsole

MessageBox
23 changes: 19 additions & 4 deletions Program.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using Microsoft.Web.WebView2.Core;
using System.Drawing;
using System.Drawing;
using System.Reflection;
using Microsoft.Web.WebView2.Core;
using Windows.Win32;
using Windows.Win32.Foundation;
using Windows.Win32.Graphics.Gdi;
Expand Down Expand Up @@ -112,8 +112,23 @@ private static void OnSize(HWND hwnd, WPARAM wParam, int width, int height)
private static async void CreateCoreWebView2(HWND hwnd)
{
Console.WriteLine("Initializing WebView2...");
var environment = await CoreWebView2Environment.CreateAsync(null, null, null);
_controller = await environment.CreateCoreWebView2ControllerAsync(hwnd);

try
{
var environment = await CoreWebView2Environment.CreateAsync(null, null, null);
_controller = await environment.CreateCoreWebView2ControllerAsync(hwnd);
}
catch (WebView2RuntimeNotFoundException)
{
var result = PInvoke.MessageBox(hwnd, "WebView2 runtime not installed.", "Error", MESSAGEBOX_STYLE.MB_OK | MESSAGEBOX_STYLE.MB_ICONERROR);

if (result == MESSAGEBOX_RESULT.IDYES)
{
//TODO: download WV2 bootstrapper from https://go.microsoft.com/fwlink/p/?LinkId=2124703 and run it
}

throw;
}
Console.WriteLine("WebView2 initialization finished.");

_controller.DefaultBackgroundColor = Color.Transparent; // avoids flash of white when page first renders
Expand Down

0 comments on commit a9a59c2

Please sign in to comment.