Hi,

The Problem:
Today I tried to run our software on a computer running Windows 8.1. And for 
some reason my application window became too large for the screen, even though 
I explicitly set the window resolution to be the same size as the display 
resolution.

Why the problem happens:
This computer was connected to a screen with FullHD resolution and as a result 
the DPI-scaling was automatically configured to 150% by the operating system.  
Since Windows 8.1, the operating system will scale your application to this 
DPI-scaling setting, unless you explicitly declare the application as 
"DPI-aware". Declaring your application as "DPI-aware" tells the operating 
system that you will be handling the scaling yourself.

The solution:
To make your application DPI-aware you must include a manifest with your DLL or 
EXE. The manifest file should look something like this:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
  <application xmlns="urn:schemas-microsoft-com:asm.v3">
    <windowsSettings>
      <dpiAware 
xmlns="http://schemas.microsoft.com/SMI/2005/WindowsSettings";>True</dpiAware>
    </windowsSettings>
  </application>
</assembly>

This manifest can be included to your EXE or DLL file by using the mt.exe 
(manifest tool), which is shipped with Visual Studio.

This process can be automated via CMake using the following custom command to 
amend the DPI-aware manifest to the standard manifest:

# Amend manifest to tell Windows that the application is DPI aware (needed for 
Windows 8.1 and up)
IF (MSVC)
    ADD_CUSTOM_COMMAND(
        TARGET ${TARGET_TARGETNAME}
        POST_BUILD
        COMMAND "mt.exe" -manifest 
\"${CMAKE_CURRENT_SOURCE_DIR}\\dpiaware.manifest\" 
-inputresource:\"$<TARGET_FILE:${TARGET_TARGETNAME}>\"\;\#1 
-outputresource:\"$<TARGET_FILE:${TARGET_TARGETNAME}>\"\;\#1
        COMMENT "Adding DPI-aware manifest..."
    )
ENDIF(MSVC)

If you are amending manifests to DLL-files you will need to change the #1 to #2 
in the CMAKE example above.

Hope this information will help others with the same problem.

Best regards

Björn

_______________________________________________
osg-users mailing list
[email protected]
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org

Reply via email to