-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpop.go
More file actions
40 lines (36 loc) · 954 Bytes
/
Copy pathpop.go
File metadata and controls
40 lines (36 loc) · 954 Bytes
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
package main
import (
"github.com/go-toast/toast"
"log"
"syscall"
"unsafe"
)
func IntPtr(n int) uintptr {
return uintptr(n)
}
func StrPtr(s string) uintptr {
return uintptr(unsafe.Pointer(syscall.StringToUTF16Ptr(s)))
}
// ShowMessage windows下的另一种DLL方法调用
func ShowMessage(title, text string) {
user32dll, _ := syscall.LoadLibrary("user32.dll")
user32 := syscall.NewLazyDLL("user32.dll")
MessageBoxW := user32.NewProc("MessageBoxW")
MessageBoxW.Call(IntPtr(0), StrPtr(text), StrPtr(title), IntPtr(0))
defer syscall.FreeLibrary(user32dll)
}
func PushNotification(x string, y string) {
notification := toast.Notification{
AppID: "Microsoft.Windows.Shell.RunDialog",
Title: x,
Message: y,
//Icon: "C:\\path\\to\\your\\logo.png", // 文件必须存在
Actions: []toast.Action{
{"protocol", "确定", "https://www.google.com/"},
},
}
err := notification.Push()
if err != nil {
log.Fatalln(err)
}
}