Micro-ISV.asia

Thursday, 16 September 2010

High DPI Support in Windows Vista and 7

Filed under: Programming — Jan Goyvaerts @ 9:35

The screen on the recently released iPhone 4 has twice the resolution or four times the number of pixels than all preceding models. The new resolution is about 300 DPI, which is the resolution at which the human eye can no longer see the individual pixels. By comparison, most desktop monitors are around 96 DPI.

When an app for an older iPhone is run on the iPhone 4, the app doesn’t know the resolution has changed. The iPhone automatically scales the app by 200% so it fills the screen of the new iPhone, without requiring the app to be updated. New apps that indicate they support the iPhone 4 don’t get the automatic scaling, so they can draw themselves at the full resolution on the new screen.

I don’t have an iPhone and don’t write software for it. But when I heard the announcement I thought this was a really clever solution. I wondered why Windows couldn’t do the same so we can finally enjoy high resolution screens on our desktops. New applications could specify in their manifest that they support high resolution screens. Old applications that don’t have such a manifest and don’t know how to scale themselves would be automatically scaled by Windows. That way new applications would look great on new high resolution monitors while old applications would still be perfectly usable.

I did some digging and found out that this is exactly what Microsoft implemented. The new “high DPI” system was introduced with Windows Vista. It was further improved in Windows 7. While Windows Vista requires a reboot after a DPI change, Windows 7 only requires you to log off and log on again. To change the DPI setting in Windows 7, right-click on the desktop. In the context menu select Personalize. In the lower left corner of the personalization window, click Display.

This screen shot shows a Delphi XE application running on Windows 7. The display settings are set to 800 by 600. Scaling is 100% which means the normal 96 DPI that Windows applications have used for decades. (Old VGA and “super VGA” monitors had resolutions around 70 to 80 DPI, but Windows has always pretended that all displays have 96 DPI.)

Windows 7 at 96 DPI

The next screen shot shows the same Delphi XE application and a second application. Scaling is 150% or 144 DPI. Form1 thinks it is running at 96 DPI and looks blurry. Form2 knows it is running at 144 DPI and looks sharp.

Windows 7 at 144 DPI

If we set custom scaling to 200%, the difference is even more dramatic. Be careful with
using high DPI on small screen sizes as I did here. Nothing really fits on the screen any more.

Windows 7 at 192 DPI

The difference between the two Delphi XE applications is that for the second application, I turned off “enable runtime themes” in the Application section in Project Options. This tells Delphi not to add a manifest to the application, so we can add our own. Then I typed {$R PowerGREP4Manifest.res} into the source code to tell Delphi to link in the resource file that contains the manifest for PowerGREP 4. PowerGREP 4 is the first Just Great Software application that supports high DPI environmens. The true tag at the bottom is what tells Windows Vista and Windows 7 that PowerGREP 4 is capable of nicely scaling itself, so Windows doesn’t have to do it on PowerGREP’s behalf.

You can add this manifest to your own applications if you change the description tag at the top. But make sure to actually test your application on a high DPI system. Make sure that everything scales nicely.

No Comments

No comments yet.

Sorry, the comment form is closed at this time.