WPF NotifyIcon

--------------
ADD   Completed events.
FIX   Suppressing second left mouse click event in case of a double click.
CHG   General cleanup.

git-svn-id: https://svn.evolvesoftware.ch/repos/evolve.net/WPF/NotifyIcon@53 9f600761-6f11-4665-b6dc-0185e9171623
This commit is contained in:
Philipp Sumi
2009-03-30 23:00:01 +00:00
parent 94085b7293
commit 6cc31cea5b
6 changed files with 520 additions and 147 deletions

View File

@@ -1,13 +1,9 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Controls.Primitives;
using Hardcodet.Wpf.TaskbarNotification.Interop;
namespace Hardcodet.Wpf.TaskbarNotification
@@ -27,39 +23,11 @@ namespace Hardcodet.Wpf.TaskbarNotification
private readonly Timer singleClickTimer;
#region SetVersion
#region Update ToolTip Settings
/// <summary>
/// Sets the version flag for the <see cref="iconData"/>.
/// </summary>
private void SetVersion()
{
iconData.VersionOrTimeout = (uint) NotifyIconVersion.Vista;
bool status = WinApi.Shell_NotifyIcon(NotifyCommand.SetVersion, ref iconData);
if (!status)
{
iconData.VersionOrTimeout = (uint) NotifyIconVersion.Win2000;
status = Util.WriteIconData(ref iconData, NotifyCommand.SetVersion);
}
if (!status)
{
iconData.VersionOrTimeout = (uint)NotifyIconVersion.Win95;
status = Util.WriteIconData(ref iconData, NotifyCommand.SetVersion);
}
if (!status)
{
Debug.Fail("Could not set version");
}
}
#endregion
/// <summary>
/// Sets tooltip settings for the class.
/// Sets tooltip settings for the class depending on defined
/// dependency properties and OS support.
/// </summary>
private void WriteToolTipSettings()
{
@@ -86,6 +54,7 @@ namespace Hardcodet.Wpf.TaskbarNotification
Util.WriteIconData(ref iconData, NotifyCommand.Modify, flags);
}
#endregion
#region Show / Hide Balloon ToolTip
@@ -98,7 +67,7 @@ namespace Hardcodet.Wpf.TaskbarNotification
/// <param name="icon">Indicates the severity.</param>
public void ShowBalloonTip(string title, string message, BalloonIcon icon)
{
lock(this)
lock (this)
{
ShowBalloonTip(title, message, icon.GetBalloonFlag(), IntPtr.Zero);
}
@@ -118,14 +87,13 @@ namespace Hardcodet.Wpf.TaskbarNotification
{
if (customIcon == null) throw new ArgumentNullException("customIcon");
lock(this)
lock (this)
{
ShowBalloonTip(title, message, BalloonFlags.User, customIcon.Handle);
}
}
/// <summary>
/// Invokes <see cref="WinApi.Shell_NotifyIcon"/> in order to display
/// a given balloon ToolTip.
@@ -148,7 +116,6 @@ namespace Hardcodet.Wpf.TaskbarNotification
}
/// <summary>
/// Hides a balloon ToolTip, if any is displayed.
/// </summary>
@@ -163,7 +130,6 @@ namespace Hardcodet.Wpf.TaskbarNotification
#endregion
#region Single Click Timer event
/// <summary>
@@ -175,6 +141,8 @@ namespace Hardcodet.Wpf.TaskbarNotification
{
if (IsDisposed) return;
Console.Out.WriteLine("TIMER EVENT");
//run action
Action action = delayedTimerAction;
if (action != null)
@@ -189,7 +157,6 @@ namespace Hardcodet.Wpf.TaskbarNotification
#endregion
#region Show Tray Popup / Context Menu
/// <summary>
@@ -232,10 +199,10 @@ namespace Hardcodet.Wpf.TaskbarNotification
//raise preview event
var args = RaisePreviewTaskbarIconContextMenuOpenEvent();
if (args.Handled) return;
//CreateActivationWindow();
ContextMenu.IsOpen = true;
//activate the message window to track deactivation - otherwise, the context menu
//does not close if the user clicks somewhere else
WinApi.SetForegroundWindow(messageSink.MessageWindowHandle);
@@ -247,4 +214,4 @@ namespace Hardcodet.Wpf.TaskbarNotification
#endregion
}
}
}