Home > Backend Development > C++ > Why Does My DPI-Unaware Application Suddenly Become DPI-Aware After an Update?

Why Does My DPI-Unaware Application Suddenly Become DPI-Aware After an Update?

Patricia Arquette
Release: 2025-01-28 08:56:10
Original
755 people have browsed it

Why Does My DPI-Unaware Application Suddenly Become DPI-Aware After an Update?

Unexpected DPI Awareness Changes After Application Updates

Some applications, originally designed as DPI-unaware (relying on Windows' UI scaling), may unexpectedly become DPI-aware (System Aware) following minor updates. This occurs even if the application manifest and external dependencies remain unchanged.

Root Cause:

This behavior is often caused by DPI-aware third-party components or dependencies. Even with an explicit DPI-Unaware declaration in the application manifest, inclusion of such components can override the setting, forcing DPI-awareness.

Solutions for Defining DPI Awareness:

Several approaches can explicitly control an application's DPI awareness:

1. Modifying the Application Manifest:

  • Modify app.manifest to include (or uncomment) the following:
<code class="language-xml"><dpiaware xmlns="http://schemas.microsoft.com/SMI/2005/WindowsSettings">false</dpiaware></code>
Copy after login

2. Utilizing Windows API Functions:

The appropriate API call depends on the Windows version:

  • Windows 7:
<code class="language-csharp">[DllImport("user32.dll", SetLastError = true)]
static extern bool SetProcessDPIAware();</code>
Copy after login
  • Windows 8.1:
<code class="language-csharp">[DllImport("shcore.dll")]
static extern int SetProcessDpiAwareness(ProcessDPIAwareness value);

enum ProcessDPIAwareness
{
    DPI_Unaware = 0,
    System_DPI_Aware = 1,
    Per_Monitor_DPI_Aware = 2
}</code>
Copy after login
  • Windows 10 (1703 and later):
<code class="language-csharp">[DllImport("user32.dll", SetLastError = true)]
static extern int SetProcessDpiAwarenessContext(DpiAwarenessContext value);

enum DpiAwarenessContext
{
    Context_Unaware = (DPI_AWARENESS_CONTEXT)-1,
    Context_SystemAware = (DPI_AWARENESS_CONTEXT)-2,
    Context_PerMonitorAware = (DPI_AWARENESS_CONTEXT)-3,
    Context_PerMonitorAwareV2 = (DPI_AWARENESS_CONTEXT)-4
}</code>
Copy after login

3. Using AssemblyInfo.cs:

Add this attribute to override system-defined DPI awareness based on component references:

<code class="language-csharp">[assembly: System.Windows.Media.DisableDpiAwareness]</code>
Copy after login

Important Considerations:

  • DPI awareness is thread-specific. Use thread-specific API functions for granular control over individual threads.
  • Ensure all third-party components and dependencies are consistent with the desired DPI awareness level.

The above is the detailed content of Why Does My DPI-Unaware Application Suddenly Become DPI-Aware After an Update?. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template