@@ -124,6 +124,12 @@ AppWindow::AppWindow(
124
124
0 , CW_USEDEFAULT, 0 , nullptr , nullptr , g_hInstance, nullptr );
125
125
}
126
126
127
+ m_appBackgroundImageHandle = (HBITMAP)LoadImage (
128
+ NULL , L" AppBackground.bmp" , IMAGE_BITMAP, 0 , 0 , LR_LOADFROMFILE);
129
+ GetObject (m_appBackgroundImageHandle, sizeof (m_appBackgroundImage), &m_appBackgroundImage);
130
+ m_memHdc = CreateCompatibleDC (GetDC (m_mainWindow));
131
+ SelectObject (m_memHdc, m_appBackgroundImageHandle);
132
+
127
133
SetWindowLongPtr (m_mainWindow, GWLP_USERDATA, (LONG_PTR)this );
128
134
129
135
#ifdef USE_WEBVIEW2_WIN10
@@ -260,7 +266,22 @@ bool AppWindow::HandleWindowMessage(
260
266
case WM_PAINT:
261
267
{
262
268
PAINTSTRUCT ps;
269
+ HDC hdc;
270
+ RECT mainWindowBounds;
271
+ RECT webViewBounds = {0 };
263
272
BeginPaint (hWnd, &ps);
273
+
274
+ hdc = GetDC (hWnd);
275
+ GetClientRect (hWnd, &mainWindowBounds);
276
+
277
+ if (auto viewComponent = GetComponent<ViewComponent>())
278
+ {
279
+ webViewBounds = viewComponent->GetBounds ();
280
+ }
281
+
282
+ StretchBlt (hdc, webViewBounds.left , webViewBounds.top , webViewBounds.right , webViewBounds.bottom ,
283
+ m_memHdc, 0 , 0 , m_appBackgroundImage.bmWidth , m_appBackgroundImage.bmHeight , SRCCOPY);
284
+
264
285
EndPaint (hWnd, &ps);
265
286
return true ;
266
287
}
@@ -282,6 +303,8 @@ bool AppWindow::HandleWindowMessage(
282
303
{
283
304
PostQuitMessage (retValue);
284
305
}
306
+ DeleteObject (m_appBackgroundImageHandle);
307
+ DeleteDC (m_memHdc);
285
308
}
286
309
break ;
287
310
// ! [RestartManager]
@@ -630,23 +653,23 @@ HRESULT AppWindow::OnCreateEnvironmentCompleted(
630
653
CHECK_FAILURE (result);
631
654
m_webViewEnvironment = environment;
632
655
633
- auto webViewExperimentalEnvironment =
634
- m_webViewEnvironment.try_query <ICoreWebView2ExperimentalEnvironment >();
656
+ auto webViewEnvironment3 =
657
+ m_webViewEnvironment.try_query <ICoreWebView2Environment3 >();
635
658
#ifdef USE_WEBVIEW2_WIN10
636
- if (webViewExperimentalEnvironment && (m_dcompDevice || m_wincompCompositor))
659
+ if (webViewEnvironment3 && (m_dcompDevice || m_wincompCompositor))
637
660
#else
638
- if (webViewExperimentalEnvironment && m_dcompDevice)
661
+ if (webViewEnvironment3 && m_dcompDevice)
639
662
#endif
640
663
{
641
- CHECK_FAILURE (webViewExperimentalEnvironment ->CreateCoreWebView2CompositionController (
664
+ CHECK_FAILURE (webViewEnvironment3 ->CreateCoreWebView2CompositionController (
642
665
m_mainWindow,
643
666
Callback<
644
- ICoreWebView2ExperimentalCreateCoreWebView2CompositionControllerCompletedHandler >(
667
+ ICoreWebView2CreateCoreWebView2CompositionControllerCompletedHandler >(
645
668
[this ](
646
669
HRESULT result,
647
- ICoreWebView2ExperimentalCompositionController * compositionController) -> HRESULT {
670
+ ICoreWebView2CompositionController * compositionController) -> HRESULT {
648
671
auto controller =
649
- wil::com_ptr<ICoreWebView2ExperimentalCompositionController >(compositionController)
672
+ wil::com_ptr<ICoreWebView2CompositionController >(compositionController)
650
673
.query <ICoreWebView2Controller>();
651
674
return OnCreateCoreWebView2ControllerCompleted (result, controller.get ());
652
675
})
@@ -693,13 +716,16 @@ HRESULT AppWindow::OnCreateCoreWebView2ControllerCompleted(HRESULT result, ICore
693
716
m_creationModeId == IDM_CREATION_MODE_TARGET_DCOMP);
694
717
NewComponent<ControlComponent>(this , &m_toolbar);
695
718
696
- wil::com_ptr<ICoreWebView2Experimental2> webview2;
697
- webview2 = coreWebView2.query <ICoreWebView2Experimental2>();
698
- // ! [AddVirtualHostNameToFolderMapping]
699
- // Setup host resource mapping for local files.
700
- webview2->SetVirtualHostNameToFolderMapping (
701
- L" appassets.example" , L" assets" , COREWEBVIEW2_HOST_RESOURCE_ACCESS_KIND_DENY_CORS);
702
- // ! [AddVirtualHostNameToFolderMapping]
719
+ m_webView3 = coreWebView2.query <ICoreWebView2_3>();
720
+ if (m_webView3)
721
+ {
722
+ // ! [AddVirtualHostNameToFolderMapping]
723
+ // Setup host resource mapping for local files.
724
+ m_webView3->SetVirtualHostNameToFolderMapping (
725
+ L" appassets.example" , L" assets" ,
726
+ COREWEBVIEW2_HOST_RESOURCE_ACCESS_KIND_DENY_CORS);
727
+ // ! [AddVirtualHostNameToFolderMapping]
728
+ }
703
729
704
730
// We have a few of our own event handlers to register here as well
705
731
RegisterEventHandlers ();
@@ -1096,10 +1122,24 @@ std::wstring AppWindow::GetLocalPath(std::wstring relativePath, bool keep_exe_pa
1096
1122
}
1097
1123
std::wstring AppWindow::GetLocalUri (std::wstring relativePath)
1098
1124
{
1099
- // ! [LocalUrlUsage]
1100
- const std::wstring localFileRootUrl = L" https://appassets.example/" ;
1101
- return localFileRootUrl + regex_replace (relativePath, std::wregex (L" \\\\ " ), L" /" );
1102
- // ! [LocalUrlUsage]
1125
+ if (m_webView3)
1126
+ {
1127
+ // ! [LocalUrlUsage]
1128
+ const std::wstring localFileRootUrl = L" https://appassets.example/" ;
1129
+ return localFileRootUrl + regex_replace (relativePath, std::wregex (L" \\\\ " ), L" /" );
1130
+ // ! [LocalUrlUsage]
1131
+ }
1132
+ else
1133
+ {
1134
+ std::wstring path = GetLocalPath (L" assets\\ " + relativePath, false );
1135
+
1136
+ wil::com_ptr<IUri> uri;
1137
+ CHECK_FAILURE (CreateUri (path.c_str (), Uri_CREATE_ALLOW_IMPLICIT_FILE_SCHEME, 0 , &uri));
1138
+
1139
+ wil::unique_bstr uriBstr;
1140
+ CHECK_FAILURE (uri->GetAbsoluteUri (&uriBstr));
1141
+ return std::wstring (uriBstr.get ());
1142
+ }
1103
1143
}
1104
1144
1105
1145
void AppWindow::RunAsync (std::function<void ()> callback)
0 commit comments