func main() { hWindow = xcgui.XWnd_Create(0, 0, 0, 0, "炫彩界面库窗口", 0, xcgui.XC_WINDOW_STYLE_NOTHING) // We load our icon from a file. icon, err := walk.NewIconFromFile("../../img/x.ico") if err != nil { log.Fatal(err) } // Create the notify icon and make sure we clean it up on exit. ni, err = walk.NewNotifyIcon() if err != nil { log.Fatal(err) } defer ni.Dispose() // Set the icon and a tool tip text. if err := ni.SetIcon(icon); err != nil { log.Fatal(err) } if err := ni.SetToolTip("托盘"); err != nil { log.Fatal(err) } // When the left mouse button is pressed, bring up our balloon. ni.MouseDown().Attach(func(x, y int, button walk.MouseButton) { if button == walk.LeftButton { if err := ni.ShowCustom( "自定义消息", "这是一个带图标的自定义消息."); err != nil { log.Fatal(err) } } else { RunXCMenu() } }) // 托盘图标默认为隐藏状态,需设置为显示。 if err := ni.SetVisible(true); err != nil { log.Fatal(err) } // Now that the icon is visible, we can bring up an info balloon. if err := ni.ShowInfo("托盘", "正在运行中."); err != nil { log.Fatal(err) } // 注册菜单选择事件 xcgui.XWnd_RegEventC(hWindow, xcgui.XWM_MENU_SELECT, xcgui.CallBack(OnWndMenuSelect)) // Run the message loop. xcgui.XRunXCGUI() }
// 托盘图标 func (mw *MyWindow) addNotyfyAction() { var err error mw.notifyIcon, err = walk.NewNotifyIcon() checkError(err) mw.notifyIcon.SetVisible(true) exitAction := walk.NewAction() exitAction.SetText("退出程序") exitAction.Triggered().Attach(func() { mw.exit() }) mw.notifyIcon.ContextMenu().Actions().Add(exitAction) }
func (mw *MyDialog) SetMyNotify() (err error) { // 托盘图标 icon, _ := walk.NewIconFromResourceId(3) mw.ni, err = walk.NewNotifyIcon() mw.checkError(err) mw.SetIcon(icon) // Set the icon and a tool tip text. err = mw.ni.SetIcon(icon) mw.checkError(err) return nil }
func newNotify() { var err error context.notifyIcon, err = walk.NewNotifyIcon() if err != nil { common.Error("Error invoking NewNotifyIcon: %v", err) } icon, _ := walk.NewIconFromFile("res/lily.ico") if err := context.notifyIcon.SetIcon(icon); err != nil { common.Error("Error setting notify icon: %v", err) } if err := context.notifyIcon.SetToolTip("Click for info or use the context menu to exit."); err != nil { common.Error("Fail to set tooltip: %v", err) } f := func() { if !context.mw.Visible() { context.mw.Show() } else { context.mw.SwitchToThisWindow() } } go core.Triggered(f) context.notifyIcon.MouseUp().Attach(func(x, y int, button walk.MouseButton) { if button == walk.LeftButton { f() } // if err := context.notifyIcon.ShowCustom( // "Walk NotifyIcon Example", // "There are multiple ShowX methods sporting different icons."); err != nil { // common.Error("Fail to show custom notify: %v", err) // } }) exitAction := walk.NewAction() if err := exitAction.SetText("退出"); err != nil { common.Error("Error setting exitAction text: %v", err) } exitAction.Triggered().Attach(func() { context.notifyIcon.Dispose() // os.Exit(-1) walk.App().Exit(0) }) if err := context.notifyIcon.ContextMenu().Actions().Add(exitAction); err != nil { common.Error("Error Adding exitAction: %v", err) } if err := context.notifyIcon.SetVisible(true); err != nil { common.Error("Error setting notify visible: %v", err) } // if err := context.notifyIcon.ShowInfo("Walk NotifyIcon Example", "Click the icon to show again."); err != nil { // common.Error("Error showing info: %v", err) // } }
func NewMainWindow() *MyWindows { mw := new(MyWindows) mw.MainWindow, _ = walk.NewMainWindow() mw.ni, err = walk.NewNotifyIcon() checkErr(err) icon, _ := walk.NewIconFromResourceId(3) mw.setVipIcon(icon) mw.addAction() mw.ni.SetVisible(true) return mw }
func main() { // Initialize walk and specify that we want errors to be panics. walk.Initialize(walk.InitParams{PanicOnError: true}) defer walk.Shutdown() // We need either a walk.MainWindow or a walk.Dialog for their message loop. // We will not make it visible in this example, though. mw, _ := walk.NewMainWindow() // We load our icon from a file. icon, _ := walk.NewIconFromFile("../img/x.ico") // Create the notify icon and make sure we clean it up on exit. ni, _ := walk.NewNotifyIcon() defer ni.Dispose() // Set the icon and a tool tip text. ni.SetIcon(icon) ni.SetToolTip("Click for info or use the context menu to exit.") // When the left mouse button is pressed, bring up our balloon. ni.MouseDown().Attach(func(x, y int, button walk.MouseButton) { if button != walk.LeftButton { return } ni.ShowCustom( "Walk NotifyIcon Example", "There are multiple ShowX methods sporting different icons.") }) // We put an exit action into the context menu. exitAction := walk.NewAction() exitAction.SetText("E&xit") exitAction.Triggered().Attach(func() { walk.App().Exit(0) }) ni.ContextMenu().Actions().Add(exitAction) // The notify icon is hidden initially, so we have to make it visible. ni.SetVisible(true) // Now that the icon is visible, we can bring up an info balloon. ni.ShowInfo("Walk NotifyIcon Example", "Click the icon to show again.") // Run the message loop. mw.Run() }
func (mw *MyDialog) setMyNotify() (err error) { // 托盘图标 // icon, _ := walk.NewIconFromFile("../../img/main.ico") icon, _ := walk.NewIconFromResourceId(3) mw.ni, err = walk.NewNotifyIcon() mw.checkError(err) mw.SetIcon(icon) // Set the icon and a tool tip text. err = mw.ni.SetIcon(icon) mw.checkError(err) mw.ni.SetToolTip("测试程序") // The notify icon is hidden initially, so we have to make it visible. err = mw.ni.SetVisible(false) mw.checkError(err) return nil }
func runNotify() { // We need either a walk.MainWindow or a walk.Dialog for their message loop. // We will not make it visible in this example, though. mw, err := walk.NewMainWindow() if err != nil { log.Fatal(err) } // We load our icon from a file. iconPlay, err = walk.NewIconFromFile("play.ico") if err != nil { log.Fatal(err) } // We load our icon from a file. iconStop, err = walk.NewIconFromFile("stop.ico") if err != nil { log.Fatal(err) } // Create the notify icon and make sure we clean it up on exit. notifyIcon, err = walk.NewNotifyIcon() if err != nil { log.Fatal(err) } defer notifyIcon.Dispose() if err := notifyIcon.SetToolTip("Direct Print Server"); err != nil { log.Fatal(err) } // We put an exit action into the context menu. startAction = walk.NewAction() startAction.Triggered().Attach(func() { if stoped { start() } else { stop() } }) if err := notifyIcon.ContextMenu().Actions().Add(startAction); err != nil { log.Fatal(err) } // We put an exit action into the context menu. exitAction := walk.NewAction() if err := exitAction.SetText("E&xit"); err != nil { log.Fatal(err) } exitAction.Triggered().Attach(func() { //stop() walk.App().Exit(0) }) if err := notifyIcon.ContextMenu().Actions().Add(exitAction); err != nil { log.Fatal(err) } // The notify icon is hidden initially, so we have to make it visible. if err := notifyIcon.SetVisible(true); err != nil { log.Fatal(err) } start() // Run the message loop. mw.Run() }
func InterfaceStart(server ZakupkiProxyServer, config ServerConfig) (err error) { if server == nil { panic("InterfaceStart: passed nil server") } if config == nil { panic("InterfaceStart: passed nil config") } /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * INITIALIZATION * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ startServer := func() { if !server.IsRunning() { go func() { // start server if err := server.Start(); err != nil { log.Println("Cannot start server:", err) } }() time.Sleep(_START_SERVER_TIMEOUT) } } stopServer := func() { if server.IsRunning() { // shutdown server if err = server.ShutDown(); err != nil { log.Println("Cannot shutdown server", err) } } } if _RUN_SERVER_ON_STARTING && !server.IsRunning() { startServer() } defer func() { if server.IsRunning() { stopServer() } }() defer func() { if err = config.Save(); err != nil { log.Println("Cannot save configures:", err) } }() /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * END INITIALIZATION * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ mw, err := walk.NewMainWindow() if err != nil { return } defer mw.Dispose() ni, err := walk.NewNotifyIcon() if err != nil { return } defer ni.Dispose() if err = ni.SetVisible(true); err != nil { return } if err = ni.SetToolTip(_PROG_TITLE); err != nil { return } ni.ShowMessage(_PROG_TITLE, _NOTICE_APP_START) // create image icon if icon, err := walk.NewIconFromFile(_PROG_ICON_FILE_NAME); err != nil { log.Println("Cannot load icon from file:", err) } else { defer icon.Dispose() if err = ni.SetIcon(icon); err != nil { log.Println("Cannot bind img with notify icon:", err) } } /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * ACTIONS * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ startServerAction := walk.NewAction() err = startServerAction.SetText(_ACTION_TITLE_START_SERVER) if err != nil { return } err = startServerAction.SetVisible(!server.IsRunning()) if err != nil { return } err = ni.ContextMenu().Actions().Add(startServerAction) if err != nil { return } stopServerAction := walk.NewAction() err = stopServerAction.SetText(_ACTION_TITLE_STOP_SERVER) if err != nil { return } err = stopServerAction.SetVisible(server.IsRunning()) if err != nil { return } err = ni.ContextMenu().Actions().Add(stopServerAction) if err != nil { return } filterEnableAction := walk.NewAction() err = filterEnableAction.SetText(_ACTION_TITLE_FILTER_ENABLED) if err != nil { return } err = filterEnableAction.SetVisible(!config.IsFilterEnabled()) if err != nil { return } err = ni.ContextMenu().Actions().Add(filterEnableAction) if err != nil { return } filterDisabledAction := walk.NewAction() err = filterDisabledAction.SetText(_ACTION_TITLE_FILTER_DISABLED) if err != nil { return } err = filterDisabledAction.SetVisible(config.IsFilterEnabled()) if err != nil { return } err = ni.ContextMenu().Actions().Add(filterDisabledAction) if err != nil { return } removeCacheAction := walk.NewAction() err = removeCacheAction.SetText(_ACTION_TITLE_REMOVE_CACHE) if err != nil { return } err = ni.ContextMenu().Actions().Add(removeCacheAction) if err != nil { return } err = ni.ContextMenu().Actions().Add(walk.NewSeparatorAction()) if err != nil { return } openURLGenAction := walk.NewAction() err = openURLGenAction.SetText(_ACTION_TITLE_OPEN_URL_GEN) if err != nil { return } err = ni.ContextMenu().Actions().Add(openURLGenAction) if err != nil { return } openDirAction := walk.NewAction() err = openDirAction.SetText(_ACTION_TITLE_OPEN_DIR) if err != nil { return } err = ni.ContextMenu().Actions().Add(openDirAction) if err != nil { return } openReadMeAction := walk.NewAction() err = openReadMeAction.SetText(_ACTION_TITLE_OPEN_README) if err != nil { return } err = ni.ContextMenu().Actions().Add(openReadMeAction) if err != nil { return } err = ni.ContextMenu().Actions().Add(walk.NewSeparatorAction()) if err != nil { return } exitAction := walk.NewAction() err = exitAction.SetText(_ACTION_TITLE_EXIT) if err != nil { return } err = ni.ContextMenu().Actions().Add(exitAction) if err != nil { return } /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * EVENT HANDLERS * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ updateServerButtons := func() { if server.IsRunning() { if err = startServerAction.SetVisible(false); err != nil { log.Println(err) } if err = stopServerAction.SetVisible(true); err != nil { log.Println(err) } } else { if err = stopServerAction.SetVisible(false); err != nil { log.Println(err) } if err = startServerAction.SetVisible(true); err != nil { log.Println(err) } } } startServerAction.Triggered().Attach(func() { if !server.IsRunning() { if err = startServerAction.SetEnabled(false); err != nil { log.Println(err) } startServer() if server.IsRunning() { ni.ShowMessage(_PROG_TITLE, _NOTICE_PROXY_ENABLED) } if err = startServerAction.SetEnabled(true); err != nil { log.Println(err) } } updateServerButtons() }) stopServerAction.Triggered().Attach(func() { if server.IsRunning() { stopServer() ni.ShowMessage(_PROG_TITLE, _NOTICE_PROXY_DISABLED) } updateServerButtons() }) updateFilterButtons := func() { if config.IsFilterEnabled() { err = filterEnableAction.SetVisible(false) if err != nil { log.Println(err) } err = filterDisabledAction.SetVisible(true) if err != nil { log.Println(err) } } else { err = filterDisabledAction.SetVisible(false) if err != nil { log.Println(err) } err = filterEnableAction.SetVisible(true) if err != nil { log.Println(err) } } } filterEnableAction.Triggered().Attach(func() { if !config.IsFilterEnabled() { config.SetFilterEnabled(true) ni.ShowInfo(_PROG_TITLE, _NOTICE_ENABLED_FILTERS) } updateFilterButtons() }) filterDisabledAction.Triggered().Attach(func() { if config.IsFilterEnabled() { config.SetFilterEnabled(false) ni.ShowInfo(_PROG_TITLE, _NOTICE_DISABLED_FILTERS) } updateFilterButtons() }) removeCacheAction.Triggered().Attach(func() { if err = server.RemoveCache(); err != nil { log.Println("Cannot remove cache:", err) } else { ni.ShowInfo(_PROG_TITLE, _NOTICE_CACHE_REMOVED) } }) openURLGenAction.Triggered().Attach(func() { err = exec.Command(_PROG_URL_GENER_FILE_NAME).Start() if err != nil { log.Println("Cannot open url generator:", err) } }) openDirAction.Triggered().Attach(func() { err = exec.Command("cmd", "/C", "start", ".").Start() if err != nil { log.Println("Cannot open program directory:", err) } else { ni.ShowInfo(_PROG_TITLE, _NOTICE_CONFIGS) } }) openReadMeAction.Triggered().Attach(func() { err = exec.Command( "cmd", "/C", "start", _PROG_DESCRIPTION_FILE_NAME, ).Start() if err != nil { log.Println("Cannot open README:", err) } }) exitAction.Triggered().Attach(func() { walk.App().Exit(0) }) /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * END EVENT HANDLERS * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ mw.Run() return }
func main() { xcgui.XWnd_Create(0, 0, 0, 0, "炫彩界面库窗口", 0, xcgui.XC_WINDOW_STYLE_NOTHING) // We load our icon from a file. icon, err := walk.NewIconFromFile("../../img/x.ico") if err != nil { log.Fatal(err) } // Create the notify icon and make sure we clean it up on exit. ni, err := walk.NewNotifyIcon() if err != nil { log.Fatal(err) } defer ni.Dispose() // Set the icon and a tool tip text. if err := ni.SetIcon(icon); err != nil { log.Fatal(err) } if err := ni.SetToolTip("托盘"); err != nil { log.Fatal(err) } // When the left mouse button is pressed, bring up our balloon. ni.MouseDown().Attach(func(x, y int, button walk.MouseButton) { if button != walk.LeftButton { return } if err := ni.ShowCustom( "自定义消息", "这是一个带图标的自定义消息."); err != nil { log.Fatal(err) } }) // 菜单使用walk的,主程序为xcgui. exitAction := walk.NewAction() if err := exitAction.SetText("退出"); err != nil { log.Fatal(err) } exitAction.Triggered().Attach(func() { ni.Dispose() walk.App().Exit(0) xcgui.XExitXCGUI() }) if err := ni.ContextMenu().Actions().Add(exitAction); err != nil { log.Fatal(err) } // 托盘图标默认为隐藏状态,需设置为显示。 if err := ni.SetVisible(true); err != nil { log.Fatal(err) } // Now that the icon is visible, we can bring up an info balloon. if err := ni.ShowInfo("托盘", "正在运行中."); err != nil { log.Fatal(err) } // Run the message loop. xcgui.XRunXCGUI() }