-
Notifications
You must be signed in to change notification settings - Fork 0
/
notifyicon.go
119 lines (108 loc) · 2.41 KB
/
notifyicon.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
package main
import (
"bytes"
_ "embed"
"fmt"
"github.com/lxn/walk"
"image"
_ "image/png"
"log"
"os"
"syscall"
"time"
"unsafe"
)
//go:embed static/favicon.png
var iconfile []byte
func GuiInit() {
mw, err := walk.NewMainWindow()
if err != nil {
log.Fatal(err)
}
//托盘图标文件
img, _, err := image.Decode(bytes.NewReader(iconfile))
icon, _ := walk.NewIconFromImageForDPI(img, 64)
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("hotkeysleep \n使用方法:win+s睡眠 win+p休眠\n作者:GavinGao \nQQ:3042752146"); err != nil {
log.Fatal(err)
}
ni.MouseDown().Attach(func(x, y int, button walk.MouseButton) {
if button != walk.LeftButton {
return
}
if err := ni.ShowCustom(
"hotkeysleep",
"hotkeysleep 已运行",
icon); err != nil {
log.Fatal(err)
}
})
go func() {
for {
if 1 == <-ch {
if err := ni.ShowCustom(
"现在时间",
time.Now().Format("15:04:05"),
icon); err != nil {
log.Fatal(err)
}
}
}
}()
go func() {
for {
if 1 == <-chs {
Timespeak()
}
}
}()
aboutAction := walk.NewAction()
if err := aboutAction.SetText("关于"); err != nil {
log.Fatal(err)
}
//about 实现的功能
aboutAction.Triggered().Attach(func() {
walk.MsgBox(mw, "关于",
"hotkeysleep \n使用方法:win+s睡眠 win+p休眠\n作者:GavinGao \nQQ:3042752146",
walk.MsgBoxOK)
}) //如何能够复制提示信息呢???
exitAction := walk.NewAction()
if err := exitAction.SetText("退出"); err != nil {
log.Fatal(err)
}
//Exit 实现的功能
exitAction.Triggered().Attach(func() { walk.App().Exit(0) })
exitAction.Triggered().Attach(func() { os.Exit(1) })
if err := ni.ContextMenu().Actions().Add(exitAction); err != nil {
log.Fatal(err)
}
if err := ni.ContextMenu().Actions().Add(aboutAction); err != nil {
log.Fatal(err)
}
if err := ni.SetVisible(true); err != nil {
log.Fatal(err)
}
if err := ni.ShowInfo("hotkeysleep", "hotkeysleep 运行中"); err != nil {
log.Fatal(err)
}
mw.Run()
}
func Timespeak() {
fmt.Println("语音报时提示")
SpeakText("你好,世界!")
}
func SpeakText(text string){
ttsdll:=syscall.NewLazyDLL("tts.dll")
speak:=ttsdll.NewProc("rapidSpeakText")
speak.Call(uintptr(unsafe.Pointer(syscall.StringToUTF16Ptr(text))))
}