diff options
author | Jason A. Donenfeld <Jason@zx2c4.com> | 2019-02-25 14:51:30 +0100 |
---|---|---|
committer | Jason A. Donenfeld <Jason@zx2c4.com> | 2019-02-25 14:52:47 +0100 |
commit | bef8437a4de7a847c18c15e804d7af066805714a (patch) | |
tree | a692170127f0d7c4b532f3701a2c5493389f89b6 | |
parent | static: Invalidate after resize (diff) | |
download | wireguard-windows-bef8437a4de7a847c18c15e804d7af066805714a.tar.xz wireguard-windows-bef8437a4de7a847c18c15e804d7af066805714a.zip |
notifyicon: Use mainwindow's window instead of creating own
This fixes problems with adding notify icons to visible main windows.
Fixes: https://github.com/lxn/walk/issues/403
-rw-r--r-- | examples/notifyicon/notifyicon.go | 2 | ||||
-rw-r--r-- | notifyicon.go | 32 |
2 files changed, 5 insertions, 29 deletions
diff --git a/examples/notifyicon/notifyicon.go b/examples/notifyicon/notifyicon.go index a24dee73..124eefe9 100644 --- a/examples/notifyicon/notifyicon.go +++ b/examples/notifyicon/notifyicon.go @@ -27,7 +27,7 @@ func main() { } // Create the notify icon and make sure we clean it up on exit. - ni, err := walk.NewNotifyIcon() + ni, err := walk.NewNotifyIcon(mw) if err != nil { log.Fatal(err) } diff --git a/notifyicon.go b/notifyicon.go index fe4ef8bf..2acaa971 100644 --- a/notifyicon.go +++ b/notifyicon.go @@ -15,12 +15,6 @@ import ( "github.com/lxn/win" ) -const notifyIconWindowClass = `\o/ Walk_NotifyIcon_Class \o/` - -func init() { - MustRegisterWindowClass(notifyIconWindowClass) -} - func notifyIconWndProc(hwnd win.HWND, msg uint32, wParam, lParam uintptr) (result uintptr) { // Retrieve our *NotifyIcon from the message window. ptr := win.GetWindowLongPtr(hwnd, win.GWLP_USERDATA) @@ -87,28 +81,10 @@ type NotifyIcon struct { // NewNotifyIcon creates and returns a new NotifyIcon. // // The NotifyIcon is initially not visible. -func NewNotifyIcon() (*NotifyIcon, error) { - // Create the message-only window for the NotifyIcon. - hWnd := win.CreateWindowEx( - 0, - syscall.StringToUTF16Ptr(notifyIconWindowClass), - nil, - 0, - 0, - 0, - 0, - 0, - win.HWND_MESSAGE, - 0, - 0, - nil) - if hWnd == 0 { - return nil, lastError("CreateWindowEx") - } - +func NewNotifyIcon(mw *MainWindow) (*NotifyIcon, error) { // Add our notify icon to the status area and make sure it is hidden. nid := win.NOTIFYICONDATA{ - HWnd: hWnd, + HWnd: mw.hWnd, UFlags: win.NIF_MESSAGE | win.NIF_STATE, DwState: win.NIS_HIDDEN, DwStateMask: win.NIS_HIDDEN, @@ -135,12 +111,12 @@ func NewNotifyIcon() (*NotifyIcon, error) { ni := &NotifyIcon{ id: nid.UID, - hWnd: hWnd, + hWnd: mw.hWnd, contextMenu: menu, } // Set our *NotifyIcon as user data for the message window. - win.SetWindowLongPtr(hWnd, win.GWLP_USERDATA, uintptr(unsafe.Pointer(ni))) + win.SetWindowLongPtr(mw.hWnd, win.GWLP_USERDATA, uintptr(unsafe.Pointer(ni))) return ni, nil } |