DPI Virtualization in Windows
Windows Vista (and subsequently, Windows 7 & 8) introduced a new feature called DPI Virtualization.
DPI Virtualization means Windows will automatically “resize” your forms and form objects for you, with no coding or resizing required on your part.
Sounds great, doesn’t it? Well, not quite. Remember my “ugly” form in an earlier post, running at 144dpi? It was DPI Virtualized by Windows 7, and the result was a blurry window.
DPI Virtualization also requires the code listing from a previous post to fail, every time. Why? Because when the code asks Windows, “Hey, what’s the current setting?”, Windows Vista, 7 and 8 will always answer “your font factor is 1” (no resizing required) if the user has selected to use DPI Virtualization.
“Whoa, whoa, whoa, Kevin! If the user has selected DPI Virtualization?”
Yes. Windows Vista, 7 and 8 have two different modes of DPI scaling: XP Style, and DPI Virtualization.
If the user changes her DPI setting, and checks the “Use Windows XP style DPI scaling” checkbox, Windows Vista, 7 and 8 will return the expected (truthful) result from the previous code listing – just like XP did.
So, a DPI of 144dpi (150%) with this box unchecked, results in the following:
And, just like I would do with the XP result from earlier, I would want to resize my forms and form objects, making them 50% larger than “normal.”
But if the user has not checked the box, here’s what Windows tells me about the “font factor” (notice the messagebox is also a bit blurry):
Great. The user has selected 144dpi, but my app does not know this because Windows has said, “Don’t worry, no need to resize anything. All is good.”
And my user gets to see “somewhat” resized, yet blurry, forms in my app.
What we need is a “Windows Lie Detector” to make sure Windows stops lying to us.
How do we do this?
We need to tell Windows that the app is “DPI Aware”.
And that’s exactly what we’ll look at in tomorrow’s post.
Related Links (With much better explanations)
High DPI Settings In Windows
Fixing Windows Programming