notifyicon.go 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. //go:build windows
  2. package wintray
  3. import (
  4. "unsafe"
  5. "golang.org/x/sys/windows"
  6. )
  7. // Contains information that the system needs to display notifications in the notification area.
  8. // Used by Shell_NotifyIcon.
  9. // https://msdn.microsoft.com/en-us/library/windows/desktop/bb773352(v=vs.85).aspx
  10. // https://msdn.microsoft.com/en-us/library/windows/desktop/bb762159
  11. type notifyIconData struct {
  12. Size uint32
  13. Wnd windows.Handle
  14. ID, Flags, CallbackMessage uint32
  15. Icon windows.Handle
  16. Tip [128]uint16
  17. State, StateMask uint32
  18. Info [256]uint16
  19. // Timeout, Version uint32
  20. Timeout uint32
  21. InfoTitle [64]uint16
  22. InfoFlags uint32
  23. GuidItem windows.GUID
  24. BalloonIcon windows.Handle
  25. }
  26. func (nid *notifyIconData) add() error {
  27. const NIM_ADD = 0x00000000
  28. res, _, err := pShellNotifyIcon.Call(
  29. uintptr(NIM_ADD),
  30. uintptr(unsafe.Pointer(nid)),
  31. )
  32. if res == 0 {
  33. return err
  34. }
  35. return nil
  36. }
  37. func (nid *notifyIconData) modify() error {
  38. const NIM_MODIFY = 0x00000001
  39. res, _, err := pShellNotifyIcon.Call(
  40. uintptr(NIM_MODIFY),
  41. uintptr(unsafe.Pointer(nid)),
  42. )
  43. if res == 0 {
  44. return err
  45. }
  46. return nil
  47. }
  48. func (nid *notifyIconData) delete() error {
  49. const NIM_DELETE = 0x00000002
  50. res, _, err := pShellNotifyIcon.Call(
  51. uintptr(NIM_DELETE),
  52. uintptr(unsafe.Pointer(nid)),
  53. )
  54. if res == 0 {
  55. return err
  56. }
  57. return nil
  58. }