Search code examples
delphiwinapi

Delphi changing high-dpi at runtime


Is it possible to switch between "High-DPi" and "not High-DPi" program view at run-time? As far as I understand it is determined in manifest file and you can either have High-DPi app or none High-Dpi app but cannot have them both. Am I right?


Solution

  • You can specify this at runtime using the SetProcessDpiAwareness function. Or for older operating systems that pre-date per-monitor DPI awareness, there is SetProcessDPIAware.

    Do read the documentation carefully. As a broad guideline you are recommended not to use these functions, and should prefer to specify this state in the manifest. It would be an unusual application indeed that needed to use SetProcessDpiAwareness or SetProcessDPIAware.

    At the very least you will surely need to make the call very early in the lifetime of the process. Not only does Windows want the call to happen early, but I expect that the VCL won't be designed to cope well with changes of policy midway through the lifetime of the process.