govcl

module
v1.2.9 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 6, 2020 License: Apache-2.0

README


跨平台的Golang GUI库,底层绑定自Delphi VCL和Lazarus LCL

从1.2.0版本开始govcl将最低要求go1.9。

截图查看 | 中文文档 | 更新日志 | 加入QQ群 | GoVCL视频教程(第三方) | 赞助GoVCL


支持的平台

Windows | Linux | macOS

注: linux和macOS由于底层使用了lcl库,则部分组件、属性和方法无效。
如果你想要支持linux arm及linux 32bit则需要自己编译对应的liblcl二进制。


预编译GUI库二进制下载

Librarys

注:压缩包内包含的“libvcl”库二进制(libvcl.dll、libvclx64.dll)仅供预览和测试使用。正式使用请自行编译“libvcl”源代码,具体编译方法参考UILIbSrcources中的说明。

res2go工具下载(文档

res2go

注:用Delphi/Lazarus设计界面,用Golang写代码。

GoVCL扩展包

注:扩展包里面的inc或者pas文件需要自己放到libvcl/liblcl目录下编译。


使用方法

步骤一:获取govcl代码

go get -u github.com/ying32/govcl

步骤二:编写代码

  • 方法一(使用Delphi/Lazarus或者GoVCLDesigner设计界面。推荐):
package main


import (
   "github.com/ying32/govcl/vcl"
   // 如果你使用自定义的syso文件则不要引用此包
   _ "github.com/ying32/govcl/pkgs/winappres"
)

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

type TAboutForm struct {
    *vcl.TForm
    Btn1    *vcl.TButton
}

var (
    mainForm *TMainForm
    aboutForm *TAboutForm
)

func main() {
    vcl.Application.Initialize()
    vcl.Application.SetMainFormOnTaskBar(true)
    vcl.Application.CreateForm(&mainForm)
    vcl.Application.CreateForm(&aboutForm)
    vcl.Application.Run()
}

// -- TMainForm

func (f *TMainForm) OnFormCreate(sender vcl.IObject) {
    
}

func (f *TMainForm) OnBtn1Click(sender vcl.IObject) {
    vcl.ShowMessage("Hello!")
}

// -- TAboutForm

func (f *TAboutForm) OnFormCreate(sender vcl.IObject) {
 
}

func (f *TAboutForm) OnBtn1Click(sender vcl.IObject) {
    vcl.ShowMessage("Hello!")
}

方法一需要配合UI设计器或者res2go工具使用。

  • 方法二(纯代码,仿照Delphi类的方式,可自动绑定事件。):
package main


import (
   "github.com/ying32/govcl/vcl"
   // 如果你使用自定义的syso文件则不要引用此包
   _ "github.com/ying32/govcl/pkgs/winappres"
)

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

type TAboutForm struct {
    *vcl.TForm
    Btn1    *vcl.TButton
}

var (
    mainForm *TMainForm
    aboutForm *TAboutForm
)

func main() {
    vcl.Application.Initialize()
    vcl.Application.SetMainFormOnTaskBar(true)
    vcl.Application.CreateForm(&mainForm)
    // 创建完后关联子组件事件
    vcl.Application.CreateForm(&aboutForm, true)
    vcl.Application.Run()
}

// -- TMainForm

func (f *TMainForm) OnFormCreate(sender vcl.IObject) {
    f.SetCaption("Hello")
    f.Btn1 = vcl.NewButton(f)
    f.Btn1.SetParent(f)
    f.Btn1.SetBounds(10, 10, 88, 28)
    f.Btn1.SetCaption("Button1")
    f.Btn1.SetOnClick(f.OnButtonClick)  
}

func (f *TMainForm) OnButtonClick(sender vcl.IObject) {
    vcl.ShowMessage("Hello!")
}


// -- TAboutForm

func (f *TAboutForm) OnFormCreate(sender vcl.IObject) {
    f.SetCaption("Hello")
    f.Btn1 = vcl.NewButton(f)
    //f.Btn1.SetName("Btn1")
    f.Btn1.SetParent(f)
    f.Btn1.SetBounds(10, 10, 88, 28)
    f.Btn1.SetCaption("Button1")
}

func (f *TAboutForm) OnBtn1Click(sender vcl.IObject) {
    vcl.ShowMessage("Hello!")
}

  • 方法三(纯代码。不推荐方式):
package main

import (
   "github.com/ying32/govcl/vcl"
   // 如果你使用自定义的syso文件则不要引用此包
   _ "github.com/ying32/govcl/pkgs/winappres"
)

func main() {
    vcl.Application.Initialize()
    mainForm := vcl.Application.CreateForm()
    mainForm.SetCaption("Hello")
    mainForm.EnabledMaximize(false)
    mainForm.ScreenCenter()
    btn := vcl.NewButton(mainForm)
    btn.SetParent(mainForm)
    btn.SetCaption("Hello")
    btn.SetOnClick(func(sender vcl.IObject) {
        vcl.ShowMessage("Hello!")
    })
    vcl.Application.Run()
}

步骤三:复制对应的二进制

  • Windows: 根据编译的二进制是32还是64位的,复制对应的"libvcl.dll"或者"libvclx64.dll"或者“liblcl.dll”到当前exe目录或系统环境路径下。

    • Go环境变量: GOARCH = amd64 386 GOOS = windows CGO_ENABLED=0
  • Linux: 复制"liblcl.so"可执行文件目录下(也可复制liblcl.so到/usr/lib/或者/usr/lib/x86_64-linux-gnu/目录中,作为公共库使用)。

    • Go环境变量: GOARCH = amd64 GOOS = linux CGO_ENABLED=1
  • MacOS: 复制"liblcl.dylib"可执行文件目录下(MacOS下注意:需要自行创建info.plist文件),或者参考:MacOS上应用打包

    • Go环境变量: GOARCH = amd64 GOOS = darwin CGO_ENABLED=1

注意:

当使用"liblcl"库时,是以兼容"libvcl"库形式运行的,所以有部分组件和组件的方法、属性及事件不可用。

特别注意:所有UI组件都是非线程/协程安全的,当在goroutine中使用时,请使用vcl.ThreadSync来同步更新到UI上。

API文档

Directories

Path Synopsis
Tools
LazarusPatch command
libBuild command
pkgs
skinh
skinsharp皮肤扩展接口 http://www.skinsharp.com/htdocs/index.htm skinsharp是收费的,这里只是头文件的导入。
skinsharp皮肤扩展接口 http://www.skinsharp.com/htdocs/index.htm skinsharp是收费的,这里只是头文件的导入。
samples
OSVersion command
SkinsharpTest command
由GOVCL UI设计器自动生成,不要编辑。
由GOVCL UI设计器自动生成,不要编辑。
WindowsMessages command
WindowsProcess command
WindowsTest command
action command
basic command
basicResForm command
由GOVCL UI设计器自动生成,不要编辑 由GOVCL UI设计器自动生成,不要编辑。
由GOVCL UI设计器自动生成,不要编辑 由GOVCL UI设计器自动生成,不要编辑。
checklistbox command
clock command
由GOVCL UI设计器自动生成,不要编辑
由GOVCL UI设计器自动生成,不要编辑
comboboxEx command
由res2go自动生成,不要编辑。
由res2go自动生成,不要编辑。
customLibTest command
draganddrop command
draw command
drawrose command
由GOVCL UI设计器自动生成,不要编辑
由GOVCL UI设计器自动生成,不要编辑
dropfiles command
eventpublic command
formEvents command
由GOVCL UI设计器自动生成,不要编辑。
由GOVCL UI设计器自动生成,不要编辑。
formscale command
由GOVCL UI设计器自动生成,不要编辑
由GOVCL UI设计器自动生成,不要编辑
gdiplustest command
由GOVCL UI设计器自动生成,不要编辑。
由GOVCL UI设计器自动生成,不要编辑。
gdiplustest2 command
由GOVCL UI设计器自动生成,不要编辑。
由GOVCL UI设计器自动生成,不要编辑。
govcl command
govcl project main.go go.exe build -i -ldflags="-H windowsgui"
govcl project main.go go.exe build -i -ldflags="-H windowsgui"
grids/drawgrid command
imagebutton command
imageviewer command
由GOVCL UI设计器自动生成,不要编辑
由GOVCL UI设计器自动生成,不要编辑
inifile command
jsonTogo command
由GOVCL UI设计器自动生成,不要编辑
由GOVCL UI设计器自动生成,不要编辑
jsonViewer command
由GOVCL UI设计器自动生成,不要编辑
由GOVCL UI设计器自动生成,不要编辑
layout command
listview command
listviewadv1 command
由res2go自动生成,不要编辑。
由res2go自动生成,不要编辑。
listviewcustomdraw command
由GOVCL UI设计器自动生成,不要编辑。
由GOVCL UI设计器自动生成,不要编辑。
listviewitemedit command
由res2go自动生成,不要编辑。
由res2go自动生成,不要编辑。
login command
由GOVCL UI设计器自动生成,不要编辑 由GOVCL UI设计器自动生成,不要编辑
由GOVCL UI设计器自动生成,不要编辑 由GOVCL UI设计器自动生成,不要编辑
markdownEd command
由GOVCL UI设计器自动生成,不要编辑
由GOVCL UI设计器自动生成,不要编辑
memloaddll command
由GOVCL UI设计器自动生成,不要编辑 由GOVCL UI设计器自动生成,不要编辑。
由GOVCL UI设计器自动生成,不要编辑 由GOVCL UI设计器自动生成,不要编辑。
memstream command
menu command
messageTest command
miniblinkWebview command
由GOVCL UI设计器自动生成,不要编辑 由GOVCL UI设计器自动生成,不要编辑 由GOVCL UI设计器自动生成,不要编辑
由GOVCL UI设计器自动生成,不要编辑 由GOVCL UI设计器自动生成,不要编辑 由GOVCL UI设计器自动生成,不要编辑
miniwebview command
由GOVCL UI设计器自动生成,不要编辑
由GOVCL UI设计器自动生成,不要编辑
mp3Player command
由GOVCL UI设计器自动生成,不要编辑
由GOVCL UI设计器自动生成,不要编辑
msgbox command
multilanguage command
Automatically generated by the GOVCL UI designer, do not edit
Automatically generated by the GOVCL UI designer, do not edit
myext command
由GOVCL UI设计器自动生成,不要编辑
由GOVCL UI设计器自动生成,不要编辑
notepad command
由GOVCL UI设计器自动生成,不要编辑。
由GOVCL UI设计器自动生成,不要编辑。
pagecontrolwizard command
由GOVCL UI设计器自动生成,不要编辑
由GOVCL UI设计器自动生成,不要编辑
printer command
registerHotKey command
由GOVCL UI设计器自动生成,不要编辑
由GOVCL UI设计器自动生成,不要编辑
registry command
res2goTest/Delphi/gocode command
由res2go自动生成,不要编辑。
由res2go自动生成,不要编辑。
res2goTest/Lazarus/gocode command
由res2go自动生成,不要编辑。
由res2go自动生成,不要编辑。
res2goTest/Test/gocode command
由res2go自动生成,不要编辑。
由res2go自动生成,不要编辑。
richedit command
shortcut command
simplelibvlc command
由GOVCL UI设计器自动生成,不要编辑
由GOVCL UI设计器自动生成,不要编辑
statusbar command
stdcontrols command
style command
sysdialog command
syslocale command
taskdialog command
trayicon command
treeview command
valuelisteditor command
由GOVCL UI设计器自动生成,不要编辑
由GOVCL UI设计器自动生成,不要编辑
virtuallistview command
winJumpList command
winTaskbar command
windowsspy command
由GOVCL UI设计器自动生成,不要编辑
由GOVCL UI设计器自动生成,不要编辑
wingif command
winole command
xunleidownloader command
由GOVCL UI设计器自动生成,不要编辑
由GOVCL UI设计器自动生成,不要编辑
vcl
api
---------------------------------------- 加载文件或者内存中的窗口资源文件功能 需要配合窗口设计器使用 ----------------------------------------
---------------------------------------- 加载文件或者内存中的窗口资源文件功能 需要配合窗口设计器使用 ----------------------------------------
rtl
win

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL