diff options
author | Alexander Neumann <alexander.neumann@picos-software.com> | 2019-02-26 10:52:26 +0100 |
---|---|---|
committer | Alexander Neumann <alexander.neumann@picos-software.com> | 2019-02-26 10:52:26 +0100 |
commit | 1fd02f56dcd2e087f5e402f2e18f95ef775d80a0 (patch) | |
tree | 20287c51ffcabb840bbdf2c6cfbb132a1117a80d | |
parent | Merge pull request #464 from zx2c4-forks/static-wrong-build-tag (diff) | |
parent | notifyicon: Use mainwindow's window instead of creating own (diff) | |
download | wireguard-windows-1fd02f56dcd2e087f5e402f2e18f95ef775d80a0.tar.xz wireguard-windows-1fd02f56dcd2e087f5e402f2e18f95ef775d80a0.zip |
Merge branch 'jd/notifyicon-visible-mainwindow' of https://github.com/zx2c4-forks/walk into notifyicon_fix
-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 } |