From 02fb2b6108d62191bc5af9be48397510bdf3e3ce Mon Sep 17 00:00:00 2001 From: Philipp Sumi Date: Sat, 2 Apr 2016 08:59:45 +0200 Subject: [PATCH] FIX Delayed message sink listener causing interop issues. --- .../Interop/WindowMessageSink.cs | 21 ++++++++++--------- .../Source/NotifyIconWpf/TaskbarIcon.cs | 11 ++++------ 2 files changed, 15 insertions(+), 17 deletions(-) diff --git a/Hardcodet.NotifyIcon.Wpf/Source/NotifyIconWpf/Interop/WindowMessageSink.cs b/Hardcodet.NotifyIcon.Wpf/Source/NotifyIconWpf/Interop/WindowMessageSink.cs index c88a860..aeb00ce 100644 --- a/Hardcodet.NotifyIcon.Wpf/Source/NotifyIconWpf/Interop/WindowMessageSink.cs +++ b/Hardcodet.NotifyIcon.Wpf/Source/NotifyIconWpf/Interop/WindowMessageSink.cs @@ -118,6 +118,7 @@ namespace Hardcodet.Wpf.TaskbarNotification.Interop public WindowMessageSink(NotifyIconVersion version) { Version = version; + CreateMessageWindow(); } @@ -125,11 +126,6 @@ namespace Hardcodet.Wpf.TaskbarNotification.Interop { } - internal void Listen() - { - CreateMessageWindow(); - } - /// /// Creates a dummy instance that provides an empty /// pointer rather than a real window handler.
@@ -209,7 +205,8 @@ namespace Hardcodet.Wpf.TaskbarNotification.Interop if (messageId == taskbarRestartMessageId) { //recreate the icon if the taskbar was restarted (e.g. due to Win Explorer shutdown) - TaskbarCreated(); + var listener = TaskbarCreated; + if(listener != null) listener(); } //forward message @@ -280,12 +277,14 @@ namespace Hardcodet.Wpf.TaskbarNotification.Interop break; case 0x402: - BalloonToolTipChanged(true); + var listener = BalloonToolTipChanged; + if (listener != null) listener(true); break; case 0x403: case 0x404: - BalloonToolTipChanged(false); + listener = BalloonToolTipChanged; + if (listener != null) listener(false); break; case 0x405: @@ -293,11 +292,13 @@ namespace Hardcodet.Wpf.TaskbarNotification.Interop break; case 0x406: - ChangeToolTipStateRequest(true); + listener = ChangeToolTipStateRequest; + if (listener != null) listener(true); break; case 0x407: - ChangeToolTipStateRequest(false); + listener = ChangeToolTipStateRequest; + if (listener != null) listener(false); break; default: diff --git a/Hardcodet.NotifyIcon.Wpf/Source/NotifyIconWpf/TaskbarIcon.cs b/Hardcodet.NotifyIcon.Wpf/Source/NotifyIconWpf/TaskbarIcon.cs index 2dd251b..58134ab 100644 --- a/Hardcodet.NotifyIcon.Wpf/Source/NotifyIconWpf/TaskbarIcon.cs +++ b/Hardcodet.NotifyIcon.Wpf/Source/NotifyIconWpf/TaskbarIcon.cs @@ -70,7 +70,7 @@ namespace Hardcodet.Wpf.TaskbarNotification /// /// The time we should wait for a double click. /// - private int doubleClickWaitTime + private int DoubleClickWaitTime { get { return NoLeftClickDelay ? 0 : WinApi.GetDoubleClickTime(); } } @@ -142,9 +142,6 @@ 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); @@ -428,7 +425,7 @@ namespace Hardcodet.Wpf.TaskbarNotification LeftClickCommand.ExecuteIfEnabled(LeftClickCommandParameter, LeftClickCommandTarget ?? this); ShowTrayPopup(cursorPosition); }; - singleClickTimer.Change(doubleClickWaitTime, Timeout.Infinite); + singleClickTimer.Change(DoubleClickWaitTime, Timeout.Infinite); isLeftClickCommandInvoked = true; } else @@ -450,7 +447,7 @@ namespace Hardcodet.Wpf.TaskbarNotification LeftClickCommand.ExecuteIfEnabled(LeftClickCommandParameter, LeftClickCommandTarget ?? this); ShowContextMenu(cursorPosition); }; - singleClickTimer.Change(doubleClickWaitTime, Timeout.Infinite); + singleClickTimer.Change(DoubleClickWaitTime, Timeout.Infinite); isLeftClickCommandInvoked = true; } else @@ -469,7 +466,7 @@ namespace Hardcodet.Wpf.TaskbarNotification { LeftClickCommand.ExecuteIfEnabled(LeftClickCommandParameter, LeftClickCommandTarget ?? this); }; - singleClickTimer.Change(doubleClickWaitTime, Timeout.Infinite); + singleClickTimer.Change(DoubleClickWaitTime, Timeout.Infinite); } }