1 Star 0 Fork 0

橙子 / lxnWalk

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README
BSD-3-Clause

About Walk

Walk is a "Windows Application Library Kit" for the Go Programming Language.

Its primarily useful for Desktop GUI development, but there is some more stuff.

Setup

Make sure you have a working Go installation. See Getting Started

Note

Go 1.7.x doesn't work with walk anymore, Make sure you use Go 1.8.x or later.

To Install

Now run go get github.com/lxn/walk

Using Walk

The preferred way to create GUIs with Walk is to use its declarative sub package, as illustrated in this small example:

test.go
package main

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

func main() {
	var inTE, outTE *walk.TextEdit

	MainWindow{
		Title:   "SCREAMO",
		MinSize: Size{600, 400},
		Layout:  VBox{},
		Children: []Widget{
			HSplitter{
				Children: []Widget{
					TextEdit{AssignTo: &inTE},
					TextEdit{AssignTo: &outTE, ReadOnly: true},
				},
			},
			PushButton{
				Text: "SCREAM",
				OnClicked: func() {
					outTE.SetText(strings.ToUpper(inTE.Text()))
				},
			},
		},
	}.Run()
}
Create Manifest test.manifest
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
    <assemblyIdentity version="1.0.0.0" processorArchitecture="*" name="SomeFunkyNameHere" type="win32"/>
    <dependency>
        <dependentAssembly>
            <assemblyIdentity type="win32" name="Microsoft.Windows.Common-Controls" version="6.0.0.0" processorArchitecture="*" publicKeyToken="6595b64144ccf1df" language="*"/>
        </dependentAssembly>
    </dependency>
    <application xmlns="urn:schemas-microsoft-com:asm.v3">
        <windowsSettings>
            <dpiAwareness xmlns="http://schemas.microsoft.com/SMI/2016/WindowsSettings">PerMonitorV2, PerMonitor</dpiAwareness>
            <dpiAware xmlns="http://schemas.microsoft.com/SMI/2005/WindowsSettings">True</dpiAware>
        </windowsSettings>
    </application>
</assembly>

Then either compile the manifest using the rsrc tool, like this:

go get github.com/akavel/rsrc
rsrc -manifest test.manifest -o rsrc.syso

or rename the test.manifest file to test.exe.manifest and distribute it with the application instead.

Build app

In the directory containing test.go run

go build

To get rid of the cmd window, instead run

go build -ldflags="-H windowsgui"
Run app
test.exe
Sample Output (Windows 7)

alt tag

More Examples

There are some examples that should get you started.

Application Manifest Files

Walk requires Common Controls 6. This means that you must put an appropriate application manifest file either next to your executable or embedded as a resource.

You can copy one of the application manifest files that come with the examples.

To embed a manifest file as a resource, you can use the rsrc tool.

IMPORTANT: If you don't embed a manifest as a resource, then you should not launch your executable before the manifest file is in place. If you do anyway, the program will not run properly. And worse, Windows will not recognize a manifest file, you later drop next to the executable. To fix this, rebuild your executable and only launch it with a manifest file in place.

Program Crashes

By default Go uses os threads with small stack sizes of 128KB. If your walk app crashes, it may be due to a stack overflow. Until a better solution is found, you can work around this by adding

import _ "runtime/cgo"

somewhere in your program. If you don't have gcc installed and on your PATH, you can alternatively add -linkmode internal to the -ldflags of your go build command like so:

go build -ldflags="-H windowsgui -linkmode internal"

CGo Optimizations

The usual default message loop includes calls to win32 API functions, which incurs a decent amount of runtime overhead coming from Go. As an alternative to this, you may compile Walk using an optional C implementation of the main message loop, by passing the walk_use_cgo build tag:

go build -tags walk_use_cgo

Copyright (c) 2010 The Walk Authors. All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 3. The names of the authors may not be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

简介

A Windows GUI toolkit for the Go Programming Language 展开 收起
BSD-3-Clause
取消

发行版

暂无发行版

贡献者

全部

近期动态

加载更多
不能加载更多了
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/xuchengzhi/lxnWalk.git
git@gitee.com:xuchengzhi/lxnWalk.git
xuchengzhi
lxnWalk
lxnWalk
master

搜索帮助

344bd9b3 5694891 D2dac590 5694891