Skip to content

Fix visual style issues on Windows

Li Shengqiu edited this page Jan 9, 2018 · 2 revisions

On Windows, you may find that wxGo programs look ugly - they are using the classic Windows98-like style. Also, if you are using a HiDPI monitor, they also look blurry. In the following screenshot, the left one has the visual issues, and the right one renders correctly on Windows 10 with 125% DPI scale.

classic, blurry vs modern

Use application manifest to specify modern styles and DPI awarness

Application Manifest is an XML file that describes some properties a binary should have. The following manifest solves the two issues mentioned above:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0" xmlns:asmv3="urn:schemas-microsoft-com:asm.v3">
    <assemblyIdentity
        version="1.0.0.0"
        processorArchitecture="*"
        name="Your program's Name"
        type="win32"
    />
    <dependency>
        <dependentAssembly>
            <assemblyIdentity
                type="win32"
                name="Microsoft.Windows.Common-Controls"
                version="6.0.0.0"
                processorArchitecture="*"
                publicKeyToken="6595b64144ccf1df"
                language="*"
            />
        </dependentAssembly>
    </dependency>
    <asmv3:application>
    <asmv3:windowsSettings xmlns="http://schemas.microsoft.com/SMI/2016/WindowsSettings">
      <dpiAwareness>system</dpiAwareness>
    </asmv3:windowsSettings>
    </asmv3:application>
</assembly>

In order to make the manifest take effect, we have to use some tools to embed the file into our binary.

Option 1: use mt.exe

mt.exe is a tool that distributed with Windows SDK. On my PC, it is at C:\Program Files (x86)\Windows Kits\10\bin\10.0.15063.0\x64.

Run "C:\Program Files (x86)\Windows Kits\10\bin\10.0.16299.0\x64\mt.exe" -manifest your_program.exe.manifest -outputresource:your_program.exe to embed the manifest into your binary.

Option 2: use rsrc

rsrc is a program that can compile resources(manifest, icons etc) into a syso file. syso files can be linked in the normal go build process.