FIX Delayed message sink listener causing interop issues.

This commit is contained in:
Philipp Sumi
2016-04-02 08:59:45 +02:00
parent d4ecbdf117
commit 02fb2b6108
2 changed files with 15 additions and 17 deletions

View File

@@ -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();
}
/// <summary>
/// Creates a dummy instance that provides an empty
/// pointer rather than a real window handler.<br/>
@@ -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:

View File

@@ -70,7 +70,7 @@ namespace Hardcodet.Wpf.TaskbarNotification
/// <summary>
/// The time we should wait for a double click.
/// </summary>
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);
}
}