About DuiLib's DPI Adaptation

Posted by slicer123 on Thu, 16 May 2019 13:09:14 +0200

In some cases, although DuiLib can zoom normally with high DPI settings, the zoomed display is not good, the text and picture display is blurred, which affects the user experience. After many experiments, the solutions are as follows:
In the project file settings, make property settings for the corresponding project:

one
In Project->Properties->Inventory Tool->Input and Output->Additional Inventory File, select the appropriate Inventory File in this configuration item, and the contents of the Inventory File are as follows:

<?xml version="1.0" encoding="UTF-8"?>
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
    <!-- Windows 6.0 Style -->  
    <dependency>
        <dependentAssembly>
            <assemblyIdentity type="win32" name="Microsoft.Windows.Common-Controls" version="6.0.0.0" processorArchitecture="x86" publicKeyToken="6595b64144ccf1df" language="*"></assemblyIdentity>
        </dependentAssembly>
    </dependency>
    <!-- Administrator -->  
    <trustInfo xmlns="urn:schemas-microsoft-com:asm.v3">
        <security>
            <requestedPrivileges>
                <requestedExecutionLevel level="asInvoker"></requestedExecutionLevel>
            </requestedPrivileges>
        </security>
    </trustInfo>
    <!-- DPI Aware -->
    <asmv3:application xmlns:asmv3="urn:schemas-microsoft-com:asm.v3">
        <asmv3:windowsSettings xmlns="http://schemas.microsoft.com/SMI/2005/WindowsSettings">
            <dpiAware>true</dpiAware>
        </asmv3:windowsSettings>
    </asmv3:application>
    <!-- OSVersion -->
    <compatibility xmlns="urn:schemas-microsoft-com:compatibility.v1">   
        <application>   
            <!-- Windows 10 -->   
            <supportedOS Id="{8e0f7a12-bfb3-4fe8-b9a5-48fd50a15a9a}"/>  
            <!-- Windows 8.1/Windows Blue/Server 2012 R2 -->  
            <supportedOS Id="{1f676c76-80e1-4239-95bb-83d0f6d0da78}"/>  
            <!-- Windows Vista/Server 2008 -->  
            <supportedOS Id="{e2011457-1546-43c5-a5fe-008deee3d3f0}"/>   
            <!-- Windows 7/Server 2008 R2 -->  
            <supportedOS Id="{35138b9a-5d96-4fbd-8e2d-a2440225f93a}"/>  
            <!-- Windows 8/Server 2012 -->  
            <supportedOS Id="{4a2f28e3-53b9-4441-ba9c-d69d4a4a6e38}"/>  
        </application>   
    </compatibility>  
</assembly>

Where requestedExecutionLevel corresponds to Project->Properties->Connector->Inventory File->UAC Execution Level, these two items need to be the same, otherwise the link will not pass;
dpiAware corresponds to whether DPI is automatically adapted or not, true is auto-adapted.

two
Once the above configuration settings are complete, you need to set the corresponding DPI for each individual form (WindowImplBase) in your code as follows:
m_pm.SetDPI(CDPI::GetMainMonitorDPI());

three
With regard to the configuration of picture resources, under high DPI settings, DuiLib automatically loads the corresponding DPI zoom ratio picture resources, such as: normal image="file='image\login_normal.png". Under DPI settings of 150 zoom ratio, the resource automatically loads imagelogin_normal@150.png. If the resource does not have this file, the resource cannot load normally and appears blank.ui files (xml) do not need to be modified, just put the corresponding naming rules in the resource file

Topics: Windows xml encoding