Code

Now let's write some code! First of all, create a new directory to put this code intodue to the way that Walk binaries are created (see the following code), we need to build at a directory level, rather with than single files, so it's good to have a clean workspace. Copy the following code into a file named hello.go:

package main

import (
"github.com/lxn/walk"
. "github.com/lxn/walk/declarative"
)

func main() {
MainWindow{
Title: "Hello",
Layout: VBox{},
Children: []Widget{
Label{Text: "Hello World!"},
PushButton{
Text: "Quit",
OnClicked: func() {
walk.App().Exit(0)
},
},
},
}.Run()
}

In the preceding code, you can see two different imports for Walkwe will talk about that more later. Inside the main() function, we set up a simple window with two items in a VBox layout: one Label, and one PushButton that will exit the app when clicked. Next, we need to create an additional file, named hello.exe.manifest, with the following contents (this manifest file is needed in the build process):

<?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="HelloWorld" 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>

This manifest file is required to tell Windows runtime that we are using the Common Controls framework version 6.0.0.0 (or newer), which is required by the Walk APIs.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.139.83.151