NotifyIcon WPF

--------------
ADD   Added custom balloon support.
CHG   Refactoring of names - properties and events are prefixed by "Tray" rather than "TaskbarIcon".

git-svn-id: https://svn.evolvesoftware.ch/repos/evolve.net/WPF/NotifyIcon@57 9f600761-6f11-4665-b6dc-0185e9171623
This commit is contained in:
Philipp Sumi
2009-04-01 14:59:44 +00:00
parent 1242596214
commit fc7fa38ef5
14 changed files with 841 additions and 696 deletions

View File

@@ -126,7 +126,20 @@ namespace Hardcodet.Wpf.TaskbarNotification.Interop
{
var data = new NotifyIconData();
data.cbSize = (uint) Marshal.SizeOf(data);
if (Environment.OSVersion.Version.Major >= 6)
{
//use the current size
data.cbSize = (uint)Marshal.SizeOf(data);
}
else
{
//we need to set another size on xp/2003- otherwise certain
//features (e.g. balloon tooltips) don't work.
data.cbSize = 504;
//set to fixed timeout
data.VersionOrTimeout = 10;
}
data.WindowHandle = handle;
data.TaskbarIconId = 0x0;

View File

@@ -12,11 +12,13 @@ namespace Hardcodet.Wpf.TaskbarNotification.Interop
public enum NotifyIconVersion
{
/// <summary>
/// Default behavior (legacy Win95).
/// Default behavior (legacy Win95). Expects
/// a <see cref="NotifyIconData"/> size of 488.
/// </summary>
Win95 = 0x0,
/// <summary>
/// Behavior representing Win2000 an higher.
/// Behavior representing Win2000 an higher. Expects
/// a <see cref="NotifyIconData"/> size of 504.
/// </summary>
Win2000 = 0x3,
/// <summary>

View File

@@ -1,95 +0,0 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Runtime.InteropServices;
namespace Hardcodet.Wpf.TaskbarNotification.Interop
{
public struct Rect
{
public int left;
public int top;
public int right;
public int bottom;
public override string ToString()
{
return "(" + left + ", " + top + ") --> (" + right + ", " + bottom + ")";
}
}
public struct TaskbarInfo
{
public int cbSize;
public IntPtr WindowHandle;
public int uCallbackMessage;
public TaskbarPosition Position;
public Rect Rectangle;
public IntPtr lParam;
}
public enum TaskbarPosition
{
Left = 0,
Top,
Right,
Bottom
}
/// <summary>
/// Locates the position of the tray area.
/// </summary>
public class TrayLocator
{
public enum ABMsg
{
ABM_NEW = 0,
ABM_REMOVE = 1,
ABM_QUERYPOS = 2,
ABM_SETPOS = 3,
ABM_GETSTATE = 4,
ABM_GETTASKBARPOS = 5,
ABM_ACTIVATE = 6,
ABM_GETAUTOHIDEBAR = 7,
ABM_SETAUTOHIDEBAR = 8,
ABM_WINDOWPOSCHANGED = 9,
ABM_SETSTATE = 10
}
public enum ABNotify
{
ABN_STATECHANGE = 0,
ABN_POSCHANGED,
ABN_FULLSCREENAPP,
ABN_WINDOWARRANGE
}
[DllImport("shell32.dll", EntryPoint = "SHAppBarMessage", CharSet = CharSet.Ansi, SetLastError = true, ExactSpelling = true)]
public static extern int SHAppBarMessage(int dwMessage, ref TaskbarInfo pData);
/// <summary>
/// Determines the current location of the taskbar.
/// </summary>
/// <returns></returns>
public static TaskbarInfo GetTaskbarInformation()
{
TaskbarInfo tbInfo = new TaskbarInfo();
tbInfo.cbSize = Marshal.SizeOf(tbInfo);
//retrieve the bounding rectangle of the Windows taskbar.
SHAppBarMessage((int)ABMsg.ABM_GETTASKBARPOS, ref tbInfo);
return tbInfo;
}
}
}