项目 https://github.com/ying32/govcl
- 配置
set GO111MODULE=on
set GOPROXY=https://mirrors.aliyun.com/goproxy/
go get -u github.com/ying32/govcl
- 设计
参考文档 https://z-kit.cc/doc.html
实用工具 Lazarus 2.0.10 下载
https://www.lazarus-ide.org/index.php?page=downloads 注意对应系统版本
res2go Lazarus IDE插件和编译的gui dll
https://github.com/ying32/res2go-ide-plugin - 编译
创建mod文件p1是工程名也是文件名go mod init p1
编译成exego build -i -ldflags="-s -w -H windowsgui"
想要运行exe文件同级目录需要liblcl.dll
编译进去liblcl.dll,就是单文件运行go get -u github.com/ying32/liblclbinres
go build -i -ldflags="-s -w -H windowsgui" -tags tempdll
函数
后面支持替换vcl.ShowMessage("消息") vcl.ShowMessageFmt("消息=%d", 1)
ok1:=vcl.PasswordBox(“输入”, “请输入密码:”)
if ok1!=””{
vcl.ShowMessage(ok1)
}
s := vcl.InputBox(“标题”, “提示”, “默认值”)
s := “default”
if vcl.InputQuery(“标题”, “提示”, &s) {
vcl.ShowMessage(s)
}
n:=vcl.InputCombo(“选择”, “请选择一项:”+strings.Repeat(“ “, 50), []string{“第一项”, “第二项”, “第三项”, “第四项”}) 索引列表
vcl.InputComboEx 返回值列表
//询问和消息
_ “github.com/ying32/govcl/vcl/locales/zh_CN”是导入本地中文语言if vcl.MessageDlg("消息", types.MtConfirmation, types.MbYes, types.MbNo) == types.MrYes { vcl.ShowMessage("你点击了“是") } if vcl.Application.MessageBox("消息", "标题", win.MB_OKCANCEL+win.MB_ICONINFORMATION) == types.IdOK { vcl.ShowMessage("你点击了“是") } vcl.MessageDlg("不能为空", types.MtInformation, types.MbOK) i提示,下面一样的 win.MessageBox(0, "我已经在运行中啦!", "运行提示", win.MB_OK+win.MB_ICONINFORMATION) s:=win.GetDesktopPath() 桌面路径C:\Users\yoby\Desktop win.UTF8ToANSI("u8")[]uint8 win.OpenInExplorer("C:\\Users\\yoby\\Desktop")//打开目录 win.RunAsAdministrator(php.GetPath()+"/cfg/ll.exe", "", "")//y运行程序 参数2是参数 3是目录留空
获取剪贴板内容
str := vcl.Clipboard.AsText()
str := ""
vcl.Clipboard.GetTextBuf(&str, 1000)
设置剪贴板vcl.Clipboard.SetAsText("afdsdf")
文本框设置值f.Edit1.SetText("设置内容")
文本框获取值s:="" f.Edit1.GetTextBuf(&s,1000)
显示图片 f.Image1.Picture().LoadFromFile(“Desktop/qr.png”)
选择颜色
dlColor := vcl.NewColorDialog(f)
if dlColor.Execute() {
vcl.ShowMessageFmt(“%s”,dlColor.Color())
}
//打开选择系统对话框 TOpenDialog 其他几个类似图片OpenPictureDialog
"文本文件(*.txt)|*.txt|所有文件(*.*)|*.*"
f1:=vcl.NewOpenDialog(f)
f1.SetFilter("文本文件(*.png;*.jpg)|*.png;*.jpg")
f1.SetTitle("选择图片")
if f1.Execute() {
s:=f1.FileName()
vcl.ShowMessage("计算的sha1已经复制到剪切板了:"+s)
}
s := vcl.Application.Location() //当前exe路径目录
rtl.SysOpen("https://www.yoby123.cn") 打开网址
rtl.SysOpen(vcl.Application.Location() + "\\res\\CapScreen.exe") 打开应用
win.ShellExecute(0, "OPEN", vcl.Application.Location()+`/ng/ng.vbs`, "", vcl.Application.Location()+`/ng/`, win.SW_HIDE) //执行vbs专用,在某个目录执行
读取配置ini
ini := vcl.NewIniFile(".\\test.ini")
defer ini.Free()
ini.WriteBool("a", "bool", true)
ini.WriteString("a", "String", "中国")
ini.WriteInteger("a", "int", 123456)
ini.WriteFloat("a", "fl", 1.2555)
b := ini.ReadBool("a", "bool", false)
c := ini.ReadString("a", "String", "")
it := ini.ReadInteger("a", "int", 0)
fl := ini.ReadFloat("a", "fl", 0)
fmt.Println(c, b, it, fl)