1

I am looking for any method for setting DPI awareness level on fly(based on user input). I came across this.

It suggests that I should use setProcessDpiAwareness function to set the awareness level. But This api call is supported from windows 8.1 preview only. Is there any other method I can use to set the Dpi awareness level dynamically which is supported from windows 7 onwards?

Thanks in advance.

mehmet
  • 1,631
  • 16
  • 21
Abhishek
  • 852
  • 9
  • 24
  • SetProcessDPIAware() is available since Vista. Win81 just added the per-monitor DPI wrinkle. It must be called before any windows are created so "user input" isn't exactly a fantastic idea. – Hans Passant Jan 19 '15 at 10:40
  • 1
    @Hans `SetProcessDpiAwareness` is not the same as `SetProcessDpiAware`. – David Heffernan Jan 19 '15 at 10:42

1 Answers1

3

Before the advent of per-monitor DPI awareness in Windows 8.1, there is SetProcessDPIAware, supported from Vista up.

However, it strikes me as very unusual that you might wish to take this decision at runtime. Best practise is that the application is designed to be high DPI aware and that awareness is written into the application manifest.

David Heffernan
  • 601,492
  • 42
  • 1,072
  • 1,490
  • Thanks for your reply. But The docs says "SetProcessDPIAware is available for use in the operating systems specified in the Requirements section. It may be altered or unavailable in subsequent versions. Instead, use SetProcessDPIAwareness." This looks little unsafe. I want to be in safer side. – Abhishek Jan 19 '15 at 10:44
  • I am currently using manifest method. But there are lot of resources(fonts, control, graphics..etc). I want to use DWM scaling if application doesn't look good for user. So I want to set dynamic dpi awareness to false to allow DWM scaling. – Abhishek Jan 19 '15 at 10:46
  • 1
    If you don't want dpi awareness then don't manifest that your app is dpi aware. No need to call a function at runtime. – David Heffernan Jan 19 '15 at 10:55
  • 2
    As for your first comment that makes no sense. You explicitly asked what function to use on Windows 7. Well, there is no `SetProcessDPIAwareness` there. On Windows 7 you have `SetProcessDPIAware`. That's it. Feel free to call `SetProcessDPIAwareness` on 8.1 and later, and fall back to `SetProcessDPIAware` on earlier versions. Of course, I'd just remove the dpi aware section from the manifest. – David Heffernan Jan 19 '15 at 10:57
  • Thanks a lot for following. Let me explain my real problem. I have manifest that my application is dpi aware. I have done scaling for font, graphics etc to look my application good on high dpi. But sometime this scaling screw up everything in low dpi machines. So I want to give user an option if he want DWM scaling of windows start my application with 'N' switch and then scaling from windows will make application usable. – Abhishek Jan 19 '15 at 11:00
  • Ok, So I just wanted to confirm. Looks like this is the only option I got. – Abhishek Jan 19 '15 at 11:01
  • 3
    In that case I would remove dpi awareness from the manifest and enable it with a call to `SetProcessDPIAware` at startup, if the user's arguments allow dpi aware. – David Heffernan Jan 19 '15 at 11:03
  • [How to change the manifest in VS](https://stackoverflow.com/questions/68915392/how-can-i-change-dpi-manifest-settings-in-a-premake-vs-c-project/68915393#68915393). – idbrii Aug 25 '21 at 00:17