简单说明:通知图标demo,原文都有注释,很好理解

需要一个walk.MainWindow 或一个walk.Dialog用于他们的消息循环。但是本例中让MainWindow 不可见。

创建通知图标,并确保在退出时将其清除

// 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)}

notifyicon.go

// 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 mainimport ("log"
)import ("github.com/lxn/walk"
)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("../img/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()
}

Go GUI---lxn/walk 自带demo学习---16.notifyicon通知图标相关推荐

  1. Go GUI---lxn/walk 自带demo学习---7.文件浏览器

    如上图,从左到右用来TreeView.TableView.WebView 定义了一个名为Directory的目录结构体,每个目录理论上有一个父节点,有0到n个子节点. type Directory s ...

  2. Py:python利用easygui实现最简单GUI带你学习区块链技术的发展和由来

    Py:python利用easygui实现最简单GUI带你学习区块链技术的发展和由来 目录 输出结果 实现代码 输出结果 实现代码 # -*- coding: utf-8 -*- ''' Created ...

  3. Go实战--使用golang开发Windows Gui桌面程序(lxn/walk)

    生命不止,继续 go go go!!! golang官方并没有提供Windows gui库,但是今天还是要跟大家分享一下使用golang开发Windows桌面程序,当然又是面向github编程了. 知 ...

  4. RPG游戏Demo学习笔记一

    导航 RPG游戏Demo学习笔记一 UE笔记 -- 一个简单的AI_weixin_52918492的博客-CSDN博客 目录 一.准备资源 二.基础功能 生命值与能量值 创建Widget Bluepr ...

  5. 微信语音idk的demo学习

    微信语音idk的demo学习 1. if ([[[UIDevice currentDevice]systemVersion]floatValue]>=7) { NSLog(@"%f&q ...

  6. 通过demo学习OpenStack开发——单元测试

    本文将进入单元测试的部分,这也是基础知识中最后一个大块.本文将重点讲述Python和OpenStack中的单元测试的生态环境. 通过demo学习OpenStack开发--单元测试\ 单元测试的重要性\ ...

  7. android vlayout 阿里,带你学习阿里巴巴的开源库VLayout

    原标题:带你学习阿里巴巴的开源库VLayout 今日科技快讯 14日,京东在总部召开"京东游戏泛娱乐产业联盟发布会",宣布完成对原LPL(英雄联盟职业联赛)队伍QG战队及LSPL( ...

  8. 如何用excle制作黑人拉馆_家居DIY带你学习如何用塑料勺制作壁挂!

    「家居DIY」带你学习如何用塑料勺制作壁挂! DIY生活馆图片展示内容介绍 传承手工艺术,放飞指尖梦想,每一节教学我们都会认真对待!只为传递手工技艺,动手实践能够让生活更美好,它让这一平淡的生活眼前一 ...

  9. gateway 内存溢出问题_带你学习jvm java虚拟机 arthas/性能调优/故障排除/gc回收/内存溢出等...

    学完本课程,您将掌握: 内存溢出问题实战 CPU飙升问题实战 阿里巴巴Arthas在线诊断 Class字节详细拆解 手写类加载器.四种类加载器.双亲委托模型 对象创建.存储.访问.加载解析 性能调优. ...

最新文章

  1. 用再生龙Clonezilla 来克隆Linux
  2. comparator java_java:Comparator比较器
  3. Scanner如何接受char类型的数据
  4. Android MediaRecorder系统结构
  5. r语言数据变量分段_R数据分析:用R语言做meta分析
  6. 如何获取图像的驱动_Adobe Camera Raw 12 Mac(Raw格式图像ps插件) v12.2.1.417
  7. InnoDB原理篇:为什么使用索引会变快?
  8. 面试:一文搞懂重载和重写的区别
  9. UDK编辑器 49条小提示(转)
  10. SharePoint2013更改网站集端口方法
  11. 从零开始搭建轻量级JavaWeb框架
  12. 软件测试---如何选择合适的正交表
  13. xposed框架_免ROOT 用“太极”替代Xposed框架
  14. 今日干货:PDF转Word工具有哪些?
  15. SAP 采购订单入库——库存查询
  16. VFB组件:MonthCalendar控件(月日历)
  17. 基于学生信息管理系统的数据库系统课程设计升级版(mysql)
  18. 基于迭代情绪交互网络的对话情绪识别
  19. 删除对象属性的三种方法
  20. VLAN、VXLAN

热门文章

  1. 阿里天池心跳信号分类预测baseline
  2. TCP/IP协议是什么计算机网络基础理论
  3. MT【118】利用线面角最小解题
  4. PiFlow 朱小杰:科学家更爱开源 | Gitee 封面人物第 19 期
  5. 定积分的基本性质6 积分第一中值定理
  6. CTA入网认证业务办理
  7. arm云服务器虚拟安卓,ARM搭建云手机
  8. 5月14日国内主流平台数字藏品发售日报
  9. 英语语法(1)——简单句
  10. B. Shifting Sort(rotate函数旋转应用)