Skip to content

Commit a83baa5

Browse files
authored
Move projects to use latest WebView2 SDK 0.9.579-prerelease (#46)
* Updated testing instructions and added missing images * Move win32 sample to use latest WebView2 prerelease SDK 0.9.579 * Move wpf sample to use latest WebView2 prerelease SDK 0.9.579 * Updated .gitignore * Move winforms sample to use latest WebView2 prerelease SDK 0.9.579 * Added VSCode debugging setup * Added screenshots that should be included in the previous commit * Improved script debugging attach and removed targeted * Moved WPF to use 0.9.579-prerelease
1 parent abd2b9b commit a83baa5

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+1090
-444
lines changed

.gitignore

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,14 @@
44
packages/
55

66
*.csproj.user
7-
*.vcxproj.user
7+
*.vcxproj.user
8+
9+
Debug/
10+
Release/
11+
x64/
12+
x86/
13+
Win32/
14+
ARM64/
15+
16+
bin/
17+
obj/

GettingStartedGuides/.gitignore

Lines changed: 0 additions & 9 deletions
This file was deleted.
Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
<Project Sdk="Microsoft.NET.Sdk.WindowsDesktop">
2-
3-
<PropertyGroup>
4-
<OutputType>WinExe</OutputType>
5-
<TargetFramework>netcoreapp3.1</TargetFramework>
6-
<UseWPF>true</UseWPF>
7-
</PropertyGroup>
8-
9-
<ItemGroup>
10-
<PackageReference Include="Microsoft.Web.WebView2" Version="0.9.538-prerelease" />
11-
</ItemGroup>
12-
1+
<Project Sdk="Microsoft.NET.Sdk.WindowsDesktop">
2+
3+
<PropertyGroup>
4+
<OutputType>WinExe</OutputType>
5+
<TargetFramework>netcoreapp3.1</TargetFramework>
6+
<UseWPF>true</UseWPF>
7+
</PropertyGroup>
8+
9+
<ItemGroup>
10+
<PackageReference Include="Microsoft.Web.WebView2" Version="0.9.579-prerelease" />
11+
</ItemGroup>
12+
1313
</Project>

SampleApps/WebView2APISample/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ packages/
1515
!*.sln
1616
!*.vcxproj
1717
!*.vcxproj.filters
18+
!*.props
1819

1920
# Ignore the binary generated version of the resource (.rc) file
2021
*.aps

SampleApps/WebView2APISample/App.cpp

Lines changed: 47 additions & 91 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,13 @@
77
#include "App.h"
88

99
#include <map>
10+
#include <shellapi.h>
1011
#include <shellscalingapi.h>
1112
#include <shobjidl.h>
1213
#include <string.h>
1314
#include <vector>
1415
#include "AppWindow.h"
16+
#include "DpiUtil.h"
1517

1618
HINSTANCE g_hInstance;
1719
int g_nCmdShow;
@@ -22,6 +24,9 @@ static int RunMessagePump();
2224
static DWORD WINAPI ThreadProc(void* pvParam);
2325
static void WaitForOtherThreads();
2426

27+
#define NEXT_PARAM_CONTAINS(command) \
28+
_wcsnicmp(nextParam.c_str(), command, ARRAYSIZE(command) - 1) == 0
29+
2530
int APIENTRY wWinMain(HINSTANCE hInstance,
2631
HINSTANCE hPrevInstance,
2732
PWSTR lpCmdLine,
@@ -35,130 +40,80 @@ int APIENTRY wWinMain(HINSTANCE hInstance,
3540
// override this.
3641
DPI_AWARENESS_CONTEXT dpiAwarenessContext =
3742
DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE_V2;
38-
// Same but for older OS versions that don't support per-monitor v2
39-
PROCESS_DPI_AWARENESS oldDpiAwareness = PROCESS_PER_MONITOR_DPI_AWARE;
4043
std::wstring appId(L"EBWebView.SampleApp");
4144
std::wstring initialUri(L"https://www.bing.com");
45+
DWORD creationModeId = IDM_CREATION_MODE_WINDOWED;
46+
4247
if (lpCmdLine && lpCmdLine[0])
4348
{
44-
bool commandLineError = false;
45-
46-
PWSTR nextParam = lpCmdLine;
47-
48-
if (nextParam[0] == L'-')
49+
int paramCount = 0;
50+
LPWSTR* params = CommandLineToArgvW(lpCmdLine, &paramCount);
51+
for (int i = 0; i < paramCount; ++i)
4952
{
50-
++nextParam;
51-
if (nextParam[0] == L'-')
53+
std::wstring nextParam;
54+
if (params[i][0] == L'-')
5255
{
53-
++nextParam;
56+
if (params[i][1] == L'-')
57+
{
58+
nextParam.assign(params[i] + 2);
59+
}
60+
else
61+
{
62+
nextParam.assign(params[i] + 1);
63+
}
5464
}
55-
if (_wcsnicmp(nextParam, L"dpiunaware", ARRAYSIZE(L"dpiunaware") - 1) ==
56-
0)
65+
if (NEXT_PARAM_CONTAINS(L"dpiunaware"))
5766
{
5867
dpiAwarenessContext = DPI_AWARENESS_CONTEXT_UNAWARE;
59-
oldDpiAwareness = PROCESS_DPI_UNAWARE;
6068
}
61-
else if (_wcsnicmp(nextParam, L"dpisystemaware",
62-
ARRAYSIZE(L"dpisystemaware") - 1) == 0)
69+
else if (NEXT_PARAM_CONTAINS(L"dpisystemaware"))
6370
{
6471
dpiAwarenessContext = DPI_AWARENESS_CONTEXT_SYSTEM_AWARE;
65-
oldDpiAwareness = PROCESS_SYSTEM_DPI_AWARE;
6672
}
67-
else if (_wcsnicmp(nextParam, L"dpipermonitorawarev2",
68-
ARRAYSIZE(L"dpipermonitorawarev2") - 1) == 0)
73+
else if (NEXT_PARAM_CONTAINS(L"dpipermonitorawarev2"))
6974
{
7075
dpiAwarenessContext = DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE_V2;
71-
oldDpiAwareness = PROCESS_PER_MONITOR_DPI_AWARE;
7276
}
73-
else if (_wcsnicmp(nextParam, L"dpipermonitoraware",
74-
ARRAYSIZE(L"dpipermonitoraware") - 1) == 0)
77+
else if (NEXT_PARAM_CONTAINS(L"dpipermonitoraware"))
7578
{
7679
dpiAwarenessContext = DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE;
77-
oldDpiAwareness = PROCESS_PER_MONITOR_DPI_AWARE;
7880
}
79-
else if (_wcsnicmp(nextParam, L"noinitialnavigation",
80-
ARRAYSIZE(L"noinitialnavigation") - 1) == 0)
81+
else if (NEXT_PARAM_CONTAINS(L"noinitialnavigation"))
8182
{
8283
initialUri = L"";
8384
}
84-
else if (_wcsnicmp(nextParam, L"appid=",
85-
ARRAYSIZE(L"appid=") - 1) == 0)
85+
else if (NEXT_PARAM_CONTAINS(L"appid="))
8686
{
87-
PWSTR appidStart = nextParam + ARRAYSIZE(L"appid=");
88-
size_t len = 0;
89-
while (appidStart[len] && (appidStart[len] != ' '))
90-
++len;
91-
appId = std::wstring(appidStart, len);
87+
appId = nextParam.substr(nextParam.find(L'=') + 1);
9288
}
93-
else if (_wcsnicmp(nextParam, L"initialUri=",
94-
ARRAYSIZE(L"initialUri=") - 1) == 0)
89+
else if (NEXT_PARAM_CONTAINS(L"initialUri="))
9590
{
96-
PWSTR uriStart = nextParam + ARRAYSIZE(L"initialUri=") - 1;
97-
size_t len = 0;
98-
while (uriStart[len] && (uriStart[len] != ' '))
99-
++len;
100-
initialUri = std::wstring(uriStart, len);
91+
initialUri = nextParam.substr(nextParam.find(L'=') + 1);
10192
}
102-
else
93+
else if (NEXT_PARAM_CONTAINS(L"creationmode="))
10394
{
104-
// --edge-webview-switches is a supported switch to pass additional
105-
// command line switches to WebView's browser process.
106-
// For example, adding
107-
// --edge-webview-switches="--remote-debugging-port=9222"
108-
// enables remote debugging for webview.
109-
// And adding
110-
// --edge-webview-switches="--auto-open-devtools-for-tabs"
111-
// causes dev tools to open automatically for the WebView.
112-
commandLineError =
113-
(wcsncmp(nextParam, L"edge-webview-switches",
114-
ARRAYSIZE(L"edge-webview-switches") - 1) != 0) &&
115-
(wcsncmp(nextParam, L"restore",
116-
ARRAYSIZE(L"restore") - 1) != 0);
95+
nextParam = nextParam.substr(nextParam.find(L'=') + 1);
96+
if (NEXT_PARAM_CONTAINS(L"windowed"))
97+
{
98+
creationModeId = IDM_CREATION_MODE_WINDOWED;
99+
}
100+
else if (NEXT_PARAM_CONTAINS(L"visualdcomp"))
101+
{
102+
creationModeId = IDM_CREATION_MODE_VISUAL_DCOMP;
103+
}
104+
else if (NEXT_PARAM_CONTAINS(L"visualwincomp"))
105+
{
106+
creationModeId = IDM_CREATION_MODE_VISUAL_WINCOMP;
107+
}
117108
}
118109
}
119-
else
120-
{
121-
commandLineError = true;
122-
}
123-
124-
if (commandLineError)
125-
{
126-
MessageBox(nullptr,
127-
L"Valid command line "
128-
L"parameters:\n\t-DPIUnaware\n\t-DPISystemAware\n\t-"
129-
L"DPIPerMonitorAware\n\t-DPIPerMonitorAwareV2",
130-
L"Command Line Parameters", MB_OK);
131-
}
110+
LocalFree(params);
132111
}
133-
134112
SetCurrentProcessExplicitAppUserModelID(appId.c_str());
135113

136-
// Call the latest DPI awareness function possible
137-
HMODULE user32 = LoadLibraryA("User32.dll");
138-
auto func = reinterpret_cast<decltype(&SetProcessDpiAwarenessContext)>(
139-
GetProcAddress(user32, "SetProcessDpiAwarenessContext"));
140-
if (func)
141-
{
142-
// Windows 10 1703+: SetProcessDpiAwarenessContext
143-
func(dpiAwarenessContext);
144-
}
145-
else {
146-
HMODULE shcore = LoadLibraryA("Shcore.dll");
147-
auto func = reinterpret_cast<decltype(&SetProcessDpiAwareness)>(
148-
GetProcAddress(shcore, "SetProcessDpiAwareness"));
149-
if (func)
150-
{
151-
// Windows 8.1+: SetProcessDpiAwareness
152-
func(oldDpiAwareness);
153-
}
154-
else if (dpiAwarenessContext != DPI_AWARENESS_CONTEXT_UNAWARE)
155-
{
156-
// Windows 7+: SetProcessDPIAware
157-
SetProcessDPIAware();
158-
}
159-
}
114+
DpiUtil::SetProcessDpiAwarenessContext(dpiAwarenessContext);
160115

161-
new AppWindow(IDM_CREATION_MODE_WINDOWED, initialUri);
116+
new AppWindow(creationModeId, initialUri);
162117

163118
int retVal = RunMessagePump();
164119

@@ -215,6 +170,7 @@ void CreateNewThread(UINT creationModeId)
215170
STACK_SIZE_PARAM_IS_A_RESERVATION, &threadId);
216171
s_threads.insert(std::pair<DWORD, HANDLE>(threadId, thread));
217172
}
173+
218174
// This function is the starting point for new threads. It will open a new app window.
219175
static DWORD WINAPI ThreadProc(void* pvParam)
220176
{

0 commit comments

Comments
 (0)