views:

647

answers:

3
+2  Q: 

About DPI issue

I have a WIN32 SW which the UI was designed in 96 DPI, so when user changes the windows DPI from 96 to 120 or bigger, the UI will be wrong. I want to know if there is API to force my SW to display the UI with 96DPI.

+1  A: 

There is no API to force your app to show at 96DPI. The DPI is a device setting and cannot be controlled per application.

If you can change your program, you can scale your UI to look properly on high DPI though. You need to call GetDeviceCaps; more specificaly, you need to calculate the X and Y scale using the number returned for LOGPIXELSX and LOGPIXELSY. Something like this:

HDC hdc;
double m_dDPIScaleX = GetDeviceCaps(hdc, LOGPIXELSX) / 96.0;
double m_dDPIScaleY = GetDeviceCaps(hdc, LOGPIXELSY) / 96.0;
Franci Penov
+2  A: 

Starting with Windows Vista, scaling for DPI is supposed to happen automatically. I don't have any direct experience to know how well it works, but here's the page that explains how to turn it off:

http://msdn.microsoft.com/en-us/library/ms701681(VS.85).aspx

Mark Ransom
+1  A: 

You can also add an appcompat key for your application. The place for this in the registry is:

HKEY_CURRENT_USER\Software\Microsoft\Windows NT\CurrentVersion\AppCompatFlags\Layers

That is the per-user settings, there is the same key in HKEY_LOCAL_MACHINE, but of course that is a system setting and will require elevated privileges to write to. Adding a key like so:

"C:\path\to\app.exe"="HIGHDPIAWARE"

Will enable that compatibility flag for your program, which will turn off DPI scaling. This is for Vista+.

SetProcessDPIAware is also an option, but be aware there is a danger of a race condition, according to the documentation.

Factor Mystic