forked from go/golangs_learn
				
			
				 8 changed files with 217 additions and 16 deletions
			
			
		| 
		 After Width: | Height: | Size: 66 KiB  | 
@ -0,0 +1,61 @@ | 
				
			|||
package main | 
				
			|||
 | 
				
			|||
import ( | 
				
			|||
	"github.com/lxn/walk" | 
				
			|||
	"log" | 
				
			|||
) | 
				
			|||
 | 
				
			|||
// TODO 报错
 | 
				
			|||
func main() { | 
				
			|||
	GuiInit() | 
				
			|||
} | 
				
			|||
 | 
				
			|||
func GuiInit() { | 
				
			|||
	mw, err := walk.NewMainWindow() | 
				
			|||
	if err != nil { | 
				
			|||
		log.Fatal(err) | 
				
			|||
	} | 
				
			|||
	//托盘图标文件
 | 
				
			|||
	icon, err := walk.Resources.Icon("./icon.ico") | 
				
			|||
	if err != nil { | 
				
			|||
		log.Fatal(err) | 
				
			|||
	} | 
				
			|||
	ni, err := walk.NewNotifyIcon(mw) | 
				
			|||
	if err != nil { | 
				
			|||
		log.Fatal(err) | 
				
			|||
	} | 
				
			|||
	defer ni.Dispose() | 
				
			|||
	if err := ni.SetIcon(icon); err != nil { | 
				
			|||
		log.Fatal(err) | 
				
			|||
	} | 
				
			|||
	if err := ni.SetToolTip("鼠标在icon上悬浮的信息."); err != nil { | 
				
			|||
		log.Fatal(err) | 
				
			|||
	} | 
				
			|||
	ni.MouseDown().Attach(func(x, y int, button walk.MouseButton) { | 
				
			|||
		if button != walk.LeftButton { | 
				
			|||
			return | 
				
			|||
		} | 
				
			|||
		if err := ni.ShowCustom( | 
				
			|||
			"Walk 任务栏通知标题", | 
				
			|||
			"walk 任务栏通知内容", | 
				
			|||
			icon); err != nil { | 
				
			|||
			log.Fatal(err) | 
				
			|||
		} | 
				
			|||
	}) | 
				
			|||
	exitAction := walk.NewAction() | 
				
			|||
	if err := exitAction.SetText("右键icon的菜单按钮"); err != nil { | 
				
			|||
		log.Fatal(err) | 
				
			|||
	} | 
				
			|||
	//Exit 实现的功能
 | 
				
			|||
	exitAction.Triggered().Attach(func() { walk.App().Exit(0) }) | 
				
			|||
	if err := ni.ContextMenu().Actions().Add(exitAction); err != nil { | 
				
			|||
		log.Fatal(err) | 
				
			|||
	} | 
				
			|||
	if err := ni.SetVisible(true); err != nil { | 
				
			|||
		log.Fatal(err) | 
				
			|||
	} | 
				
			|||
	if err := ni.ShowInfo("Walk NotifyIcon Example", "Click the icon to show again."); err != nil { | 
				
			|||
		log.Fatal(err) | 
				
			|||
	} | 
				
			|||
	mw.Run() | 
				
			|||
} | 
				
			|||
@ -0,0 +1,79 @@ | 
				
			|||
// Copyright 2011 The Walk Authors. All rights reserved.
 | 
				
			|||
// Use of this source code is governed by a BSD-style
 | 
				
			|||
// license that can be found in the LICENSE file.
 | 
				
			|||
 | 
				
			|||
package main | 
				
			|||
 | 
				
			|||
import ( | 
				
			|||
	"github.com/lxn/walk" | 
				
			|||
	"log" | 
				
			|||
) | 
				
			|||
 | 
				
			|||
// TODO 报错
 | 
				
			|||
func main() { | 
				
			|||
	// 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.
 | 
				
			|||
	icon, err := walk.Resources.Icon("E://stop.ico") | 
				
			|||
	if err != nil { | 
				
			|||
		log.Fatal(err) | 
				
			|||
	} | 
				
			|||
 | 
				
			|||
	// Create the notify icon and make sure we clean it up on exit.
 | 
				
			|||
	ni, err := walk.NewNotifyIcon(mw) | 
				
			|||
	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("Click for info or use the context menu to exit."); 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( | 
				
			|||
			"Walk NotifyIcon Example", | 
				
			|||
			"There are multiple ShowX methods sporting different icons.", | 
				
			|||
			icon); 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() { walk.App().Exit(0) }) | 
				
			|||
	if err := ni.ContextMenu().Actions().Add(exitAction); err != nil { | 
				
			|||
		log.Fatal(err) | 
				
			|||
	} | 
				
			|||
 | 
				
			|||
	// The notify icon is hidden initially, so we have to make it visible.
 | 
				
			|||
	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("Walk NotifyIcon Example", "Click the icon to show again."); err != nil { | 
				
			|||
		log.Fatal(err) | 
				
			|||
	} | 
				
			|||
 | 
				
			|||
	// Run the message loop.
 | 
				
			|||
	mw.Run() | 
				
			|||
} | 
				
			|||
| 
		 After Width: | Height: | Size: 66 KiB  | 
| 
		 After Width: | Height: | Size: 66 KiB  | 
					Loading…
					
					
				
		Reference in new issue