Revision 9bae55d1
b/trunk/NotifyIconWpf/BalloonIcon.cs | ||
---|---|---|
1 |
// hardcodet.net NotifyIcon for WPF |
|
2 |
// Copyright (c) 2009 Philipp Sumi |
|
3 |
// Contact and Information: http://www.hardcodet.net |
|
4 |
// |
|
5 |
// This library is free software; you can redistribute it and/or |
|
6 |
// modify it under the terms of the Code Project Open License (CPOL); |
|
7 |
// either version 1.0 of the License, or (at your option) any later |
|
8 |
// version. |
|
9 |
// |
|
10 |
// The above copyright notice and this permission notice shall be |
|
11 |
// included in all copies or substantial portions of the Software. |
|
12 |
// |
|
13 |
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, |
|
14 |
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES |
|
15 |
// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
|
16 |
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT |
|
17 |
// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, |
|
18 |
// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
|
19 |
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR |
|
20 |
// OTHER DEALINGS IN THE SOFTWARE. |
|
21 |
// |
|
22 |
// THIS COPYRIGHT NOTICE MAY NOT BE REMOVED FROM THIS FILE |
|
23 |
|
|
24 |
|
|
25 |
namespace Hardcodet.Wpf.TaskbarNotification |
|
26 |
{ |
|
27 |
///<summary> |
|
28 |
/// Supported icons for the tray's balloon messages. |
|
29 |
///</summary> |
|
30 |
public enum BalloonIcon |
|
31 |
{ |
|
32 |
/// <summary> |
|
33 |
/// The balloon message is displayed without an icon. |
|
34 |
/// </summary> |
|
35 |
None, |
|
36 |
/// <summary> |
|
37 |
/// An information is displayed. |
|
38 |
/// </summary> |
|
39 |
Info, |
|
40 |
/// <summary> |
|
41 |
/// A warning is displayed. |
|
42 |
/// </summary> |
|
43 |
Warning, |
|
44 |
/// <summary> |
|
45 |
/// An error is displayed. |
|
46 |
/// </summary> |
|
47 |
Error |
|
48 |
} |
|
49 |
} |
b/trunk/NotifyIconWpf/Diagrams/TaskbarIcon Overview.cd | ||
---|---|---|
1 |
<?xml version="1.0" encoding="utf-8"?> |
|
2 |
<ClassDiagram MajorVersion="1" MinorVersion="1"> |
|
3 |
<Class Name="Hardcodet.Wpf.TaskbarNotification.TaskbarIcon"> |
|
4 |
<Position X="1.75" Y="0.5" Width="3.5" /> |
|
5 |
<Compartments> |
|
6 |
<Compartment Name="Fields" Collapsed="true" /> |
|
7 |
<Compartment Name="Methods" Collapsed="true" /> |
|
8 |
</Compartments> |
|
9 |
<TypeIdentifier> |
|
10 |
<HashCode>N6qdVIeUdLmQtSUbiJhEGdYRjvJYXlhbEVBDKuPRO5s=</HashCode> |
|
11 |
<FileName>TaskbarIcon.cs</FileName> |
|
12 |
</TypeIdentifier> |
|
13 |
<Lollipop Position="0.2" /> |
|
14 |
</Class> |
|
15 |
<Enum Name="Hardcodet.Wpf.TaskbarNotification.PopupActivationMode"> |
|
16 |
<Position X="6.75" Y="0.5" Width="2" /> |
|
17 |
<TypeIdentifier> |
|
18 |
<HashCode>ABAEAAAAAAAAAAABAAAAAAAAAAAAAAAAAIAKAIAAAAA=</HashCode> |
|
19 |
<FileName>PopupActivationMode.cs</FileName> |
|
20 |
</TypeIdentifier> |
|
21 |
</Enum> |
|
22 |
<Enum Name="Hardcodet.Wpf.TaskbarNotification.BalloonIcon"> |
|
23 |
<Position X="9.25" Y="0.5" Width="1.5" /> |
|
24 |
<TypeIdentifier> |
|
25 |
<HashCode>AAAAAAAAAAAAAQAAAAAAABAAAAAAAAAAAAAAAEEAAAA=</HashCode> |
|
26 |
<FileName>BalloonIcon.cs</FileName> |
|
27 |
</TypeIdentifier> |
|
28 |
</Enum> |
|
29 |
<Font Name="Segoe UI" Size="9" /> |
|
30 |
</ClassDiagram> |
b/trunk/NotifyIconWpf/Interop/BalloonFlags.cs | ||
---|---|---|
1 |
namespace Hardcodet.Wpf.TaskbarNotification.Interop |
|
2 |
{ |
|
3 |
/// <summary> |
|
4 |
/// Flags that define the icon that is shown on a balloon |
|
5 |
/// tooltip. |
|
6 |
/// </summary> |
|
7 |
public enum BalloonFlags |
|
8 |
{ |
|
9 |
/// <summary> |
|
10 |
/// No icon is displayed. |
|
11 |
/// </summary> |
|
12 |
None = 0x00, |
|
13 |
/// <summary> |
|
14 |
/// An information icon is displayed. |
|
15 |
/// </summary> |
|
16 |
Info = 0x01, |
|
17 |
/// <summary> |
|
18 |
/// A warning icon is displayed. |
|
19 |
/// </summary> |
|
20 |
Warning = 0x02, |
|
21 |
/// <summary> |
|
22 |
/// An error icon is displayed. |
|
23 |
/// </summary> |
|
24 |
Error = 0x03, |
|
25 |
/// <summary> |
|
26 |
/// Windows XP Service Pack 2 (SP2) and later. |
|
27 |
/// Use a custom icon as the title icon. |
|
28 |
/// </summary> |
|
29 |
User = 0x04, |
|
30 |
/// <summary> |
|
31 |
/// Windows XP (Shell32.dll version 6.0) and later. |
|
32 |
/// Do not play the associated sound. Applies only to balloon ToolTips. |
|
33 |
/// </summary> |
|
34 |
NoSound = 0x10, |
|
35 |
/// <summary> |
|
36 |
/// Windows Vista (Shell32.dll version 6.0.6) and later. The large version |
|
37 |
/// of the icon should be used as the balloon icon. This corresponds to the |
|
38 |
/// icon with dimensions SM_CXICON x SM_CYICON. If this flag is not set, |
|
39 |
/// the icon with dimensions XM_CXSMICON x SM_CYSMICON is used.<br/> |
|
40 |
/// - This flag can be used with all stock icons.<br/> |
|
41 |
/// - Applications that use older customized icons (NIIF_USER with hIcon) must |
|
42 |
/// provide a new SM_CXICON x SM_CYICON version in the tray icon (hIcon). These |
|
43 |
/// icons are scaled down when they are displayed in the System Tray or |
|
44 |
/// System Control Area (SCA).<br/> |
|
45 |
/// - New customized icons (NIIF_USER with hBalloonIcon) must supply an |
|
46 |
/// SM_CXICON x SM_CYICON version in the supplied icon (hBalloonIcon). |
|
47 |
/// </summary> |
|
48 |
LargeIcon = 0x20, |
|
49 |
/// <summary> |
|
50 |
/// Windows 7 and later. |
|
51 |
/// </summary> |
|
52 |
RespectQuietTime = 0x80 |
|
53 |
|
|
54 |
} |
|
55 |
} |
b/trunk/NotifyIconWpf/Interop/IconDataMembers.cs | ||
---|---|---|
1 |
using System; |
|
2 |
|
|
3 |
namespace Hardcodet.Wpf.TaskbarNotification.Interop |
|
4 |
{ |
|
5 |
/// <summary> |
|
6 |
/// Indicates which members of a <see cref="NotifyIconData"/> structure |
|
7 |
/// were set, and thus contain valid data or provide additional information |
|
8 |
/// to the ToolTip as to how it should display. |
|
9 |
/// </summary> |
|
10 |
[Flags] |
|
11 |
public enum IconDataMembers |
|
12 |
{ |
|
13 |
/// <summary> |
|
14 |
/// The message ID is set. |
|
15 |
/// </summary> |
|
16 |
Message = 0x01, |
|
17 |
/// <summary> |
|
18 |
/// The notification icon is set. |
|
19 |
/// </summary> |
|
20 |
Icon = 0x02, |
|
21 |
/// <summary> |
|
22 |
/// The tooltip is set. |
|
23 |
/// </summary> |
|
24 |
Tip = 0x04, |
|
25 |
/// <summary> |
|
26 |
/// State information (<see cref="IconState"/>) is set. This |
|
27 |
/// applies to both <see cref="NotifyIconData.IconState"/> and |
|
28 |
/// <see cref="NotifyIconData.StateMask"/>. |
|
29 |
/// </summary> |
|
30 |
State = 0x08, |
|
31 |
/// <summary> |
|
32 |
/// The balloon ToolTip is set. Accordingly, the following |
|
33 |
/// members are set: <see cref="NotifyIconData.BalloonText"/>, |
|
34 |
/// <see cref="NotifyIconData.BalloonTitle"/>, <see cref="NotifyIconData.BalloonFlags"/>, |
|
35 |
/// and <see cref="NotifyIconData.VersionOrTimeout"/>. |
|
36 |
/// </summary> |
|
37 |
Info = 0x10, |
|
38 |
|
|
39 |
/// <summary> |
|
40 |
/// Internal identifier is set. Reserved, thus commented out. |
|
41 |
/// </summary> |
|
42 |
//Guid = 0x20, |
|
43 |
|
|
44 |
/// <summary> |
|
45 |
/// Windows Vista (Shell32.dll version 6.0.6) and later. If the ToolTip |
|
46 |
/// cannot be displayed immediately, discard it.<br/> |
|
47 |
/// Use this flag for ToolTips that represent real-time information which |
|
48 |
/// would be meaningless or misleading if displayed at a later time. |
|
49 |
/// For example, a message that states "Your telephone is ringing."<br/> |
|
50 |
/// This modifies and must be combined with the <see cref="Info"/> flag. |
|
51 |
/// </summary> |
|
52 |
Realtime = 0x40, |
|
53 |
/// <summary> |
|
54 |
/// Windows Vista (Shell32.dll version 6.0.6) and later. |
|
55 |
/// Use the standard ToolTip. Normally, when uVersion is set |
|
56 |
/// to NOTIFYICON_VERSION_4, the standard ToolTip is replaced |
|
57 |
/// by the application-drawn pop-up user interface (UI). |
|
58 |
/// If the application wants to show the standard tooltip |
|
59 |
/// in that case, regardless of whether the on-hover UI is showing, |
|
60 |
/// it can specify NIF_SHOWTIP to indicate the standard tooltip |
|
61 |
/// should still be shown.<br/> |
|
62 |
/// Note that the NIF_SHOWTIP flag is effective until the next call |
|
63 |
/// to Shell_NotifyIcon. |
|
64 |
/// </summary> |
|
65 |
UseLegacyToolTips = 0x80 |
|
66 |
} |
|
67 |
} |
b/trunk/NotifyIconWpf/Interop/IconState.cs | ||
---|---|---|
1 |
namespace Hardcodet.Wpf.TaskbarNotification.Interop |
|
2 |
{ |
|
3 |
/// <summary> |
|
4 |
/// The state of the icon - can be set to |
|
5 |
/// hide the icon. |
|
6 |
/// </summary> |
|
7 |
public enum IconState |
|
8 |
{ |
|
9 |
/// <summary> |
|
10 |
/// The icon is visible. |
|
11 |
/// </summary> |
|
12 |
Visible = 0x00, |
|
13 |
/// <summary> |
|
14 |
/// Hide the icon. |
|
15 |
/// </summary> |
|
16 |
Hidden = 0x01, |
|
17 |
|
|
18 |
/// <summary> |
|
19 |
/// The icon is shared - currently not supported, thus commented out. |
|
20 |
/// </summary> |
|
21 |
//Shared = 0x02 |
|
22 |
} |
|
23 |
} |
b/trunk/NotifyIconWpf/Interop/MouseEvent.cs | ||
---|---|---|
1 |
|
|
2 |
|
|
3 |
namespace Hardcodet.Wpf.TaskbarNotification.Interop |
|
4 |
{ |
|
5 |
/// <summary> |
|
6 |
/// Event flags for clicked events. |
|
7 |
/// </summary> |
|
8 |
public enum MouseEvent |
|
9 |
{ |
|
10 |
/// <summary> |
|
11 |
/// The mouse was moved withing the |
|
12 |
/// taskbar icon's area. |
|
13 |
/// </summary> |
|
14 |
MouseMove, |
|
15 |
/// <summary> |
|
16 |
/// The right mouse button was clicked. |
|
17 |
/// </summary> |
|
18 |
IconRightMouseDown, |
|
19 |
/// <summary> |
|
20 |
/// The left mouse button was clicked. |
|
21 |
/// </summary> |
|
22 |
IconLeftMouseDown, |
|
23 |
/// <summary> |
|
24 |
/// The right mouse button was released. |
|
25 |
/// </summary> |
|
26 |
IconRightMouseUp, |
|
27 |
/// <summary> |
|
28 |
/// The left mouse button was released. |
|
29 |
/// </summary> |
|
30 |
IconLeftMouseUp, |
|
31 |
/// <summary> |
|
32 |
/// The middle mouse button was clicked. |
|
33 |
/// </summary> |
|
34 |
IconMiddleMouseDown, |
|
35 |
/// <summary> |
|
36 |
/// The middle mouse button was released. |
|
37 |
/// </summary> |
|
38 |
IconMiddleMouseUp, |
|
39 |
/// <summary> |
|
40 |
/// The taskbar icon was double clicked. |
|
41 |
/// </summary> |
|
42 |
IconDoubleClick, |
|
43 |
/// <summary> |
|
44 |
/// The balloon tip was clicked. |
|
45 |
/// </summary> |
|
46 |
BalloonToolTipClicked |
|
47 |
} |
|
48 |
} |
b/trunk/NotifyIconWpf/Interop/NotifyCommand.cs | ||
---|---|---|
1 |
|
|
2 |
|
|
3 |
namespace Hardcodet.Wpf.TaskbarNotification.Interop |
|
4 |
{ |
|
5 |
/// <summary> |
|
6 |
/// Main operations performed on the |
|
7 |
/// <see cref="WinApi.Shell_NotifyIcon"/> function. |
|
8 |
/// </summary> |
|
9 |
public enum NotifyCommand |
|
10 |
{ |
|
11 |
/// <summary> |
|
12 |
/// The taskbar icon is being created. |
|
13 |
/// </summary> |
|
14 |
Add = 0x00, |
|
15 |
/// <summary> |
|
16 |
/// The settings of the taskbar icon are being updated. |
|
17 |
/// </summary> |
|
18 |
Modify = 0x01, |
|
19 |
/// <summary> |
|
20 |
/// The taskbar icon is deleted. |
|
21 |
/// </summary> |
|
22 |
Delete = 0x02, |
|
23 |
/// <summary> |
|
24 |
/// Focus is returned to the taskbar icon. Currently not in use. |
|
25 |
/// </summary> |
|
26 |
SetFocus = 0x03, |
|
27 |
/// <summary> |
|
28 |
/// Shell32.dll version 5.0 and later only. Instructs the taskbar |
|
29 |
/// to behave according to the version number specified in the |
|
30 |
/// uVersion member of the structure pointed to by lpdata. |
|
31 |
/// This message allows you to specify whether you want the version |
|
32 |
/// 5.0 behavior found on Microsoft Windows 2000 systems, or the |
|
33 |
/// behavior found on earlier Shell versions. The default value for |
|
34 |
/// uVersion is zero, indicating that the original Windows 95 notify |
|
35 |
/// icon behavior should be used. |
|
36 |
/// </summary> |
|
37 |
SetVersion = 0x04 |
|
38 |
} |
|
39 |
} |
b/trunk/NotifyIconWpf/Interop/NotifyIconData.cs | ||
---|---|---|
1 |
using System; |
|
2 |
using System.Drawing; |
|
3 |
using System.Runtime.InteropServices; |
|
4 |
|
|
5 |
namespace Hardcodet.Wpf.TaskbarNotification.Interop |
|
6 |
{ |
|
7 |
/// <summary> |
|
8 |
/// A struct that is submitted in order to configure |
|
9 |
/// the taskbar icon. Provides various members that |
|
10 |
/// can be configured partially, according to the |
|
11 |
/// values of the <see cref="IconDataMembers"/> |
|
12 |
/// that were defined. |
|
13 |
/// </summary> |
|
14 |
[StructLayout(LayoutKind.Sequential)] |
|
15 |
public struct NotifyIconData |
|
16 |
{ |
|
17 |
/// <summary> |
|
18 |
/// Size of this structure, in bytes. |
|
19 |
/// </summary> |
|
20 |
public uint cbSize; |
|
21 |
|
|
22 |
/// <summary> |
|
23 |
/// Handle to the window that receives notification messages associated with an icon in the |
|
24 |
/// taskbar status area. The Shell uses hWnd and uID to identify which icon to operate on |
|
25 |
/// when Shell_NotifyIcon is invoked. |
|
26 |
/// </summary> |
|
27 |
public IntPtr WindowHandle; |
|
28 |
|
|
29 |
/// <summary> |
|
30 |
/// Application-defined identifier of the taskbar icon. The Shell uses hWnd and uID to identify |
|
31 |
/// which icon to operate on when Shell_NotifyIcon is invoked. You can have multiple icons |
|
32 |
/// associated with a single hWnd by assigning each a different uID. This feature, however |
|
33 |
/// is currently not used. |
|
34 |
/// </summary> |
|
35 |
public uint TaskbarIconId; |
|
36 |
|
|
37 |
/// <summary> |
|
38 |
/// Flags that indicate which of the other members contain valid data. This member can be |
|
39 |
/// a combination of the NIF_XXX constants. |
|
40 |
/// </summary> |
|
41 |
public IconDataMembers ValidMembers; |
|
42 |
|
|
43 |
/// <summary> |
|
44 |
/// Application-defined message identifier. The system uses this identifier to send |
|
45 |
/// notifications to the window identified in hWnd. |
|
46 |
/// </summary> |
|
47 |
public uint CallbackMessageId; |
|
48 |
|
|
49 |
/// <summary> |
|
50 |
/// A handle to the icon that should be displayed. Just |
|
51 |
/// <see cref="Icon.Handle"/>. |
|
52 |
/// </summary> |
|
53 |
public IntPtr IconHandle; |
|
54 |
|
|
55 |
/// <summary> |
|
56 |
/// String with the text for a standard ToolTip. It can have a maximum of 64 characters including |
|
57 |
/// the terminating NULL. For Version 5.0 and later, szTip can have a maximum of |
|
58 |
/// 128 characters, including the terminating NULL. |
|
59 |
/// </summary> |
|
60 |
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 128)] public string ToolTipText; |
|
61 |
|
|
62 |
|
|
63 |
/// <summary> |
|
64 |
/// State of the icon. Remember to also set the <see cref="StateMask"/>. |
|
65 |
/// </summary> |
|
66 |
public IconState IconState; |
|
67 |
|
|
68 |
/// <summary> |
|
69 |
/// A value that specifies which bits of the state member are retrieved or modified. |
|
70 |
/// For example, setting this member to <see cref="Interop.IconState.Hidden"/> |
|
71 |
/// causes only the item's hidden |
|
72 |
/// state to be retrieved. |
|
73 |
/// </summary> |
|
74 |
public IconState StateMask; |
|
75 |
|
|
76 |
/// <summary> |
|
77 |
/// String with the text for a balloon ToolTip. It can have a maximum of 255 characters. |
|
78 |
/// To remove the ToolTip, set the NIF_INFO flag in uFlags and set szInfo to an empty string. |
|
79 |
/// </summary> |
|
80 |
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 256)] public string BalloonText; |
|
81 |
|
|
82 |
/// <summary> |
|
83 |
/// Mainly used to set the version when <see cref="WinApi.Shell_NotifyIcon"/> is invoked |
|
84 |
/// with <see cref="NotifyCommand.SetVersion"/>. However, for legacy operations, |
|
85 |
/// the same member is also used to set timouts for balloon ToolTips. |
|
86 |
/// </summary> |
|
87 |
public uint VersionOrTimeout; |
|
88 |
|
|
89 |
/// <summary> |
|
90 |
/// String containing a title for a balloon ToolTip. This title appears in boldface |
|
91 |
/// above the text. It can have a maximum of 63 characters. |
|
92 |
/// </summary> |
|
93 |
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 64)] public string BalloonTitle; |
|
94 |
|
|
95 |
/// <summary> |
|
96 |
/// Adds an icon to a balloon ToolTip, which is placed to the left of the title. If the |
|
97 |
/// <see cref="BalloonTitle"/> member is zero-length, the icon is not shown. |
|
98 |
/// </summary> |
|
99 |
public BalloonFlags BalloonFlags; |
|
100 |
|
|
101 |
/// <summary> |
|
102 |
/// Windows XP (Shell32.dll version 6.0) and later.<br/> |
|
103 |
/// - Windows 7 and later: A registered GUID that identifies the icon. |
|
104 |
/// This value overrides uID and is the recommended method of identifying the icon.<br/> |
|
105 |
/// - Windows XP through Windows Vista: Reserved. |
|
106 |
/// </summary> |
|
107 |
public Guid TaskbarIconGuid; |
|
108 |
|
|
109 |
/// <summary> |
|
110 |
/// Windows Vista (Shell32.dll version 6.0.6) and later. The handle of a customized |
|
111 |
/// balloon icon provided by the application that should be used independently |
|
112 |
/// of the tray icon. If this member is non-NULL and the <see cref="Interop.BalloonFlags.User"/> |
|
113 |
/// flag is set, this icon is used as the balloon icon.<br/> |
|
114 |
/// If this member is NULL, the legacy behavior is carried out. |
|
115 |
/// </summary> |
|
116 |
public IntPtr CustomBalloonIconHandle; |
|
117 |
|
|
118 |
|
|
119 |
/// <summary> |
|
120 |
/// Creates a default data structure that provides |
|
121 |
/// a hidden taskbar icon without the icon being set. |
|
122 |
/// </summary> |
|
123 |
/// <param name="handle"></param> |
|
124 |
/// <returns></returns> |
|
125 |
public static NotifyIconData CreateDefault(IntPtr handle) |
|
126 |
{ |
|
127 |
var data = new NotifyIconData(); |
|
128 |
|
|
129 |
if (Environment.OSVersion.Version.Major >= 6) |
|
130 |
{ |
|
131 |
//use the current size |
|
132 |
data.cbSize = (uint)Marshal.SizeOf(data); |
|
133 |
} |
|
134 |
else |
|
135 |
{ |
|
136 |
//we need to set another size on xp/2003- otherwise certain |
|
137 |
//features (e.g. balloon tooltips) don't work. |
|
138 |
data.cbSize = 504; |
|
139 |
|
|
140 |
//set to fixed timeout |
|
141 |
data.VersionOrTimeout = 10; |
|
142 |
} |
|
143 |
|
|
144 |
data.WindowHandle = handle; |
|
145 |
data.TaskbarIconId = 0x0; |
|
146 |
data.CallbackMessageId = WindowMessageSink.CallbackMessageId; |
|
147 |
data.VersionOrTimeout = (uint) NotifyIconVersion.Win95; |
|
148 |
|
|
149 |
data.IconHandle = IntPtr.Zero; |
|
150 |
|
|
151 |
//hide initially |
|
152 |
data.IconState = IconState.Hidden; |
|
153 |
data.StateMask = IconState.Hidden; |
|
154 |
|
|
155 |
//set flags |
|
156 |
data.ValidMembers = IconDataMembers.Message |
|
157 |
| IconDataMembers.Icon |
|
158 |
| IconDataMembers.Tip; |
|
159 |
|
|
160 |
//reset strings |
|
161 |
data.ToolTipText = data.BalloonText = data.BalloonTitle = String.Empty; |
|
162 |
|
|
163 |
return data; |
|
164 |
} |
|
165 |
} |
|
166 |
} |
b/trunk/NotifyIconWpf/Interop/NotifyIconVersion.cs | ||
---|---|---|
1 |
namespace Hardcodet.Wpf.TaskbarNotification.Interop |
|
2 |
{ |
|
3 |
/// <summary> |
|
4 |
/// The notify icon version that is used. The higher |
|
5 |
/// the version, the more capabilities are available. |
|
6 |
/// </summary> |
|
7 |
public enum NotifyIconVersion |
|
8 |
{ |
|
9 |
/// <summary> |
|
10 |
/// Default behavior (legacy Win95). Expects |
|
11 |
/// a <see cref="NotifyIconData"/> size of 488. |
|
12 |
/// </summary> |
|
13 |
Win95 = 0x0, |
|
14 |
/// <summary> |
|
15 |
/// Behavior representing Win2000 an higher. Expects |
|
16 |
/// a <see cref="NotifyIconData"/> size of 504. |
|
17 |
/// </summary> |
|
18 |
Win2000 = 0x3, |
|
19 |
/// <summary> |
|
20 |
/// Extended tooltip support, which is available |
|
21 |
/// for Vista and later. |
|
22 |
/// </summary> |
|
23 |
Vista = 0x4 |
|
24 |
} |
|
25 |
} |
b/trunk/NotifyIconWpf/Interop/Point.cs | ||
---|---|---|
1 |
using System.Runtime.InteropServices; |
|
2 |
|
|
3 |
namespace Hardcodet.Wpf.TaskbarNotification.Interop |
|
4 |
{ |
|
5 |
/// <summary> |
|
6 |
/// Win API struct providing coordinates for a single point. |
|
7 |
/// </summary> |
|
8 |
[StructLayout(LayoutKind.Sequential)] |
|
9 |
public struct Point |
|
10 |
{ |
|
11 |
public int X; |
|
12 |
public int Y; |
|
13 |
} |
|
14 |
} |
b/trunk/NotifyIconWpf/Interop/TrayInfo.cs | ||
---|---|---|
1 |
// Some interop code taken from Mike Marshall's AnyForm |
|
2 |
|
|
3 |
using System; |
|
4 |
using System.Drawing; |
|
5 |
using System.Runtime.InteropServices; |
|
6 |
|
|
7 |
|
|
8 |
namespace Hardcodet.Wpf.TaskbarNotification.Interop |
|
9 |
{ |
|
10 |
/// <summary> |
|
11 |
/// Resolves the current tray position. |
|
12 |
/// </summary> |
|
13 |
public static class TrayInfo |
|
14 |
{ |
|
15 |
/// <summary> |
|
16 |
/// Gets the position of the system tray. |
|
17 |
/// </summary> |
|
18 |
/// <returns>Tray coordinates.</returns> |
|
19 |
public static Point GetTrayLocation() |
|
20 |
{ |
|
21 |
var info = new AppBarInfo(); |
|
22 |
info.GetSystemTaskBarPosition(); |
|
23 |
|
|
24 |
Rectangle rcWorkArea = info.WorkArea; |
|
25 |
|
|
26 |
int x = 0, y = 0; |
|
27 |
if (info.Edge == AppBarInfo.ScreenEdge.Left) |
|
28 |
{ |
|
29 |
x = rcWorkArea.Left + 2; |
|
30 |
y = rcWorkArea.Bottom; |
|
31 |
} |
|
32 |
else if (info.Edge == AppBarInfo.ScreenEdge.Bottom) |
|
33 |
{ |
|
34 |
x = rcWorkArea.Right; |
|
35 |
y = rcWorkArea.Bottom; |
|
36 |
} |
|
37 |
else if (info.Edge == AppBarInfo.ScreenEdge.Top) |
|
38 |
{ |
|
39 |
x = rcWorkArea.Right; |
|
40 |
y = rcWorkArea.Top; |
|
41 |
} |
|
42 |
else if (info.Edge == AppBarInfo.ScreenEdge.Right) |
|
43 |
{ |
|
44 |
x = rcWorkArea.Right; |
|
45 |
y = rcWorkArea.Bottom; |
|
46 |
} |
|
47 |
|
|
48 |
return new Point { X = x, Y = y}; |
|
49 |
} |
|
50 |
} |
|
51 |
|
|
52 |
|
|
53 |
|
|
54 |
|
|
55 |
internal class AppBarInfo |
|
56 |
{ |
|
57 |
|
|
58 |
[DllImport("user32.dll")] |
|
59 |
private static extern IntPtr FindWindow(String lpClassName, String lpWindowName); |
|
60 |
|
|
61 |
[DllImport("shell32.dll")] |
|
62 |
private static extern UInt32 SHAppBarMessage(UInt32 dwMessage, ref APPBARDATA data); |
|
63 |
|
|
64 |
[DllImport("user32.dll")] |
|
65 |
private static extern Int32 SystemParametersInfo(UInt32 uiAction, UInt32 uiParam, |
|
66 |
IntPtr pvParam, UInt32 fWinIni); |
|
67 |
|
|
68 |
|
|
69 |
private const int ABE_BOTTOM = 3; |
|
70 |
private const int ABE_LEFT = 0; |
|
71 |
private const int ABE_RIGHT = 2; |
|
72 |
private const int ABE_TOP = 1; |
|
73 |
|
|
74 |
private const int ABM_GETTASKBARPOS = 0x00000005; |
|
75 |
|
|
76 |
// SystemParametersInfo constants |
|
77 |
private const UInt32 SPI_GETWORKAREA = 0x0030; |
|
78 |
|
|
79 |
private APPBARDATA m_data; |
|
80 |
|
|
81 |
public ScreenEdge Edge |
|
82 |
{ |
|
83 |
get { return (ScreenEdge) m_data.uEdge; } |
|
84 |
} |
|
85 |
|
|
86 |
|
|
87 |
public Rectangle WorkArea |
|
88 |
{ |
|
89 |
get |
|
90 |
{ |
|
91 |
Int32 bResult = 0; |
|
92 |
var rc = new RECT(); |
|
93 |
IntPtr rawRect = Marshal.AllocHGlobal(Marshal.SizeOf(rc)); |
|
94 |
bResult = SystemParametersInfo(SPI_GETWORKAREA, 0, rawRect, 0); |
|
95 |
rc = (RECT) Marshal.PtrToStructure(rawRect, rc.GetType()); |
|
96 |
|
|
97 |
if (bResult == 1) |
|
98 |
{ |
|
99 |
Marshal.FreeHGlobal(rawRect); |
|
100 |
return new Rectangle(rc.left, rc.top, rc.right - rc.left, rc.bottom - rc.top); |
|
101 |
} |
|
102 |
|
|
103 |
return new Rectangle(0, 0, 0, 0); |
|
104 |
} |
|
105 |
} |
|
106 |
|
|
107 |
|
|
108 |
|
|
109 |
public void GetPosition(string strClassName, string strWindowName) |
|
110 |
{ |
|
111 |
m_data = new APPBARDATA(); |
|
112 |
m_data.cbSize = (UInt32) Marshal.SizeOf(m_data.GetType()); |
|
113 |
|
|
114 |
IntPtr hWnd = FindWindow(strClassName, strWindowName); |
|
115 |
|
|
116 |
if (hWnd != IntPtr.Zero) |
|
117 |
{ |
|
118 |
UInt32 uResult = SHAppBarMessage(ABM_GETTASKBARPOS, ref m_data); |
|
119 |
|
|
120 |
if (uResult != 1) |
|
121 |
{ |
|
122 |
throw new Exception("Failed to communicate with the given AppBar"); |
|
123 |
} |
|
124 |
} |
|
125 |
else |
|
126 |
{ |
|
127 |
throw new Exception("Failed to find an AppBar that matched the given criteria"); |
|
128 |
} |
|
129 |
} |
|
130 |
|
|
131 |
|
|
132 |
public void GetSystemTaskBarPosition() |
|
133 |
{ |
|
134 |
GetPosition("Shell_TrayWnd", null); |
|
135 |
} |
|
136 |
|
|
137 |
|
|
138 |
|
|
139 |
|
|
140 |
public enum ScreenEdge |
|
141 |
{ |
|
142 |
Undefined = -1, |
|
143 |
Left = ABE_LEFT, |
|
144 |
Top = ABE_TOP, |
|
145 |
Right = ABE_RIGHT, |
|
146 |
Bottom = ABE_BOTTOM |
|
147 |
} |
|
148 |
|
|
149 |
|
|
150 |
[StructLayout(LayoutKind.Sequential)] |
|
151 |
private struct APPBARDATA |
|
152 |
{ |
|
153 |
public UInt32 cbSize; |
|
154 |
public IntPtr hWnd; |
|
155 |
public UInt32 uCallbackMessage; |
|
156 |
public UInt32 uEdge; |
|
157 |
public RECT rc; |
|
158 |
public Int32 lParam; |
|
159 |
} |
|
160 |
|
|
161 |
[StructLayout(LayoutKind.Sequential)] |
|
162 |
private struct RECT |
|
163 |
{ |
|
164 |
public Int32 left; |
|
165 |
public Int32 top; |
|
166 |
public Int32 right; |
|
167 |
public Int32 bottom; |
|
168 |
} |
|
169 |
|
|
170 |
} |
|
171 |
} |
b/trunk/NotifyIconWpf/Interop/WinApi.cs | ||
---|---|---|
1 |
using System; |
|
2 |
using System.Runtime.InteropServices; |
|
3 |
|
|
4 |
namespace Hardcodet.Wpf.TaskbarNotification.Interop |
|
5 |
{ |
|
6 |
/// <summary> |
|
7 |
/// Win32 API imports. |
|
8 |
/// </summary> |
|
9 |
internal static class WinApi |
|
10 |
{ |
|
11 |
/// <summary> |
|
12 |
/// Creates, updates or deletes the taskbar icon. |
|
13 |
/// </summary> |
|
14 |
[DllImport("shell32.Dll")] |
|
15 |
public static extern bool Shell_NotifyIcon(NotifyCommand cmd, [In]ref NotifyIconData data); |
|
16 |
|
|
17 |
|
|
18 |
/// <summary> |
|
19 |
/// Creates the helper window that receives messages from the taskar icon. |
|
20 |
/// </summary> |
|
21 |
[DllImport("USER32.DLL", EntryPoint = "CreateWindowExW", SetLastError = true)] |
|
22 |
public static extern IntPtr CreateWindowEx(int dwExStyle, [MarshalAs(UnmanagedType.LPWStr)] string lpClassName, |
|
23 |
[MarshalAs(UnmanagedType.LPWStr)] string lpWindowName, int dwStyle, int x, int y, |
|
24 |
int nWidth, int nHeight, uint hWndParent, int hMenu, int hInstance, |
|
25 |
int lpParam); |
|
26 |
|
|
27 |
|
|
28 |
/// <summary> |
|
29 |
/// Processes a default windows procedure. |
|
30 |
/// </summary> |
|
31 |
[DllImport("USER32.DLL")] |
|
32 |
public static extern long DefWindowProc(IntPtr hWnd, uint msg, uint wparam, uint lparam); |
|
33 |
|
|
34 |
/// <summary> |
|
35 |
/// Registers the helper window class. |
|
36 |
/// </summary> |
|
37 |
[DllImport("USER32.DLL", EntryPoint = "RegisterClassW", SetLastError = true)] |
|
38 |
public static extern short RegisterClass(ref WindowClass lpWndClass); |
|
39 |
|
|
40 |
/// <summary> |
|
41 |
/// Registers a listener for a window message. |
|
42 |
/// </summary> |
|
43 |
/// <param name="lpString"></param> |
|
44 |
/// <returns></returns> |
|
45 |
[DllImport("User32.Dll", EntryPoint = "RegisterWindowMessageW")] |
|
46 |
public static extern uint RegisterWindowMessage([MarshalAs(UnmanagedType.LPWStr)] string lpString); |
|
47 |
|
|
48 |
/// <summary> |
|
49 |
/// Used to destroy the hidden helper window that receives messages from the |
|
50 |
/// taskbar icon. |
|
51 |
/// </summary> |
|
52 |
/// <param name="hWnd"></param> |
|
53 |
/// <returns></returns> |
|
54 |
[DllImport("USER32.DLL", SetLastError = true)] |
|
55 |
public static extern bool DestroyWindow(IntPtr hWnd); |
|
56 |
|
|
57 |
|
|
58 |
/// <summary> |
|
59 |
/// Gives focus to a given window. |
|
60 |
/// </summary> |
|
61 |
/// <param name="hWnd"></param> |
|
62 |
/// <returns></returns> |
|
63 |
[DllImport("USER32.DLL")] |
|
64 |
public static extern bool SetForegroundWindow(IntPtr hWnd); |
|
65 |
|
|
66 |
|
|
67 |
/// <summary> |
|
68 |
/// Gets the maximum number of milliseconds that can elapse between a |
|
69 |
/// first click and a second click for the OS to consider the |
|
70 |
/// mouse action a double-click. |
|
71 |
/// </summary> |
|
72 |
/// <returns>The maximum amount of time, in milliseconds, that can |
|
73 |
/// elapse between a first click and a second click for the OS to |
|
74 |
/// consider the mouse action a double-click.</returns> |
|
75 |
[DllImport("user32.dll", CharSet = CharSet.Auto, ExactSpelling = true)] |
|
76 |
public static extern int GetDoubleClickTime(); |
|
77 |
|
|
78 |
|
|
79 |
/// <summary> |
|
80 |
/// Gets the screen coordinates of the current mouse position. |
|
81 |
/// </summary> |
|
82 |
/// <param name="lpPoint"></param> |
|
83 |
/// <returns></returns> |
|
84 |
[DllImport("USER32.DLL", SetLastError = true)] |
|
85 |
public static extern bool GetCursorPos(ref Point lpPoint); |
|
86 |
} |
|
87 |
} |
b/trunk/NotifyIconWpf/Interop/WindowClass.cs | ||
---|---|---|
1 |
using System; |
|
2 |
using System.Runtime.InteropServices; |
|
3 |
|
|
4 |
namespace Hardcodet.Wpf.TaskbarNotification.Interop |
|
5 |
{ |
|
6 |
/// <summary> |
|
7 |
/// Callback delegate which is used by the Windows API to |
|
8 |
/// submit window messages. |
|
9 |
/// </summary> |
|
10 |
public delegate long WindowProcedureHandler(IntPtr hwnd, uint uMsg, uint wparam, uint lparam); |
|
11 |
|
|
12 |
|
|
13 |
/// <summary> |
|
14 |
/// Win API WNDCLASS struct - represents a single window. |
|
15 |
/// Used to receive window messages. |
|
16 |
/// </summary> |
|
17 |
[StructLayout(LayoutKind.Sequential)] |
|
18 |
public struct WindowClass |
|
19 |
{ |
|
20 |
public uint style; |
|
21 |
public WindowProcedureHandler lpfnWndProc; |
|
22 |
public int cbClsExtra; |
|
23 |
public int cbWndExtra; |
|
24 |
public IntPtr hInstance; |
|
25 |
public IntPtr hIcon; |
|
26 |
public IntPtr hCursor; |
|
27 |
public IntPtr hbrBackground; |
|
28 |
[MarshalAs(UnmanagedType.LPWStr)] public string lpszMenuName; |
|
29 |
[MarshalAs(UnmanagedType.LPWStr)] public string lpszClassName; |
|
30 |
} |
|
31 |
} |
b/trunk/NotifyIconWpf/Interop/WindowMessageSink.cs | ||
---|---|---|
1 |
// hardcodet.net NotifyIcon for WPF |
|
2 |
// Copyright (c) 2009 Philipp Sumi |
|
3 |
// Contact and Information: http://www.hardcodet.net |
|
4 |
// |
|
5 |
// This library is free software; you can redistribute it and/or |
|
6 |
// modify it under the terms of the Code Project Open License (CPOL); |
|
7 |
// either version 1.0 of the License, or (at your option) any later |
|
8 |
// version. |
|
9 |
// |
|
10 |
// The above copyright notice and this permission notice shall be |
|
11 |
// included in all copies or substantial portions of the Software. |
|
12 |
// |
|
13 |
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, |
|
14 |
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES |
|
15 |
// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
|
16 |
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT |
|
17 |
// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, |
|
18 |
// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
|
19 |
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR |
|
20 |
// OTHER DEALINGS IN THE SOFTWARE. |
|
21 |
// |
|
22 |
// THIS COPYRIGHT NOTICE MAY NOT BE REMOVED FROM THIS FILE |
|
23 |
|
|
24 |
|
|
25 |
|
|
26 |
using System; |
|
27 |
using System.ComponentModel; |
|
28 |
using System.Diagnostics; |
|
29 |
|
|
30 |
namespace Hardcodet.Wpf.TaskbarNotification.Interop |
|
31 |
{ |
|
32 |
/// <summary> |
|
33 |
/// Receives messages from the taskbar icon through |
|
34 |
/// window messages of an underlying helper window. |
|
35 |
/// </summary> |
|
36 |
public class WindowMessageSink : IDisposable |
|
37 |
{ |
|
38 |
|
|
39 |
#region members |
|
40 |
|
|
41 |
/// <summary> |
|
42 |
/// The ID of messages that are received from the the |
|
43 |
/// taskbar icon. |
|
44 |
/// </summary> |
|
45 |
public const int CallbackMessageId = 0x400; |
|
46 |
|
|
47 |
/// <summary> |
|
48 |
/// The ID of the message that is being received if the |
|
49 |
/// taskbar is (re)started. |
|
50 |
/// </summary> |
|
51 |
private uint taskbarRestartMessageId; |
|
52 |
|
|
53 |
/// <summary> |
|
54 |
/// Used to track whether a mouse-up event is just |
|
55 |
/// the aftermath of a double-click and therefore needs |
|
56 |
/// to be suppressed. |
|
57 |
/// </summary> |
|
58 |
private bool isDoubleClick; |
|
59 |
|
|
60 |
/// <summary> |
|
61 |
/// A delegate that processes messages of the hidden |
|
62 |
/// native window that receives window messages. Storing |
|
63 |
/// this reference makes sure we don't loose our reference |
|
64 |
/// to the message window. |
|
65 |
/// </summary> |
|
66 |
private WindowProcedureHandler messageHandler; |
|
67 |
|
|
68 |
/// <summary> |
|
69 |
/// Window class ID. |
|
70 |
/// </summary> |
|
71 |
internal string WindowId { get; private set; } |
|
72 |
|
|
73 |
/// <summary> |
|
74 |
/// Handle for the message window. |
|
75 |
/// </summary |
|
76 |
internal IntPtr MessageWindowHandle { get; private set; } |
|
77 |
|
|
78 |
/// <summary> |
|
79 |
/// The version of the underlying icon. Defines how |
|
80 |
/// incoming messages are interpreted. |
|
81 |
/// </summary> |
|
82 |
public NotifyIconVersion Version { get; set; } |
|
83 |
|
|
84 |
#endregion |
|
85 |
|
|
86 |
|
|
87 |
#region events |
|
88 |
|
|
89 |
/// <summary> |
|
90 |
/// The custom tooltip should be closed or hidden. |
|
91 |
/// </summary> |
|
92 |
public event Action<bool> ChangeToolTipStateRequest; |
|
93 |
|
|
94 |
/// <summary> |
|
95 |
/// Fired in case the user clicked or moved within |
|
96 |
/// the taskbar icon area. |
|
97 |
/// </summary> |
|
98 |
public event Action<MouseEvent> MouseEventReceived; |
|
99 |
|
|
100 |
/// <summary> |
|
101 |
/// Fired if a balloon ToolTip was either displayed |
|
102 |
/// or closed (indicated by the boolean flag). |
|
103 |
/// </summary> |
|
104 |
public event Action<bool> BalloonToolTipChanged; |
|
105 |
|
|
106 |
/// <summary> |
|
107 |
/// Fired if the taskbar was created or restarted. Requires the taskbar |
|
108 |
/// icon to be reset. |
|
109 |
/// </summary> |
|
110 |
public event Action TaskbarCreated; |
|
111 |
|
|
112 |
#endregion |
|
113 |
|
|
114 |
|
|
115 |
#region construction |
|
116 |
|
|
117 |
/// <summary> |
|
118 |
/// Creates a new message sink that receives message from |
|
119 |
/// a given taskbar icon. |
|
120 |
/// </summary> |
|
121 |
/// <param name="version"></param> |
|
122 |
public WindowMessageSink(NotifyIconVersion version) |
|
123 |
{ |
|
124 |
Version = version; |
|
125 |
CreateMessageWindow(); |
|
126 |
} |
|
127 |
|
|
128 |
|
|
129 |
private WindowMessageSink() |
|
130 |
{ |
|
131 |
} |
|
132 |
|
|
133 |
|
|
134 |
/// <summary> |
|
135 |
/// Creates a dummy instance that provides an empty |
|
136 |
/// pointer rather than a real window handler.<br/> |
|
137 |
/// Used at design time. |
|
138 |
/// </summary> |
|
139 |
/// <returns></returns> |
|
140 |
internal static WindowMessageSink CreateEmpty() |
|
141 |
{ |
|
142 |
return new WindowMessageSink |
|
143 |
{ |
|
144 |
MessageWindowHandle = IntPtr.Zero, |
|
145 |
Version = NotifyIconVersion.Vista |
|
146 |
}; |
|
147 |
} |
|
148 |
|
|
149 |
#endregion |
|
150 |
|
|
151 |
|
|
152 |
#region CreateMessageWindow |
|
153 |
|
|
154 |
/// <summary> |
|
155 |
/// Creates the helper message window that is used |
|
156 |
/// to receive messages from the taskbar icon. |
|
157 |
/// </summary> |
|
158 |
private void CreateMessageWindow() |
|
159 |
{ |
|
160 |
//generate a unique ID for the window |
|
161 |
WindowId = "WPFTaskbarIcon_" + DateTime.Now.Ticks; |
|
162 |
|
|
163 |
//register window message handler |
|
164 |
messageHandler = OnWindowMessageReceived; |
|
165 |
|
|
166 |
// Create a simple window class which is reference through |
|
167 |
//the messageHandler delegate |
|
168 |
WindowClass wc; |
|
169 |
|
|
170 |
wc.style = 0; |
|
171 |
wc.lpfnWndProc = messageHandler; |
|
172 |
wc.cbClsExtra = 0; |
|
173 |
wc.cbWndExtra = 0; |
|
174 |
wc.hInstance = IntPtr.Zero; |
|
175 |
wc.hIcon = IntPtr.Zero; |
|
176 |
wc.hCursor = IntPtr.Zero; |
|
177 |
wc.hbrBackground = IntPtr.Zero; |
|
178 |
wc.lpszMenuName = ""; |
|
179 |
wc.lpszClassName = WindowId; |
|
180 |
|
|
181 |
// Register the window class |
|
182 |
WinApi.RegisterClass(ref wc); |
|
183 |
|
|
184 |
// Get the message used to indicate the taskbar has been restarted |
|
185 |
// This is used to re-add icons when the taskbar restarts |
|
186 |
taskbarRestartMessageId = WinApi.RegisterWindowMessage("TaskbarCreated"); |
|
187 |
|
|
188 |
// Create the message window |
|
189 |
MessageWindowHandle = WinApi.CreateWindowEx(0, WindowId, "", 0, 0, 0, 1, 1, 0, 0, 0, 0); |
|
190 |
|
|
191 |
if (MessageWindowHandle == IntPtr.Zero) |
|
192 |
{ |
|
193 |
throw new Win32Exception(); |
|
194 |
} |
|
195 |
} |
|
196 |
|
|
197 |
#endregion |
|
198 |
|
|
199 |
|
|
200 |
#region Handle Window Messages |
|
201 |
|
|
202 |
/// <summary> |
|
203 |
/// Callback method that receives messages from the taskbar area. |
|
204 |
/// </summary> |
|
205 |
private long OnWindowMessageReceived(IntPtr hwnd, uint messageId, uint wparam, uint lparam) |
|
206 |
{ |
|
207 |
if (messageId == taskbarRestartMessageId) |
|
208 |
{ |
|
209 |
//recreate the icon if the taskbar was restarted (e.g. due to Win Explorer shutdown) |
|
210 |
TaskbarCreated(); |
|
211 |
} |
|
212 |
|
|
213 |
//forward message |
|
214 |
ProcessWindowMessage(messageId, wparam, lparam); |
|
215 |
|
|
216 |
// Pass the message to the default window procedure |
|
217 |
return WinApi.DefWindowProc(hwnd, messageId, wparam, lparam); |
|
218 |
} |
|
219 |
|
|
220 |
|
|
221 |
/// <summary> |
|
222 |
/// Processes incoming system messages. |
|
223 |
/// </summary> |
|
224 |
/// <param name="msg">Callback ID.</param> |
|
225 |
/// <param name="wParam">If the version is <see cref="NotifyIconVersion.Vista"/> |
|
226 |
/// or higher, this parameter can be used to resolve mouse coordinates. |
|
227 |
/// Currently not in use.</param> |
|
228 |
/// <param name="lParam">Provides information about the event.</param> |
|
229 |
private void ProcessWindowMessage(uint msg, uint wParam, uint lParam) |
|
230 |
{ |
|
231 |
if (msg != CallbackMessageId) return; |
|
232 |
|
|
233 |
switch (lParam) |
|
234 |
{ |
|
235 |
case 0x200: |
|
236 |
MouseEventReceived(MouseEvent.MouseMove); |
|
237 |
break; |
|
238 |
|
|
239 |
case 0x201: |
|
240 |
MouseEventReceived(MouseEvent.IconLeftMouseDown); |
|
241 |
break; |
|
242 |
|
|
243 |
case 0x202: |
|
244 |
if (!isDoubleClick) |
|
245 |
{ |
|
246 |
MouseEventReceived(MouseEvent.IconLeftMouseUp); |
|
247 |
} |
|
248 |
isDoubleClick = false; |
|
249 |
break; |
|
250 |
|
|
251 |
case 0x203: |
|
252 |
isDoubleClick = true; |
|
253 |
MouseEventReceived(MouseEvent.IconDoubleClick); |
|
254 |
break; |
|
255 |
|
|
256 |
case 0x204: |
|
257 |
MouseEventReceived(MouseEvent.IconRightMouseDown); |
|
258 |
break; |
|
259 |
|
|
260 |
case 0x205: |
|
261 |
MouseEventReceived(MouseEvent.IconRightMouseUp); |
|
262 |
break; |
|
263 |
|
|
264 |
case 0x206: |
|
265 |
//double click with right mouse button - do not trigger event |
|
266 |
break; |
|
267 |
|
|
268 |
case 0x207: |
|
269 |
MouseEventReceived(MouseEvent.IconMiddleMouseDown); |
|
270 |
break; |
|
271 |
|
|
272 |
case 520: |
|
273 |
MouseEventReceived(MouseEvent.IconMiddleMouseUp); |
|
274 |
break; |
|
275 |
|
|
276 |
case 0x209: |
|
277 |
//double click with middle mouse button - do not trigger event |
|
278 |
break; |
|
279 |
|
|
280 |
case 0x402: |
|
281 |
BalloonToolTipChanged(true); |
|
282 |
break; |
|
283 |
|
|
284 |
case 0x403: |
|
285 |
case 0x404: |
|
286 |
BalloonToolTipChanged(false); |
|
287 |
break; |
|
288 |
|
|
289 |
case 0x405: |
|
290 |
MouseEventReceived(MouseEvent.BalloonToolTipClicked); |
|
291 |
break; |
|
292 |
|
|
293 |
case 0x406: |
|
294 |
ChangeToolTipStateRequest(true); |
|
295 |
break; |
|
296 |
|
|
297 |
case 0x407: |
|
298 |
ChangeToolTipStateRequest(false); |
|
299 |
break; |
|
300 |
|
|
301 |
default: |
|
302 |
Debug.WriteLine("Unhandled NotifyIcon message ID: " + lParam); |
|
303 |
break; |
|
304 |
} |
|
305 |
|
|
306 |
} |
|
307 |
|
|
308 |
#endregion |
|
309 |
|
|
310 |
|
|
311 |
#region Dispose |
|
312 |
|
|
313 |
/// <summary> |
|
314 |
/// Set to true as soon as <see cref="Dispose"/> |
|
315 |
/// has been invoked. |
|
316 |
/// </summary> |
|
317 |
public bool IsDisposed { get; private set; } |
|
318 |
|
|
319 |
|
|
320 |
/// <summary> |
|
321 |
/// Disposes the object. |
|
322 |
/// </summary> |
|
323 |
/// <remarks>This method is not virtual by design. Derived classes |
|
324 |
/// should override <see cref="Dispose(bool)"/>. |
|
325 |
/// </remarks> |
|
326 |
public void Dispose() |
|
327 |
{ |
|
328 |
Dispose(true); |
|
329 |
|
|
330 |
// This object will be cleaned up by the Dispose method. |
|
331 |
// Therefore, you should call GC.SupressFinalize to |
|
332 |
// take this object off the finalization queue |
|
333 |
// and prevent finalization code for this object |
|
334 |
// from executing a second time. |
|
335 |
GC.SuppressFinalize(this); |
|
336 |
} |
|
337 |
|
|
338 |
/// <summary> |
|
339 |
/// This destructor will run only if the <see cref="Dispose()"/> |
|
340 |
/// method does not get called. This gives this base class the |
|
341 |
/// opportunity to finalize. |
|
342 |
/// <para> |
|
343 |
/// Important: Do not provide destructors in types derived from |
|
344 |
/// this class. |
|
345 |
/// </para> |
|
346 |
/// </summary> |
|
347 |
~WindowMessageSink() |
|
348 |
{ |
|
349 |
Dispose(false); |
|
350 |
} |
|
351 |
|
|
352 |
|
|
353 |
/// <summary> |
|
354 |
/// Removes the windows hook that receives window |
|
355 |
/// messages and closes the underlying helper window. |
|
356 |
/// </summary> |
|
357 |
private void Dispose(bool disposing) |
|
358 |
{ |
|
359 |
//don't do anything if the component is already disposed |
|
360 |
if (IsDisposed || !disposing) return; |
|
361 |
IsDisposed = true; |
|
362 |
|
|
363 |
WinApi.DestroyWindow(MessageWindowHandle); |
|
364 |
messageHandler = null; |
|
365 |
} |
|
366 |
|
|
367 |
#endregion |
|
368 |
} |
|
369 |
} |
b/trunk/NotifyIconWpf/NotifyIconWpf.csproj | ||
---|---|---|
1 |
<?xml version="1.0" encoding="utf-8"?> |
|
2 |
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> |
|
3 |
<PropertyGroup> |
|
4 |
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> |
|
5 |
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform> |
|
6 |
<ProductVersion>9.0.30729</ProductVersion> |
|
7 |
<SchemaVersion>2.0</SchemaVersion> |
|
8 |
<ProjectGuid>{7AC63864-7638-41C4-969C-D3197EF2BED9}</ProjectGuid> |
|
9 |
<OutputType>library</OutputType> |
|
10 |
<AppDesignerFolder>Properties</AppDesignerFolder> |
|
11 |
<RootNamespace>Hardcodet.Wpf.TaskbarNotification</RootNamespace> |
|
12 |
<AssemblyName>Hardcodet.Wpf.TaskbarNotification</AssemblyName> |
|
13 |
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion> |
|
14 |
<FileAlignment>512</FileAlignment> |
|
15 |
<ProjectTypeGuids>{60dc8134-eba5-43b8-bcc9-bb4bc16c2548};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids> |
|
16 |
<WarningLevel>4</WarningLevel> |
|
17 |
<TargetFrameworkProfile>Client</TargetFrameworkProfile> |
|
18 |
<FileUpgradeFlags> |
|
19 |
</FileUpgradeFlags> |
|
20 |
<UpgradeBackupLocation> |
|
21 |
</UpgradeBackupLocation> |
|
22 |
<OldToolsVersion>3.5</OldToolsVersion> |
|
23 |
<PublishUrl>publish\</PublishUrl> |
|
24 |
<Install>true</Install> |
|
25 |
<InstallFrom>Disk</InstallFrom> |
|
26 |
<UpdateEnabled>false</UpdateEnabled> |
|
27 |
<UpdateMode>Foreground</UpdateMode> |
|
28 |
<UpdateInterval>7</UpdateInterval> |
|
29 |
<UpdateIntervalUnits>Days</UpdateIntervalUnits> |
|
30 |
<UpdatePeriodically>false</UpdatePeriodically> |
|
31 |
<UpdateRequired>false</UpdateRequired> |
|
32 |
<MapFileExtensions>true</MapFileExtensions> |
|
33 |
<ApplicationRevision>0</ApplicationRevision> |
|
34 |
<ApplicationVersion>1.0.0.%2a</ApplicationVersion> |
|
35 |
<IsWebBootstrapper>false</IsWebBootstrapper> |
|
36 |
<UseApplicationTrust>false</UseApplicationTrust> |
|
37 |
<BootstrapperEnabled>true</BootstrapperEnabled> |
|
38 |
</PropertyGroup> |
|
39 |
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> |
|
40 |
<DebugSymbols>true</DebugSymbols> |
|
41 |
<DebugType>full</DebugType> |
|
42 |
<Optimize>false</Optimize> |
|
43 |
<OutputPath>bin\Debug\</OutputPath> |
|
44 |
<DefineConstants>DEBUG;TRACE</DefineConstants> |
|
45 |
<ErrorReport>prompt</ErrorReport> |
|
46 |
<WarningLevel>4</WarningLevel> |
|
47 |
<PlatformTarget>AnyCPU</PlatformTarget> |
|
48 |
<CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet> |
|
49 |
</PropertyGroup> |
|
50 |
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "> |
|
51 |
<DebugType>pdbonly</DebugType> |
|
52 |
<Optimize>true</Optimize> |
|
53 |
<OutputPath>bin\Release\</OutputPath> |
|
54 |
<DefineConstants>TRACE</DefineConstants> |
|
55 |
<ErrorReport>prompt</ErrorReport> |
|
56 |
<WarningLevel>4</WarningLevel> |
|
57 |
<DocumentationFile>bin\Release\Hardcodet.Wpf.TaskbarNotification.xml</DocumentationFile> |
|
58 |
<CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet> |
|
59 |
</PropertyGroup> |
|
60 |
<PropertyGroup> |
|
61 |
<SignAssembly>true</SignAssembly> |
|
62 |
</PropertyGroup> |
|
63 |
<PropertyGroup> |
|
64 |
<AssemblyOriginatorKeyFile>pithos.snk</AssemblyOriginatorKeyFile> |
|
65 |
</PropertyGroup> |
|
66 |
<ItemGroup> |
|
67 |
<Reference Include="System" /> |
|
68 |
<Reference Include="System.Core"> |
|
69 |
<RequiredTargetFramework>3.5</RequiredTargetFramework> |
|
70 |
</Reference> |
|
71 |
<Reference Include="System.Drawing" /> |
|
72 |
<Reference Include="System.Xaml" /> |
|
73 |
<Reference Include="WindowsBase" /> |
|
74 |
<Reference Include="PresentationCore" /> |
|
75 |
<Reference Include="PresentationFramework" /> |
|
76 |
</ItemGroup> |
|
77 |
<ItemGroup> |
|
78 |
<Compile Include="BalloonIcon.cs" /> |
|
79 |
<Compile Include="Interop\TrayInfo.cs"> |
|
80 |
<SubType>Code</SubType> |
|
81 |
</Compile> |
|
82 |
<Compile Include="Interop\Point.cs" /> |
|
83 |
<Compile Include="Interop\WindowClass.cs" /> |
|
84 |
<Compile Include="PopupActivationMode.cs" /> |
|
85 |
<Compile Include="RoutedEventHelper.cs" /> |
|
86 |
<Compile Include="Interop\WinApi.cs" /> |
|
87 |
<Compile Include="Interop\MouseEvent.cs" /> |
|
88 |
<Compile Include="Interop\NotifyCommand.cs" /> |
|
89 |
<Compile Include="Interop\NotifyIconData.cs" /> |
|
90 |
<Compile Include="Interop\IconDataMembers.cs" /> |
|
91 |
<Compile Include="Interop\IconState.cs" /> |
|
92 |
<Compile Include="Interop\NotifyIconVersion.cs" /> |
|
93 |
<Compile Include="Interop\BalloonFlags.cs" /> |
|
94 |
<Compile Include="Interop\WindowMessageSink.cs" /> |
|
95 |
<Compile Include="Properties\AssemblyInfo.cs"> |
|
96 |
<SubType>Code</SubType> |
|
97 |
</Compile> |
|
98 |
<Compile Include="Properties\Resources.Designer.cs"> |
|
99 |
<AutoGen>True</AutoGen> |
|
100 |
<DesignTime>True</DesignTime> |
|
101 |
<DependentUpon>Resources.resx</DependentUpon> |
|
102 |
</Compile> |
|
103 |
<Compile Include="TaskbarIcon.cs" /> |
|
104 |
<Compile Include="TaskbarIcon.Declarations.cs" /> |
|
105 |
<Compile Include="Util.cs" /> |
|
106 |
<EmbeddedResource Include="Properties\Resources.resx"> |
|
107 |
<Generator>ResXFileCodeGenerator</Generator> |
|
108 |
<LastGenOutput>Resources.Designer.cs</LastGenOutput> |
|
109 |
</EmbeddedResource> |
|
110 |
<None Include="Diagrams\TaskbarIcon Overview.cd" /> |
|
111 |
<AppDesigner Include="Properties\" /> |
|
112 |
<None Include="pithos.snk" /> |
|
113 |
</ItemGroup> |
|
114 |
<ItemGroup> |
|
115 |
<Resource Include="DefaultTrayIcon.ico" /> |
|
116 |
</ItemGroup> |
|
117 |
<ItemGroup> |
|
118 |
<BootstrapperPackage Include="Microsoft.Net.Client.3.5"> |
|
119 |
<Visible>False</Visible> |
|
120 |
<ProductName>.NET Framework 3.5 SP1 Client Profile</ProductName> |
|
121 |
<Install>false</Install> |
|
122 |
</BootstrapperPackage> |
|
123 |
<BootstrapperPackage Include="Microsoft.Net.Framework.3.5.SP1"> |
|
124 |
<Visible>False</Visible> |
|
125 |
<ProductName>.NET Framework 3.5 SP1</ProductName> |
|
126 |
<Install>true</Install> |
|
127 |
</BootstrapperPackage> |
|
128 |
<BootstrapperPackage Include="Microsoft.Windows.Installer.3.1"> |
|
129 |
<Visible>False</Visible> |
|
130 |
<ProductName>Windows Installer 3.1</ProductName> |
|
131 |
<Install>true</Install> |
|
132 |
</BootstrapperPackage> |
|
133 |
</ItemGroup> |
|
134 |
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> |
|
135 |
<!-- To modify your build process, add your task inside one of the targets below and uncomment it. |
|
136 |
Other similar extension points exist, see Microsoft.Common.targets. |
|
137 |
<Target Name="BeforeBuild"> |
|
138 |
</Target> |
|
139 |
<Target Name="AfterBuild"> |
|
140 |
</Target> |
|
141 |
--> |
|
142 |
</Project> |
b/trunk/NotifyIconWpf/PopupActivationMode.cs | ||
---|---|---|
1 |
// hardcodet.net NotifyIcon for WPF |
|
2 |
// Copyright (c) 2009 Philipp Sumi |
|
3 |
// Contact and Information: http://www.hardcodet.net |
|
4 |
// |
|
5 |
// This library is free software; you can redistribute it and/or |
|
6 |
// modify it under the terms of the Code Project Open License (CPOL); |
|
7 |
// either version 1.0 of the License, or (at your option) any later |
|
8 |
// version. |
|
9 |
// |
|
10 |
// The above copyright notice and this permission notice shall be |
|
11 |
// included in all copies or substantial portions of the Software. |
|
12 |
// |
|
13 |
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, |
|
14 |
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES |
|
15 |
// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
|
16 |
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT |
|
17 |
// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, |
|
18 |
// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
|
19 |
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR |
|
20 |
// OTHER DEALINGS IN THE SOFTWARE. |
|
21 |
// |
|
22 |
// THIS COPYRIGHT NOTICE MAY NOT BE REMOVED FROM THIS FILE |
|
23 |
|
|
24 |
|
|
25 |
namespace Hardcodet.Wpf.TaskbarNotification |
|
26 |
{ |
|
27 |
/// <summary> |
|
28 |
/// Defines flags that define when a popup |
|
29 |
/// is being displyed. |
|
30 |
/// </summary> |
|
31 |
public enum PopupActivationMode |
|
32 |
{ |
|
33 |
/// <summary> |
|
34 |
/// The item is displayed if the user clicks the |
|
35 |
/// tray icon with the left mouse button. |
|
36 |
/// </summary> |
|
37 |
LeftClick, |
|
38 |
/// <summary> |
|
39 |
/// The item is displayed if the user clicks the |
|
40 |
/// tray icon with the right mouse button. |
|
41 |
/// </summary> |
|
42 |
RightClick, |
|
43 |
/// <summary> |
|
44 |
/// The item is displayed if the user double-clicks the |
|
45 |
/// tray icon. |
|
46 |
/// </summary> |
|
47 |
DoubleClick, |
|
48 |
/// <summary> |
|
49 |
/// The item is displayed if the user clicks the |
|
50 |
/// tray icon with the left or the right mouse button. |
|
51 |
/// </summary> |
|
52 |
LeftOrRightClick, |
|
53 |
/// <summary> |
|
54 |
/// The item is displayed if the user clicks the |
|
55 |
/// tray icon with the left mouse button or if a |
|
56 |
/// double-click is being performed. |
|
57 |
/// </summary> |
|
58 |
LeftOrDoubleClick, |
|
59 |
/// <summary> |
|
60 |
/// The item is displayed if the user clicks the |
|
61 |
/// tray icon with the middle mouse button. |
|
62 |
/// </summary> |
|
63 |
MiddleClick, |
|
64 |
/// <summary> |
|
65 |
/// The item is displayed whenever a click occurs. |
Also available in: Unified diff