2017/04/09

WPFのPer-Monitor DPIサポート(その4)

完結編。


Windows 10 Creators Updateがリリースされましたが、Windows 8.1から3年経過して、なぜか分かりませんがMicrosoftがようやくデスクトップアプリのPer-Monitor DPI対応に力を入れてきています。今更WinFormsまで対応してくるとは予想外でした。
新APIの追加など色々ありますが、WPFの場合は特別なことをしていない限り、関係するのはマニフェストへのPerMonitorV2の追加だけです。
<application xmlns="urn:schemas-microsoft-com:asm.v3">
<windowsSettings>
<!-- Per Monitor V1 [OS >= Windows 8.1]
Values: False, True, Per-monitor, True/PM -->
<dpiAware xmlns="http://schemas.microsoft.com/SMI/2005/WindowsSettings">
true/PM</dpiAware>
<!-- Per Monitor V1 [OS >= Windows 10 Anniversary Update (1607, 10.0.14393, Redstone 1)]
Values: Unaware, System, PerMonitor -->
<!-- Per Monitor V2 [OS >= Windows 10 Creators Update (1703, 10.0.15063, Redstone 2)]
Value: PerMonitorV2 -->
<dpiAwareness xmlns="http://schemas.microsoft.com/SMI/2016/WindowsSettings">
PerMonitorV2, PerMonitor</dpiAwareness>
</windowsSettings>
</application>
これでWPFでも、例のNon-client areaのスケーリングが自動的にかかるようになります(Creators Update上では。なお、この例はAnniversary Updateより前の対応は自前でやる前提のもの)。

これによって、WPFのPer-Monitor DPI対応はひとまず完成ということで、何か特別なことをしない限りマニフェストに書くだけです。まあUIを作っていると、その何か特別なことが往々にして必要になりますが。