You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
put_ShouldDetectMonitorScaleChanges unable to block Windows DPI scale #3665
I think calling “controller3->put_ShouldDetectMonitorScaleChanges(FALSE)” should not have any scaling effects on WebView2 when switching Windows DPI Scale. However, in reality, even after calling this, switching Windows DPI Scale still affects WebView2 and causes scaling effects
Framework:Win32
Microsoft.Web.WebView2:1.0.1901.177
Microsoft.Windows.ImplementationLibrary:1.0.230629.1
System version:Win11 10.0.22621
menghuijinxi, can you be more specific about the scaling effects you are seeing? Calling ShouldDetectMonitorScaleChanges(FALSE) should prevent the WebView2 from changing the RasterizationScale property as a result of monitor DPI scale changes. It is the app's responsibility to update the RasterizationScale. But calling ShouldDetectMonitorScaleChanges(FALSE) does not change the scale of the WebView2.
So if you created WebView2 on a monitor with a scale of 1.25, WebView2 would set the RasterizationScale to 1.25. Calling ShouldDetectMonitorScaleChanges(FALSE) will prevent future monitor scale changes from impacting RasterizationScale, but it does not change the WebView2 RasterizationScale back to 1.0. If you want WebView2 to render at 100%, you need to also call put_RasterizationScale(1.0).
I now use “GetDpiForMonitor” to obtain the DPI of the Windows system, and then divide it by 96 to get the system’s scaling factor, assuming it is 1.25. Finally, by using 1/1.25=0.8 and invoking put_RasterizationScale(0.8), I can achieve the desired effect and solve this problem.
Activity
novac42 commentedon Jul 28, 2023
menghuijinxi Could you tell us the repro steps, what's the expected outcome vs actual results? Also may you share informartion about the environment:
menghuijinxi commentedon Jul 28, 2023
I think calling “controller3->put_ShouldDetectMonitorScaleChanges(FALSE)” should not have any scaling effects on WebView2 when switching Windows DPI Scale. However, in reality, even after calling this, switching Windows DPI Scale still affects WebView2 and causes scaling effects
Framework:Win32
Microsoft.Web.WebView2:1.0.1901.177
Microsoft.Windows.ImplementationLibrary:1.0.230629.1
System version:Win11 10.0.22621
menghuijinxi commentedon Jul 28, 2023
// code snippet
bradp0721 commentedon Aug 2, 2023
menghuijinxi, can you be more specific about the scaling effects you are seeing? Calling ShouldDetectMonitorScaleChanges(FALSE) should prevent the WebView2 from changing the RasterizationScale property as a result of monitor DPI scale changes. It is the app's responsibility to update the RasterizationScale. But calling ShouldDetectMonitorScaleChanges(FALSE) does not change the scale of the WebView2.
So if you created WebView2 on a monitor with a scale of 1.25, WebView2 would set the RasterizationScale to 1.25. Calling ShouldDetectMonitorScaleChanges(FALSE) will prevent future monitor scale changes from impacting RasterizationScale, but it does not change the WebView2 RasterizationScale back to 1.0. If you want WebView2 to render at 100%, you need to also call put_RasterizationScale(1.0).
menghuijinxi commentedon Aug 8, 2023
After your explanation, I understand the purpose of the ShouldDetectMonitorScaleChanges function, this function is not what I need.
menghuijinxi commentedon Aug 8, 2023
I now use “GetDpiForMonitor” to obtain the DPI of the Windows system, and then divide it by 96 to get the system’s scaling factor, assuming it is 1.25. Finally, by using 1/1.25=0.8 and invoking put_RasterizationScale(0.8), I can achieve the desired effect and solve this problem.