MCPcopy
hub / github.com/lxn/walk / NewNotifyIcon

Function NewNotifyIcon

notifyicon.go:90–133  ·  view source on GitHub ↗

NewNotifyIcon creates and returns a new NotifyIcon. The NotifyIcon is initially not visible.

(form Form)

Source from the content-addressed store, hash-verified

88//
89// The NotifyIcon is initially not visible.
90func 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
135func (ni *NotifyIcon) DPI() int {
136 fakeWb := WindowBase{hWnd: win.FindWindow(syscall.StringToUTF16Ptr("Shell_TrayWnd"), syscall.StringToUTF16Ptr(""))}

Callers

nothing calls this directly

Calls 3

newErrorFunction · 0.85
NewMenuFunction · 0.85
AsFormBaseMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…