From 0426aa87d25f8f623ca918535ecdd75d7f6ed9e9 Mon Sep 17 00:00:00 2001 From: Philipp Sumi Date: Fri, 1 Apr 2016 19:18:08 +0200 Subject: [PATCH] FIX Fixed potential event propagation before event listeners where registered. --- .../Source/NotifyIconWpf/Interop/WindowMessageSink.cs | 8 +++++--- .../Source/NotifyIconWpf/TaskbarIcon.cs | 3 +++ 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/Hardcodet.NotifyIcon.Wpf/Source/NotifyIconWpf/Interop/WindowMessageSink.cs b/Hardcodet.NotifyIcon.Wpf/Source/NotifyIconWpf/Interop/WindowMessageSink.cs index 8b55f18..c88a860 100644 --- a/Hardcodet.NotifyIcon.Wpf/Source/NotifyIconWpf/Interop/WindowMessageSink.cs +++ b/Hardcodet.NotifyIcon.Wpf/Source/NotifyIconWpf/Interop/WindowMessageSink.cs @@ -25,7 +25,6 @@ using System; using System.ComponentModel; using System.Diagnostics; -using System.Runtime.InteropServices; namespace Hardcodet.Wpf.TaskbarNotification.Interop { @@ -119,7 +118,6 @@ namespace Hardcodet.Wpf.TaskbarNotification.Interop public WindowMessageSink(NotifyIconVersion version) { Version = version; - CreateMessageWindow(); } @@ -127,6 +125,10 @@ namespace Hardcodet.Wpf.TaskbarNotification.Interop { } + internal void Listen() + { + CreateMessageWindow(); + } /// /// Creates a dummy instance that provides an empty @@ -154,7 +156,7 @@ namespace Hardcodet.Wpf.TaskbarNotification.Interop private void CreateMessageWindow() { //generate a unique ID for the window - WindowId = "WPFTaskbarIcon_" + DateTime.Now.Ticks; + WindowId = "WPFTaskbarIcon_" + Guid.NewGuid(); //register window message handler messageHandler = OnWindowMessageReceived; diff --git a/Hardcodet.NotifyIcon.Wpf/Source/NotifyIconWpf/TaskbarIcon.cs b/Hardcodet.NotifyIcon.Wpf/Source/NotifyIconWpf/TaskbarIcon.cs index 5a7538a..2dd251b 100644 --- a/Hardcodet.NotifyIcon.Wpf/Source/NotifyIconWpf/TaskbarIcon.cs +++ b/Hardcodet.NotifyIcon.Wpf/Source/NotifyIconWpf/TaskbarIcon.cs @@ -142,6 +142,9 @@ namespace Hardcodet.Wpf.TaskbarNotification messageSink.ChangeToolTipStateRequest += OnToolTipChange; messageSink.BalloonToolTipChanged += OnBalloonToolTipChanged; + //start listening once we registered to events + if(!Util.IsDesignMode) messageSink.Listen(); + //init single click / balloon timers singleClickTimer = new Timer(DoSingleClickAction); balloonCloseTimer = new Timer(CloseBalloonCallback);