Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 503
Yigang Wu Avatar asked Dec 06 '25 06:12

Yigang Wu


2 Answers

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

like image 61
Mark Ransom Avatar answered Dec 07 '25 21:12

Mark Ransom


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;
like image 45
Franci Penov Avatar answered Dec 07 '25 21:12

Franci Penov



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!