I found a WPF app which declares itself Per-Monitor DPI aware in the application manifest runs as System DPI aware when it is executed in Visual Studio 2013 (both debug and release). The app runs as Per-Monitor DPI aware when stand alone. I created an app which has exactly the same code in Visual Studio 2012 Express for Windows Desktop and in that case, it runs as Per-Monitor DPI aware even in Visual Studio.
So I think something in Visual Studio 2013 prevents the app from running as Per-Monitor DPI aware. Does anyone has a clue or suggestion?
The code behind of test app is as follows:
using System;
using System.Runtime.InteropServices;
using System.Windows;
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}
protected override void OnSourceInitialized(EventArgs e)
{
base.OnSourceInitialized(e);
var awareness = GetDpiAwareness();
if (awareness.HasValue)
this.Title = awareness.Value.ToString();
}
private PROCESS_DPI_AWARENESS? GetDpiAwareness()
{
var ver = Environment.OSVersion.Version;
if (!((6 == ver.Major && 3 <= ver.Minor) || (7 <= ver.Major)))
return null;
PROCESS_DPI_AWARENESS value;
var result = GetProcessDpiAwareness(IntPtr.Zero, out value);
if (result != 0)
return null;
return value;
}
[DllImport("Shcore.dll")]
private static extern int GetProcessDpiAwareness(IntPtr hprocess, out PROCESS_DPI_AWARENESS value);
private enum PROCESS_DPI_AWARENESS
{
Process_DPI_Unaware = 0,
Process_System_DPI_Aware = 1,
Process_Per_Monitor_DPI_Aware = 2
}
}
and the application manifest is as follows:
<?xml version="1.0" encoding="utf-8"?>
<asmv1:assembly manifestVersion="1.0" xmlns="urn:schemas-microsoft-com:asm.v1" xmlns:asmv1="urn:schemas-microsoft-com:asm.v1" xmlns:asmv2="urn:schemas-microsoft-com:asm.v2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<assemblyIdentity version="1.0.0.0" name="MyApplication.app"/>
<trustInfo xmlns="urn:schemas-microsoft-com:asm.v2">
<security>
<requestedPrivileges xmlns="urn:schemas-microsoft-com:asm.v3">
<requestedExecutionLevel level="asInvoker" uiAccess="false" />
</requestedPrivileges>
</security>
</trustInfo>
<compatibility xmlns="urn:schemas-microsoft-com:compatibility.v1">
<application>
<supportedOS Id="{1f676c76-80e1-4239-95bb-83d0f6d0da78}"/>
</application>
</compatibility>
<asmv3:application xmlns:asmv3="urn:schemas-microsoft-com:asm.v3">
<asmv3:windowsSettings
xmlns="http://schemas.microsoft.com/SMI/2005/WindowsSettings">
<dpiAware>True/PM</dpiAware>
</asmv3:windowsSettings>
</asmv3:application>
</asmv1:assembly>