-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create manifest file programmatically
This removes the hassle for the user to mess with manifest files. We also have control over the exact contents of the manifest file, no user errors.
- Loading branch information
Lars
committed
Aug 20, 2018
1 parent
02935ba
commit 9ec6100
Showing
2 changed files
with
49 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
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) | ||
} |