Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DPI Problem in Win32/Windows 10 (blurry text) #571

Closed
kmeboe opened this issue Oct 23, 2020 · 3 comments
Closed

DPI Problem in Win32/Windows 10 (blurry text) #571

kmeboe opened this issue Oct 23, 2020 · 3 comments

Comments

@kmeboe
Copy link

kmeboe commented Oct 23, 2020

Out of the box, the sample code for webview2 creates blurry text on high-DPI monitors with scaling enabled on Windows 10.

To reproduce:

-Make sure you are on a high DPI monitor, and set scaling to 200%.
-Begin following the steps from here: https://docs.microsoft.com/en-us/microsoft-edge/webview2/gettingstarted/win32
-Run after Step 3.
-Bug: all text is blurry.

See the following picture. The left side is the sample app, and the right side is native Chromium Microsoft Edge.
image

Note that there are ways to fix this, such as adding the following line of code before the window creation:
SetThreadDpiAwarenessContext(DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE_V2);

But the problem is that this code isn't available if you're targeting older Windows versions. For our individual case, our MFC app supports Windows 7 and above (but even if we were starting with 8.1 we would still have the problem, as SetThreadDpiAwarenessContext and related monitor awareness isn't available until later versions of Windows 10). We are moving from CHtmlView (Internet Explorer) over to webview2. Unfortunately, CHtmlView looks better in high DPI cases (although it's not perfect).

While I would be okay with our app being a bit blurry on Windows 7 and 8, the way things stand right now, it's blurry on all the latest versions of Windows 10 as well. Is there a way for me to fix this on our app that has a WINVER that's older than Windows 10?

@champnic
Copy link
Member

Hey @kmeboe, please see DpiUtil.cpp in our sample app for examples of setting DPI awareness down to Win7:
https://github.com/MicrosoftEdge/WebView2Samples/blob/master/SampleApps/WebView2APISample/DpiUtil.cpp#L36

For example, you should be able to use SetProcessDpiAware on Win7. Let me know if that doesn't work for you, thanks!

@kmeboe
Copy link
Author

kmeboe commented Oct 26, 2020

Thanks for the quick response. The DpiUtil class seems like it handles everything perfectly!

The rest of our app isn't DPI-aware, so I'm going to have my work cut out for me. Although maybe I can use the GetProcAddress technique from DpiUtil.cpp to try and call SetThreadDpiAwarenessContext(), which may allow me to fix just the browser window without addressing the rest of my app (on Windows 10 machines, of course).

Either way, you've given me the tools to proceed. Thank you!

@techyrajeev
Copy link

@champnic how can I use this in WPF?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants