title: Troubleshooting DPI Virtualization and DPI-aware applications, in Windows Vista and Windows 7
body: <p>I have a problem where an application (written in Delphi) is behaving properly at default 96 DPI settings on all systems, but is behaving inconsistently at the "150% text size" (internally 144 dpi) setting, on different systems.  It seems that on some systems, that certain text/font parts of my application are being stretched and on other systems, they aren't.  I would have thought that my application, on a certain version of Windows (Win7), at a certain DPI, should behave the same way.</p>
  
  <p>Either my application will make it known to Windows that it doesn't need the DPI Virtualization feature, or it will not.  That much I understand. What I don't understand is how DPI changes can cause different appearance on two machines, both running Windows 7, both at 144 dpi, displaying the same fonts and forms at the same fixed sizes.</p>
  
  <p>Is there some configuration-dependant elements involved in DPI Virtualization that I need to inspect in windows (registry etc)? Otherwise, how do you troubleshoot and know whether DPI virtualization is being done on your client window?  </p>
  
  <p>In Delphi, one has to set the TForm.Scaled property to false, if one doesn't want scaling. But what I don't understand is that when the main form's Scaled property is true, I cannot always predict the outcome.</p>
  
  <p>What is most perplexing to me in my application, is that I have a control that only misbehaves in my large real application, but which does not misbehave in a standalone app where I am trying to debug just the control. To understand the control behaviour in a standalone app I was forced to make a demo app where I force the DPI awareness in via the manifest file. Then I can reproduce the control drawing glitch, although in a different form.</p>
  
  <p>Here is the manifest file I use in my demo app, which exposes the problems that my controls have with dealing with high-dpi settings in windows.  However, one strange thing I have found is that it is possible for an application </p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8" standalone="yes"?&gt;
  &lt;assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0"&gt;
   &lt;asmv3:application xmlns:asmv3="urn:schemas-microsoft-com:asm.v3"&gt;
      &lt;asmv3:windowsSettings
           xmlns="http://schemas.microsoft.com/SMI/2005/WindowsSettings"&gt;
        &lt;dpiAware&gt;true&lt;/dpiAware&gt;
      &lt;/asmv3:windowsSettings&gt;
    &lt;/asmv3:application&gt;
    &lt;assemblyIdentity version="14.0.3615.26342" processorArchitecture="*"            
     name="TestProject" type="win32"&gt;&lt;/assemblyIdentity&gt;
    &lt;description&gt;High DPI Controls Test App&lt;/description&gt;
  &lt;/assembly&gt;
  </code></pre>
  
  <p>here's an example of one of about 30 places where the controls in my application are messed up when I disable DPI virtualization in my app. This particular glitch was solved by turning off the Scaled property in my form. But in other places, having TForm.Scaled=false causes the problem, whereas in some forms, it fixes it:</p>
  
  <p><img src="https://i.stack.imgur.com/02TUo.png" alt="DPI Glitch Example with a non-DPI-virtualized app manifest, but main form is Scaled"></p>
  
  <p>Update:  It turns out that some of my controls use GDI+ and that font behaviour in GDI+ contexts is different than font behaviour in normal GDI contexts, at least for certain third-party controls that use GDI+.   That's a major source of headaches.  Secondly, there is the spotty test coverage and poorly-defined requirements, for DPI awareness, in the VCL.  Some VCL controls are based on MS Common Controls, and while it's fair to say that the underlying common controls probably work fine in high-DPI situations, not all the VCL control wrappers can be guaranteed to work correctly. So, reviewing an application for high-DPI-awareness in all its controls, as well as correct behaviour in all available windows 7 themes:</p>
  
  <ol>
  <li>aero glass on, at 96dpi (Default Win7 appearance on most modern hardware)</li>
  <li>basic theme (aero glass off) but xp themes enabled</li>
  <li>classic win2000 look where glass is off, as well as xp level themes,  </li>
  <li>high contrast white </li>
  <li>high contrast black</li>
  <li>Various Other-than-96-DPI settings</li>
  </ol>
  
  <p>..and the list goes on., and you have a pretty heavy burden, as an application developer.  Whether you are a delphi user and use the VCL, or you are an MFC/ATL C++ developer, it seems to me, that supporting all of the various quirky windows modes is a burden almost too heavy to bear. So most people don't bother. Am I right?</p>