如何在PowerShell WinForm应用中完全禁用DPI缩放
PowerShell开发WinForm嵌套WPF控件时无法禁用DPI缩放的问题
我正在用PowerShell开发一款WinForm应用,通过ElementHost嵌套了部分WPF控件,目前始终无法完全禁用该WinForm窗口的Windows DPI缩放,尝试以下方法均未成功:
- 脚本顶部添加DPI感知检测与设置代码,执行后返回提示
Process is already DPI aware.,但未实现禁用缩放:
# Check if the process is already DPI aware if (-not ([System.Windows.Forms.Application]::DpiAwarenessContext -eq 'None')) { Write-Host "Process is already DPI aware." } else { # Define the Windows API function signature to set DPI awareness Add-Type @" using System; using System.Runtime.InteropServices; public class DPIAwareness { [DllImport("User32.dll")] public static extern bool SetProcessDPIAware(); } "@ # Set the process DPI awareness [DPIAwareness]::SetProcessDPIAware() Write-Host "Process DPI awareness set successfully." }
工作环境为双显示器(分别是100%和125% DPI),受GPO策略影响,仅通过兼容性设置开启“High DPI scaling override - System (Enhanced)”时应用显示正常,但将窗口拖拽到不同DPI显示器间时仍会自动缩放。我需要应用像Mozilla Firefox一样始终保持100% DPI,而非类似MS Edge随显示器切换缩放。
尝试使用从微软文档复制内容的
App.exe.manifest文件,执行以下代码后同样无效:
#Add the SendMessage function as a static method of a class Add-Type -ReferencedAssemblies $assemblies -TypeDefinition $code -Language CSharp # Set the path to your manifest XML file $manifestPath = Join-Path -Path $PSScriptRoot -ChildPath "PerkUI RemoteAppManager.exe.manifest" # Read the content of the manifest XML file $manifestContent = Get-Content -Path $manifestPath -Raw
内容的提问来源于stack exchange,提问作者user282262
相关产品推荐
相关产品推荐

