forked from go/golangs_learn
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
74 lines
1.5 KiB
74 lines
1.5 KiB
package main
|
|
|
|
import (
|
|
"github.com/lxn/walk"
|
|
"log"
|
|
)
|
|
|
|
func (mw *myApp) AddNotifyIcon() {
|
|
var err error
|
|
mw.ni, err = walk.NewNotifyIcon(mw)
|
|
checkError(err)
|
|
mw.ni.SetVisible(true)
|
|
|
|
icon, err := walk.NewIconFromResourceId(3)
|
|
checkError(err)
|
|
mw.SetIcon(icon)
|
|
mw.ni.SetIcon(icon)
|
|
|
|
sjMenu := mw.addMenu("数据库")
|
|
service1.menuStart = mw.addAction(sjMenu, "启动")
|
|
service1.menuStop = mw.addAction(sjMenu, "停止")
|
|
|
|
service1.menuStart.Triggered().Attach(func() {
|
|
startService(service1)
|
|
})
|
|
service1.menuStop.Triggered().Attach(func() {
|
|
stopService(service1)
|
|
})
|
|
|
|
cxMenu := mw.addMenu("应用")
|
|
service3.menuStart = mw.addAction(cxMenu, "启动")
|
|
service3.menuStop = mw.addAction(cxMenu, "停止")
|
|
service3.menuStart.Triggered().Attach(func() {
|
|
startService(service3)
|
|
})
|
|
service3.menuStop.Triggered().Attach(func() {
|
|
stopService(service3)
|
|
})
|
|
|
|
mw.addAction(nil, "exit").Triggered().Attach(func() {
|
|
mw.ni.Dispose()
|
|
mw.Dispose()
|
|
walk.App().Exit(0)
|
|
})
|
|
|
|
}
|
|
|
|
func (mw *myApp) addMenu(name string) *walk.Menu {
|
|
helpMenu, err := walk.NewMenu()
|
|
checkError(err)
|
|
help, err := mw.ni.ContextMenu().Actions().AddMenu(helpMenu)
|
|
checkError(err)
|
|
help.SetText(name)
|
|
|
|
return helpMenu
|
|
}
|
|
|
|
func (mw *myApp) addAction(menu *walk.Menu, name string) *walk.Action {
|
|
action := walk.NewAction()
|
|
action.SetText(name)
|
|
if menu != nil {
|
|
menu.Actions().Add(action)
|
|
} else {
|
|
mw.ni.ContextMenu().Actions().Add(action)
|
|
}
|
|
|
|
return action
|
|
}
|
|
|
|
func checkError(err error) {
|
|
if err != nil {
|
|
log.Fatal(err)
|
|
}
|
|
}
|
|
|