使用Golang语言walk框架开发一个简单的windowsGUI
创始人
2024-03-24 18:12:43
0

1、前言

最近使用golang语言开发了一个windowsGUI的Demo,由于golang语言属于比较新的语言,对GUI开发这一块并没有原生库也没有推荐库,因此我在github上找到了一个叫做walk的GUI开发框架。

github原址为:http://github.com/lxn/walk

在golang社区也能看到他的文档:http://godoc.org/github.com/lxn/walk

当然,你看了github和godoc就能发现,这个文档和直接看源码没啥区别,文档里没有让人一眼就能明白的描述,只是对方法和属性的介绍,至于具体使用更是没有。全靠自己摸索。

当然,在他的源码里,你可以看到有一个examples的文件夹,这个里面包含了所有作者写出的示例(当然,也没有什么有用的注释告诉你这个例子干了什么)。只能在terminal里进入一个个的文件夹,一次次的编译,然后运行.exe文件看效果,才能知道这个例子到底是干嘛的。

当然,作者贴心的在每个示例里上传了.syso文件,这样我们可以直接使用go build进行编译然后运行.exe查看效果了。否则的话还需要安装rsrc工具,对.manifest文件进行打包,然后再编译.exe文件。如果想编译出的.exe文件没有cmd命令行,则需要加上 -ldflags="-H windowsgui"参数,所以最终编译的命令为:go build -ldflags="-H windowsgui"

2、源码地址

项目名称为clientDemo

github地址:https://github.com/imcc2022/clientDemo

gitee地址:https://gitee.com/imcc2022/client-demo

访问不了github的同学可以访问gitee。项目的详细介绍在 README.md文件中。这里再贴一下

3、项目介绍

演示图
演示图

 

clientDemo

一个用walk框架写的windowsGUI示例(golang) / A windows GUI demo written by walk framework(golang)

功能点包括:输入框,密码行,登录,系统托盘,页面切换,窗口最大化禁用,窗口尺寸禁止修改等 / Function nodes include: input box, password line, login, system tray, page switching, window maximization disabled, window size disabled, etc

项目结构 / Project Structure

1:主目录(clientDemo)

master directory(clientDemo)

2:资源目录(clientDemo/resource)[包含图片和manifest声明打包文件]

resource directory(clientDemo/resource)[Include imgs and manifest files]

3:服务目录(clientDemo/service)[包含所有非ui相关的功能]

service directory(clientDemo/service)[Include all functions except ui]

4:界面目录(clientDemo/ui)[包含所有ui功能]

ui directory(clientDemo/ui)[Include all ui functions]

5:main.go[程序入口]

main.go[Program entry]

6:clientDemo.syso[由rsrc工具执行生成]

clientDemo.syso[Generate by rsrc tool]

7:go.mod[golang的包管理文件]

go.mod[Package management file of golang]

步骤 / Steps

1:安装golang环境,需要Go 1.11.x或更新的版本(https://go.dev/doc/install)

Install the golang environment,require Go 1.11.x or later(https://go.dev/doc/install)

2:执行"go mod tidy"命令下载go.mod文件中的依赖

Run "go mod tidy" command to download the dependencies in the go.mod file

3:如果想完整掌握项目编译过程,则需要安装rsrc工具

If you want to fully master the project compilation process, you need to install the rsrc tool

(1):执行"go get github.com/akavel/rsrc" 命令下载rsrc工具

Execute the "go get github.com/akavel/rsrc" command to download the rsrc tool

(2):进入GOPATH并找到rsrc目录

Enter GOPATH and find the rsrc directory

如果配置了GOPATH环境变量则可以直接通过"%GOPATH%\pkg\mod\github.com\akavel"进入

If the GOPATH environment variable is configured, you can directly enter through "%GOPATH%\pkg\mod\github.com\akavel"

如果没有配置且golang是默认安装的话,GOPATH通常会在"C:\Users\yourComputerName\go"目录下

If there is no configuration and golang is installed by default, GOPATH is usually in the "C: Users yourComputerName go" directory

(3):进入rsrc目录并将rsrc.exe文件拷贝到%GOROOT%\bin目录下,这时你就可以使用rsrc命令了(%GOROOT%是golang的安装目录)

Enter the rsrc directory and set the rsrc Copy the exe file to the% GOROOT% bin directory, and then you can use the rsrc command (% GOROOT% is the installation directory of golang)

(4):使用"rsrc -manifest resource/clientDemo.exe.manifest -o clientDemo.syso -ico resource/icon.ico"命令进行打包,"-manifest resource/clientDemo.exe.manifest"表示将"resource/clientDemo.exe.manifest"文件作为打包时的声明文件,"-o clientDemo.syso"设置生成的文件名称,"-ico resource/icon.ico"声明最终生成.exe文件的图标。PS:icon.ico文件必须是标准的.ico文件,不能是.jpeg文件直接修改文件后缀名形成。

Use the "rsrc -manifest resource/clientDemo.exe.manifest -o clientDemo.syso -ico resource/icon.ico" command to package. "-manifest resource/clientDemo.exe.manifest" means to use the "resource/clientDemo.exe.manifest" file as the declaration file when packaging. "-o clientDemo.syso" sets the name of the generated file. "-ico resource/icon.ico" declares the icon of the final generated.exe file. PS:The icon.ico file must be a standard. ico file, not a .jpeg file.can't get by Modifing the file suffix!

(5):执行" go build -ldflags="-H windowsgui" "命令进行编译,并形成.exe文件," -ldflags="-H windowsgui" "参数用于消除cmd命令框,如果需要则可以直接使用"go build"命令进行编译

Execute the " go build -ldflags="-H windowsgui" " command to compile and form Exe file, " -ldflags="-H windowsgui" " parameter is used to eliminate the cmd command box. If necessary, you can directly use the "go build" command to compile

(6):运行clientDemo.exe文件

run clientDemo.exe file

相关内容

热门资讯

AWSECS:访问外部网络时出... 如果您在AWS ECS中部署了应用程序,并且该应用程序需要访问外部网络,但是无法正常访问,可能是因为...
银河麒麟V10SP1高级服务器... 银河麒麟高级服务器操作系统简介: 银河麒麟高级服务器操作系统V10是针对企业级关键业务...
【NI Multisim 14...   目录 序言 一、工具栏 🍊1.“标准”工具栏 🍊 2.视图工具...
不能访问光猫的的管理页面 光猫是现代家庭宽带网络的重要组成部分,它可以提供高速稳定的网络连接。但是,有时候我们会遇到不能访问光...
AWSElasticBeans... 在Dockerfile中手动配置nginx反向代理。例如,在Dockerfile中添加以下代码:FR...
月入8000+的steam搬砖... 大家好,我是阿阳 今天要给大家介绍的是 steam 游戏搬砖项目,目前...
​ToDesk 远程工具安装及... 目录 前言 ToDesk 优势 ToDesk 下载安装 ToDesk 功能展示 文件传输 设备链接 ...
北信源内网安全管理卸载 北信源内网安全管理是一款网络安全管理软件,主要用于保护内网安全。在日常使用过程中,卸载该软件是一种常...
AWS管理控制台菜单和权限 要在AWS管理控制台中创建菜单和权限,您可以使用AWS Identity and Access Ma...
AWR报告解读 WORKLOAD REPOSITORY PDB report (PDB snapshots) AW...