Question

In my case, No matter how user change win7 dpi setting,I can always get the correct screen resolution via code PrimaryScreen.Bounds,just as same as what set in the control-panel-display on system of win7.

But in my colleague's computer, I run the same code just after setting his os's dpi from 100% to 150%. I get a relative bounds result.

For example, his screen resolution is 1920 * 1080 now, I ran the code after I had set his os dpi from 100% to 150%. Finally I get the resolution is 1280 * 720 by the code PrimaryScreen.Bounds. Why this?

I did this in the same way, but I got a same resolution.

Was it helpful?

Solution

This is by design. Windows has supported changing the video adapter's DPI (dots-per-inch) setting to 96 dpi (100%) and 120 dpi (125%) for a long time. At least since XP, possibly before that. So applications are expected to know how to deal with this.

Starting at Vista, Windows now supports arbitrary DPI settings. When you go past 120 dpi, Windows takes over the job of scaling the output of your program. A feature of Aero, it lies to the app about the DPI setting and lets the app render its window content into a memory buffer. It then rescales that buffer content before it draws it to the screen.

This is an important app-compat feature, it allows old programs to still be functional on a modern machine and avoids their window from turning into an unusable postage stamp. The result is not entirely flawless, you do see the quality of text in particular being less than stellar.

The Aero lie isn't just about the DPI setting, it also lies about the screen size. Necessary to prevent the app from creating a window that is too large and won't fit the screen anymore after it is rescaled. Which is why you got 1280 x 720.

To turn off the lie, you have to tell Aero that you do support higher DPI settings, even though your program is marked to still be compatible with old Windows versions. This answer shows you how to edit the manifest of your program to add the <dpiAware> element.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top