govcl

govcl mod

  • govcl一个Go的跨平台GUI库 见作者 wikis
  • Go版本>1.15需要使用dev-分支

dev分支

clone到GOPATH/src/github.com/ying32
git checkout dev 不用下面的方法了


当前操作系统

1
2
3
4
5
6
NAME="openSUSE Tumbleweed"
# VERSION="20210810"
ID="opensuse-tumbleweed"
ID_LIKE="opensuse suse"
VERSION_ID="20210810"
PRETTY_NAME="openSUSE Tumbleweed"

建立go mod模式

先建立一个GOPATH

1
2
3
4
5
cd $GOPATH/src
mkdir -p github.com/ying32
cd github.com/ying32
git clone https://github.com/ying32/govcl.git
git checkout dev

建立go mod

  • 这里建立在当前用户的tftp目录下
    1
    2
    3
    4
    5
    6
    7
    8
    9
    cd ~/tftp/
    git clone https://github.com/ying32/govcl.git
    cd govcl
    git checkout dev
    go mod init github.com/ying32/govcl
    cp -r vendor/github.com/ying32/dylib/ .
    cd dylib
    go mod init github.com/ying32/dylib

  • 修改 floatpatch目录下 asmTest_test.go 引用为 “github.com/ying32/dylib”
1
2
3
go mod tidy 
cd -
go mod tidy

使用方法

  • 引用go mod文件位置
1
2
3
cd sample
go mod init sample

1
2
3
4
5
6
7
8
9
module sample

go 1.16

replace github.com/ying32/govcl => /home/xuan/tftp/govcl

replace github.com/dylib => /home/xuan/tftp/govcl/dylib

require github.com/ying32/govcl v0.0.0-00010101000000-000000000000
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
package main

import (
"github.com/ying32/govcl/vcl"

"fmt"

_ "github.com/ying32/govcl/pkgs/winappres"
"github.com/ying32/govcl/vcl/types"
)

type TMainForm struct {
*vcl.TForm
Button1 *vcl.TButton
}

type TForm1 struct {
*vcl.TForm
Button1 *vcl.TButton
}

var (
mainForm *TMainForm
form1 *TForm1
)

func main() {
vcl.RunApp(&mainForm, &form1)
}

// --------------MainForm -----------------
func (f *TMainForm) OnFormCreate(sender vcl.IObject) {
f.SetCaption("Hello")
f.EnabledMaximize(false)
f.SetWidth(300)
f.SetHeight(200)
f.ScreenCenter()

f.Button1 = vcl.NewButton(f)
f.Button1.SetParent(f)
f.Button1.SetCaption("窗口1")
f.Button1.SetLeft(50)
f.Button1.SetTop(50)
f.Button1.SetOnClick(f.OnButton1Click)

}

func (f *TMainForm) OnFormCloseQuery(Sender vcl.IObject, CanClose *bool) {
*CanClose = vcl.MessageDlg("是否退出?", types.MtConfirmation, types.MbYes, types.MbNo) == types.IdYes
}

func (f *TMainForm) OnButton1Click(object vcl.IObject) {
form1.Show()
}

// ---------- Form1 ----------------

func (f *TForm1) OnFormCreate(sender vcl.IObject) {
fmt.Println("onCreate")
f.Button1 = vcl.NewButton(f)
fmt.Println("f.Button1:", f.Button1.Instance())
f.Button1.SetParent(f)
//f.Button1.SetName("Button1")
f.Button1.SetCaption("我是按钮")
f.Button1.SetOnClick(f.OnButton1Click)
}

func (f *TForm1) OnButton1Click(object vcl.IObject) {
vcl.ShowMessage("Click")
}

编译独立文件

1
2
go get -u github.com/ying32/liblclbinres
GOOS=windows GOARCH=amd64 go build -ldflags="-H windowsgui -s -w" -tags tempdll -buildmode=exe .

推荐文章