NewNotifyIcon creates and returns a new NotifyIcon. The NotifyIcon is initially not visible.
(form Form)
| 88 | // |
| 89 | // The NotifyIcon is initially not visible. |
| 90 | func NewNotifyIcon(form Form) (*NotifyIcon, error) { |
| 91 | fb := form.AsFormBase() |
| 92 | // Add our notify icon to the status area and make sure it is hidden. |
| 93 | nid := win.NOTIFYICONDATA{ |
| 94 | HWnd: fb.hWnd, |
| 95 | UFlags: win.NIF_MESSAGE | win.NIF_STATE, |
| 96 | DwState: win.NIS_HIDDEN, |
| 97 | DwStateMask: win.NIS_HIDDEN, |
| 98 | UCallbackMessage: notifyIconMessageId, |
| 99 | } |
| 100 | nid.CbSize = uint32(unsafe.Sizeof(nid) - unsafe.Sizeof(win.HICON(0))) |
| 101 | |
| 102 | if !win.Shell_NotifyIcon(win.NIM_ADD, &nid) { |
| 103 | return nil, newError("Shell_NotifyIcon") |
| 104 | } |
| 105 | |
| 106 | // We want XP-compatible message behavior. |
| 107 | nid.UVersion = win.NOTIFYICON_VERSION |
| 108 | |
| 109 | if !win.Shell_NotifyIcon(win.NIM_SETVERSION, &nid) { |
| 110 | return nil, newError("Shell_NotifyIcon") |
| 111 | } |
| 112 | |
| 113 | // Create and initialize the NotifyIcon already. |
| 114 | menu, err := NewMenu() |
| 115 | if err != nil { |
| 116 | return nil, err |
| 117 | } |
| 118 | menu.window = form |
| 119 | |
| 120 | ni := &NotifyIcon{ |
| 121 | id: nid.UID, |
| 122 | hWnd: fb.hWnd, |
| 123 | contextMenu: menu, |
| 124 | } |
| 125 | |
| 126 | menu.getDPI = ni.DPI |
| 127 | |
| 128 | // Set our *NotifyIcon as user data for the message window. |
| 129 | win.SetWindowLongPtr(fb.hWnd, win.GWLP_USERDATA, uintptr(unsafe.Pointer(ni))) |
| 130 | |
| 131 | notifyIcons[ni] = true |
| 132 | return ni, nil |
| 133 | } |
| 134 | |
| 135 | func (ni *NotifyIcon) DPI() int { |
| 136 | fakeWb := WindowBase{hWnd: win.FindWindow(syscall.StringToUTF16Ptr("Shell_TrayWnd"), syscall.StringToUTF16Ptr(""))} |
nothing calls this directly
no test coverage detected
searching dependent graphs…