-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmanifest.go
55 lines (50 loc) · 1.76 KB
/
manifest.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
// Copyright 2018 The Walk Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
// +build windows
package walk
import (
"io/ioutil"
"os"
"path/filepath"
"strings"
"syscall"
"github.com/lxn/win"
)
/*
This function creates a manifest file for this application and activates it
before creating the GUI controls. This way, the common controls version 6 is
used automatically and the users of this library does not need to mess with
manifest files themselves.
*/
func init() {
appName := filepath.Base(os.Args[0])
appName = strings.TrimSuffix(appName, filepath.Ext(appName))
manifest := `<?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="` + appName + `" 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/2005/WindowsSettings">
<dpiAware>true</dpiAware>
</asmv3:windowsSettings>
</asmv3:application>
</assembly>`
// create a temporary manifest file, load it, then delete it
f, err := ioutil.TempFile("", "manifest_")
if err != nil {
return
}
manifestPath := f.Name()
defer os.Remove(manifestPath)
f.WriteString(manifest)
f.Close()
ctx := win.CreateActCtx(&win.ACTCTX{
Source: syscall.StringToUTF16Ptr(manifestPath),
})
win.ActivateActCtx(ctx)
}