Get Monitor Scale Factor

In my application I’d like to find what scaling factor each monitor is set to.

I’ve tried GetScaleFactorForMonitor (from SHCORE.DLL) but it returns 140 for my 4K monitor when Windows shows it as 150%. The other monitors that are set to 100% all return 100.

Am I misunderstanding something or is there a better way to get this info?

Use the Screen variable; the Monitors items have the PixelsPerInch property, compare to 96

Scaling for HiDPI - how to make your apps work properly at any screen resolution with Ian Barker

Malcolm Cheyne
Townsville

1 Like

Screen.PixelsPerInch says 96 so not sure how that helps. This is with Delphi XE so that’s possibly the issue?

Yes, that’s a problem. Most of the changes for HiDPI support came with the version 12 releases although from XE5 onwards things improved too.

I do have Delphi 12 so any changes will have to wait until I can migrate my project to it.

A bit more investigation seems to suggest that the GetScaleFactorForMonitor result is influenced by the DPI awareness of the calling process and this is why the result is wrong for XE. I had assumed that the call would be independent. Oh well.

You can make your application dpi aware by adding a windows manifest file

of course the Vcl in XE didn’t do anything for high dpi but at least GetScaleFactorForMonitor will give the correct results.

Thanks Vincent. I’ll have a go with adding a manifest file.

Today I read many pages about manifests and get the general idea, but I’m stalled at the point of what exactly to name the file and how to add it into my Delphi XE project. There were many contradictory explanations online.

I can see in Project Options where I need to uncheck Use Runtime Themes and that does seem to affect the manifest section in the exe’s resources (I looked with Resource Hacker).

Can someone please help me over this hurdle? I’m obviously missing something!

I read all that, but the issue is that Delphi XE only has one option; a checkbox called Enable Runtime Themes. There is nowhere to specify a custom manifest. Maybe it’s just not possible with Delphi XE ?

My only option seems to be to deploy the manifest file alongside the exe ?

This is XE3 but might still be relevant. https://stackoverflow.com/questions/61199631/cannot-add-custom-manifest-file-to-delphi-xe3-project

  1. In the project options → Application → Runtime Themes → Use custom manifest, set it to the saved manifest file.
  2. Rebuild the project.

However, after that, when I run the application. It does not show the elevate to adminsitrator messagebox. I try to open and browse its resources. There is a manifest file inside the resource, but it is not the one I set.

So, how to set custom manifest file for a project?


Make sure to set the “Target” choice at the top of that window to each target type and check the setting. I’ve had to hand edit the dproj file to fix issues with bad target info being stuck. I also use Project Magician from Uwe Raabe which is a huge help. – MarkF

CommentedApr 14, 2020 at 2:51

  • @MarkF, Thank you very much. I edit the dproj file manually and the problem is solved. – alancc

CommentedApr 14, 2020 at 6:24

Project Magician

No, in XE the only option is a checkbox, so it looks like I’m out of luck there.

I did try putting the manifest file (with the DPI Awareness) in the same folder as the exe, but either it’s not being used or doesn’t help the other code I’m trying to use.

Can you edit the .dproj file?

I have just made a small win32 console app to grab some files from online.
It’s only 2mb in Release build.

The .dproj file is 1100 lines, and mentions 9 platforms. :rofl: (12.3, Rad Studio)

I copied the xml from the SO link, and added it to my project as ‘test.manifest’.
This is what the .dproj diff looks like :

I can include the file, but it looks like XE doesn’t do anything with it.

It just shows in the .dproj file as a plain included file.

I think we’ve exhausted all the possibilities. It will just have to wait until the D12 migration.

Hi David,

This is what I do with Delphi 2007.
Put this as the 2nd line of your DPR file:

{$R ‘WindowsDpiAwareness.res’ ‘WindowsDpiAwareness.rc’}

This is WindowsDpiAwareness.rc:

1 24 WindowsDpiAwareness.manifest

And WindowsDpiAwareness.manifest:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?> Microtax Pty Ltd True

Cheers,
Lex Edmonds

Hmm, the Manifest seems to have been clobbered by GMail.
Here’s a copy of the actual file.

Lex

(Attachment WindowsDpiAwareness.manifest is missing)

Hmm, OK lets try with a zipfile.

Lex

(attachments)

WindowsDpiAwareness.zip (1.25 KB)

It seems the ADUG forum is what has rejected my files.
Please contact me on ledmonds99@gmail.com if you’d like a copy.

Cheers,
Lex