Getting custom DPI percentage in Delphi

Viewed 15933

Trying to my Delphi 2010 application more user freindly in high DPI modes in Windows 7 I have been trying several methods to retrive PixelsPerInch and compare to 96. Alas, no matter what I tried I always get 96. My questions are:

  1. What is the best practice to get custom DPI mode?
  2. Is the fact I am getting a constant 96 no matter what I what the percebtage is means I missing somthing?

Here is what I had tried

dpiX := Form1.PixelsPerInch

and

dpiX := Screen.PixelsPerInch

and finally:

D2DFactoryOptions.DebugLevel := D2D1_DEBUG_LEVEL_NONE;
pD2DFactoryOptions := @D2DFactoryOptions;
if D2D1CreateFactory(
    D2D1_FACTORY_TYPE_SINGLE_THREADED,
    IID_ID2D1Factory,
    PD2DFactoryOptions,
    D2DFactory
    ) <> S_OK then exit;
D2DFactory.GetDesktopDpi(dpiX, dpiY)

Care to guess? that's right dpiX is a constant 96 in 100%, 125% and 150%

Please advice.

7 Answers

i set out to fix this delphi program which had DPI troubles in Windows 10, fine in Windows 7 Virtual Magnifying Glass, after landing here and troubleshooting, i ended up saving alot of time by just right clicking properties of the exe and fiddling with Compatibility settings, there's a "Change high DPI settings" button, at the bottom of that dialog turned on "Override high DPI scaling" and app is now working fine.

So if it's just personal use or w/e this will be much less of a headache!

In case it helps someone, I have noticed that Screen->PrimaryMonitor->PixelsPerInch DOES change according to the display scaling.

Related