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

Webview locks after changing scale on a VSTO addin. #3163

Closed
Mark-IDB opened this issue Jan 26, 2023 · 4 comments
Closed

Webview locks after changing scale on a VSTO addin. #3163

Mark-IDB opened this issue Jan 26, 2023 · 4 comments
Assignees
Labels
bug Something isn't working tracked We are tracking this work internally.

Comments

@Mark-IDB
Copy link

Mark-IDB commented Jan 26, 2023

Description
In a VSTO project the webview locks the window after a display scaling change.
Most of the times the window can be closed but the webview content is not shown and sometimes even the mouse-cursor leaves a trail across the window.
This happens when a laptop user disconnects the external monitor(scaling 100%) and switches to his laptop monitor (scaling 125%)
The window with the webview must be opened before and it must be the main(!) monitor. This behaviour does not occur on a standalone executable and is reproducable in Outlook/Word/Excel.
Repro is in an c# Excel VSTO.

Version
SDK: 1.0.1518.46
Runtime: Evergreen (current 109.0.1518.61)
Framework: VSTO/WinForms
OS: Win10, Win11

Repro Steps

  • Open the included solution.
  • Start the project. Excel will be started.
  • Click on the WebView2Test ribbon and the Webview Label

image

  • The microsoft site wil be opened normally (check if the window is opened on your main monitor!)
    image

  • Close the window (do not keep it open!)

  • Change in the display settings the scale (up or down)

  • Open the window again

  • The content will now not be visible and the window locks (not allways) (screenshotting this is also not possible)

  • If you change the Left property (in frmWebview_Load to -1500 (if you have a monitor to the left of your main) so the window is opened on another monitor there will be no problem if you change the scale on that monitor. So the problem only occurs on the main monitor.

The webview window should be normally visible after changing the scale (through the interface or by disconnecting an external monitor)

Screenshots

Additional context
ExcelAddInWebView.zip

AB#43216643

@Mark-IDB Mark-IDB added the bug Something isn't working label Jan 26, 2023
@champnic
Copy link
Member

champnic commented Feb 1, 2023

Hey @Mark-IDB - can you see if this might be related to #3008? That seems to be cause by an app-compat setting that sets Office and WebView2 DPI mode to system aware which causes some problems. Additionally, please check the Office documentation on DPI support to see if there's something there that might help: https://learn.microsoft.com/en-us/office/client-developer/ddpi/handle-high-dpi-and-dpi-scaling-in-your-office-solution

Otherwise we can open a bug to track this issue.

@Mark-IDB
Copy link
Author

Mark-IDB commented Feb 2, 2023

Hello @champnic.
#3008 doesn't seem related because we don't get an exception and the e.IsSucces is true in the CoreWebView2InitializationCompleted event.
The DPI handling in the VSTO seems normal. We have other winform windows which can be opened after the scale change. If the Webview2 Window is created on a non-main monitor the scaling is is handled without a problem. Only on the main-monitor the problem occurs. Webview2 isn't locked completly, i still can close the window through the taskbar. But interacting with the webview2 control is impossible.

@champnic
Copy link
Member

champnic commented Feb 2, 2023

Thanks for the info - I've added this bug to our backlog to take a look. Sorry you're hitting this!

@champnic champnic added the tracked We are tracking this work internally. label Feb 2, 2023
@champnic
Copy link
Member

Hey @Mark-IDB - We think this might be a related to a bug in windows that disallows connecting HWNDs with differing DPIs in SystemAware mode. In this case what's happening is that the host (Excel) and WebView2 are both launched in SystemAware (Enhanced/Per-process) with, say, 100% DPI. When the WebView2 is closed and the scale changes to 150%, the DPI of Excel stays at 100% because it's SystemAware instead of Per-Monitor Aware. Then when the second WebView2 is launched it gets the updated DPI of 150% and then fails parenting to the Excel HWND because Excel is 100% and WebView2 is 150%.

The current workaround is to disable the per-process DPI of Excel (which is also inherited by the child WebView2 processes). If you want to try this out, this can be done with the following regkey:

[HKEY_CURRENT_USER\Software\Microsoft\Windows NT\CurrentVersion\AppCompatFlags\Layers]
"C:\\Program Files\\Microsoft Office\\root\\Office16\\EXCEL.EXE"="~ PERPROCESSSYSTEMDPIFORCEOFF"

If the path to Excel.exe is different in your machine you'll have to update to be the correct path.

We are working on a better fix here that we're tracking as part of #985. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working tracked We are tracking this work internally.
Projects
None yet
Development

No branches or pull requests

2 participants