Golang Windows GUI Bindings Like Delphi VCL
Windows的GUI界面Go语言封装,目标是实现一个类似Delphi VCL版本效果的界面库
typeGForm1struct {
controls.GFormButton1*controls.GButtonEdit1*controls.GEdit
}
funcNewForm1(app*controls.WApplication)*GForm1{
frm:=new(GForm1)
frm.SubInit()
frm.Button1=controls.NewButton(frm)
frm.Button1.SetWidth(80)
frm.Button1.SetHeight(30)
frm.Button1.SetLeft(frm.Width() -90)
frm.Button1.SetTop(frm.Height() -80)
frm.Button1.SetCaption("确定关闭")
frm.Edit1=controls.NewEdit(frm)
frm.OnClose=func(senderinterface{},closeAction*int8) {
*closeAction=controls.CAFree
}
frm.Button1.OnClick=func(senderinterface{}) {
WinApi.MessageBox(frm.GetWindowHandle(),"sadf","Asdf",64)
frm.SetModalResult(controls.MrOK)
}
returnfrm
}
funcmain() {
app:=new(controls.WApplication)
app.ShowMainForm=truem:=app.CreateForm()
m.SetLeft(200)
m.SetTop(50)
m.SetCaption("测试窗体")
e:=controls.NewEdit(m)
e.SetName("Edit1")
e.SetLeft(10)
e.SetWidth(100)
e.SetHeight(20)
e.SetCaption("测试")
b:=controls.NewButton(m)
b.SetDefault(true)
b.SetLeft(120)
b.SetCaption("创建窗体")
b.OnClick=func(senderinterface{}) {
tmpm:=NewForm1(app)
tmpm.SetCaption(e.GetText())
iftmpm.ShowModal() ==controls.MrOK{
WinApi.MessageBox(tmpm.GetWindowHandle(),"程序确定退出","消息",64)
}
}
b1:=controls.NewButton(m)
b1.SetCaption("关闭")
b1.SetLeft(100)
b1.SetTop(40)
b1.OnClick=func(senderinterface{}) {
b.SetVisible(!b.Visible())
b.SetCaption("测试")
}
app.Run()
}<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<assemblyxmlns="urn:schemas-microsoft-com:asm.v1"manifestVersion="1.0">
<assemblyIdentityversion="1.0.0.0"processorArchitecture="*"name="SomeFunkyNameHere"type="win32"/>
<dependency>
<dependentAssembly>
<assemblyIdentitytype="win32"name="Microsoft.Windows.Common-Controls"version="6.0.0.0"processorArchitecture="*"publicKeyToken="6595b64144ccf1df"language="*"/>
</dependentAssembly>
</dependency>
</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.
使用Go Build 建立文件,会将这个manifest资源包含进去,以使用系统皮肤
b1.Font.BeginUpdate()
b1.Font.SetSize(10)
b1.Font.Underline=1b1.Font.EndUpdate()菜单使用方法
//菜单pop:=NVisbleControls.NewPopupMenu(m)
tmpitem:=pop.Items().AddItem("测试1")
citem:=tmpitem.AddItem("子测试1")
citem.OnClick=func(senderinterface{}) {
WinApi.MessageBox(m.GetWindowHandle(),"菜单测试"+sender.(*NVisbleControls.GMenuItem).Caption(),"消息",64)
}
citem=pop.Items().AddItem("测试2")
citem.OnClick=func(senderinterface{}) {
WinApi.MessageBox(m.GetWindowHandle(),"菜单测试"+sender.(*NVisbleControls.GMenuItem).Caption(),"消息",64)
}
m.PopupMenu=pop目前整体组件框架已经具备雏形,要增加其他组件库按照扩展的Button和Edit以及Label增加则可,下一步做完托盘就暂时放一段落
//菜单pop:=NVisbleControls.NewPopupMenu(m)
tmpitem:=pop.Items().AddItem("测试1")
citem:=tmpitem.AddItem("子测试1")
citem.OnClick=func(senderinterface{}) {
WinApi.MessageBox(m.GetWindowHandle(),"菜单测试"+sender.(*NVisbleControls.GMenuItem).Caption(),"消息",64)
}
citem=pop.Items().AddItem("测试2")
citem.OnClick=func(senderinterface{}) {
WinApi.MessageBox(m.GetWindowHandle(),"菜单测试"+sender.(*NVisbleControls.GMenuItem).Caption(),"消息",64)
}
//托盘图标,结合弹出菜单icon:=NVisbleControls.NewTrayIcon(m)
icon.SetIcon(app.AppIcon()) //设置托盘图标//icon.SetIcon(WinApi.LoadIcon(controls.Hinstance,uintptr(5))) icon.SetVisible(true)
icon.PopupMenu=pop//设置托盘的右键弹出菜单icon.OnDblClick=func(senderinterface{}) {
if!m.Visible(){
m.Show()
}else{
m.SetVisible(false)
}
}reg := NVisbleControls.NewRegistry(0)
reg.SetRootKey(WinApi.HKEY_LOCAL_MACHINE)
if reg.OpenKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run",false){
if reg.ValueExists("SynTPEnh"){
WinApi.MessageBox(m.GetWindowHandle(),"SynTPEnh自动启动: "+reg.ReadString("SynTPEnh"),"消息",64) }
WinApi.MessageBox(m.GetWindowHandle(),"打开注册表测试"+sender.(*NVisbleControls.GMenuItem).Caption(),"消息",6)
}
reg.Free()
