root / trunk / NotifyIconWpf / Interop / NotifyIconData.cs @ 049333d2
History | View | Annotate | Download (5.9 kB)
1 | 9bae55d1 | Panagiotis Kanavos | using System; |
---|---|---|---|
2 | 9bae55d1 | Panagiotis Kanavos | using System.Drawing; |
3 | 9bae55d1 | Panagiotis Kanavos | using System.Runtime.InteropServices; |
4 | 9bae55d1 | Panagiotis Kanavos | |
5 | 9bae55d1 | Panagiotis Kanavos | namespace Hardcodet.Wpf.TaskbarNotification.Interop |
6 | 9bae55d1 | Panagiotis Kanavos | { |
7 | 9bae55d1 | Panagiotis Kanavos | /// <summary> |
8 | 9bae55d1 | Panagiotis Kanavos | /// A struct that is submitted in order to configure |
9 | 9bae55d1 | Panagiotis Kanavos | /// the taskbar icon. Provides various members that |
10 | 9bae55d1 | Panagiotis Kanavos | /// can be configured partially, according to the |
11 | 9bae55d1 | Panagiotis Kanavos | /// values of the <see cref="IconDataMembers"/> |
12 | 9bae55d1 | Panagiotis Kanavos | /// that were defined. |
13 | 9bae55d1 | Panagiotis Kanavos | /// </summary> |
14 | 9bae55d1 | Panagiotis Kanavos | [StructLayout(LayoutKind.Sequential)] |
15 | 9bae55d1 | Panagiotis Kanavos | public struct NotifyIconData |
16 | 9bae55d1 | Panagiotis Kanavos | { |
17 | 9bae55d1 | Panagiotis Kanavos | /// <summary> |
18 | 9bae55d1 | Panagiotis Kanavos | /// Size of this structure, in bytes. |
19 | 9bae55d1 | Panagiotis Kanavos | /// </summary> |
20 | 9bae55d1 | Panagiotis Kanavos | public uint cbSize; |
21 | 9bae55d1 | Panagiotis Kanavos | |
22 | 9bae55d1 | Panagiotis Kanavos | /// <summary> |
23 | 9bae55d1 | Panagiotis Kanavos | /// Handle to the window that receives notification messages associated with an icon in the |
24 | 9bae55d1 | Panagiotis Kanavos | /// taskbar status area. The Shell uses hWnd and uID to identify which icon to operate on |
25 | 9bae55d1 | Panagiotis Kanavos | /// when Shell_NotifyIcon is invoked. |
26 | 9bae55d1 | Panagiotis Kanavos | /// </summary> |
27 | 9bae55d1 | Panagiotis Kanavos | public IntPtr WindowHandle; |
28 | 9bae55d1 | Panagiotis Kanavos | |
29 | 9bae55d1 | Panagiotis Kanavos | /// <summary> |
30 | 9bae55d1 | Panagiotis Kanavos | /// Application-defined identifier of the taskbar icon. The Shell uses hWnd and uID to identify |
31 | 9bae55d1 | Panagiotis Kanavos | /// which icon to operate on when Shell_NotifyIcon is invoked. You can have multiple icons |
32 | 9bae55d1 | Panagiotis Kanavos | /// associated with a single hWnd by assigning each a different uID. This feature, however |
33 | 9bae55d1 | Panagiotis Kanavos | /// is currently not used. |
34 | 9bae55d1 | Panagiotis Kanavos | /// </summary> |
35 | 9bae55d1 | Panagiotis Kanavos | public uint TaskbarIconId; |
36 | 9bae55d1 | Panagiotis Kanavos | |
37 | 9bae55d1 | Panagiotis Kanavos | /// <summary> |
38 | 9bae55d1 | Panagiotis Kanavos | /// Flags that indicate which of the other members contain valid data. This member can be |
39 | 9bae55d1 | Panagiotis Kanavos | /// a combination of the NIF_XXX constants. |
40 | 9bae55d1 | Panagiotis Kanavos | /// </summary> |
41 | 9bae55d1 | Panagiotis Kanavos | public IconDataMembers ValidMembers; |
42 | 9bae55d1 | Panagiotis Kanavos | |
43 | 9bae55d1 | Panagiotis Kanavos | /// <summary> |
44 | 9bae55d1 | Panagiotis Kanavos | /// Application-defined message identifier. The system uses this identifier to send |
45 | 9bae55d1 | Panagiotis Kanavos | /// notifications to the window identified in hWnd. |
46 | 9bae55d1 | Panagiotis Kanavos | /// </summary> |
47 | 9bae55d1 | Panagiotis Kanavos | public uint CallbackMessageId; |
48 | 9bae55d1 | Panagiotis Kanavos | |
49 | 9bae55d1 | Panagiotis Kanavos | /// <summary> |
50 | 9bae55d1 | Panagiotis Kanavos | /// A handle to the icon that should be displayed. Just |
51 | 9bae55d1 | Panagiotis Kanavos | /// <see cref="Icon.Handle"/>. |
52 | 9bae55d1 | Panagiotis Kanavos | /// </summary> |
53 | 9bae55d1 | Panagiotis Kanavos | public IntPtr IconHandle; |
54 | 9bae55d1 | Panagiotis Kanavos | |
55 | 9bae55d1 | Panagiotis Kanavos | /// <summary> |
56 | 9bae55d1 | Panagiotis Kanavos | /// String with the text for a standard ToolTip. It can have a maximum of 64 characters including |
57 | 9bae55d1 | Panagiotis Kanavos | /// the terminating NULL. For Version 5.0 and later, szTip can have a maximum of |
58 | 9bae55d1 | Panagiotis Kanavos | /// 128 characters, including the terminating NULL. |
59 | 9bae55d1 | Panagiotis Kanavos | /// </summary> |
60 | 9bae55d1 | Panagiotis Kanavos | [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 128)] public string ToolTipText; |
61 | 9bae55d1 | Panagiotis Kanavos | |
62 | 9bae55d1 | Panagiotis Kanavos | |
63 | 9bae55d1 | Panagiotis Kanavos | /// <summary> |
64 | 9bae55d1 | Panagiotis Kanavos | /// State of the icon. Remember to also set the <see cref="StateMask"/>. |
65 | 9bae55d1 | Panagiotis Kanavos | /// </summary> |
66 | 9bae55d1 | Panagiotis Kanavos | public IconState IconState; |
67 | 9bae55d1 | Panagiotis Kanavos | |
68 | 9bae55d1 | Panagiotis Kanavos | /// <summary> |
69 | 9bae55d1 | Panagiotis Kanavos | /// A value that specifies which bits of the state member are retrieved or modified. |
70 | 9bae55d1 | Panagiotis Kanavos | /// For example, setting this member to <see cref="Interop.IconState.Hidden"/> |
71 | 9bae55d1 | Panagiotis Kanavos | /// causes only the item's hidden |
72 | 9bae55d1 | Panagiotis Kanavos | /// state to be retrieved. |
73 | 9bae55d1 | Panagiotis Kanavos | /// </summary> |
74 | 9bae55d1 | Panagiotis Kanavos | public IconState StateMask; |
75 | 9bae55d1 | Panagiotis Kanavos | |
76 | 9bae55d1 | Panagiotis Kanavos | /// <summary> |
77 | 9bae55d1 | Panagiotis Kanavos | /// String with the text for a balloon ToolTip. It can have a maximum of 255 characters. |
78 | 9bae55d1 | Panagiotis Kanavos | /// To remove the ToolTip, set the NIF_INFO flag in uFlags and set szInfo to an empty string. |
79 | 9bae55d1 | Panagiotis Kanavos | /// </summary> |
80 | 9bae55d1 | Panagiotis Kanavos | [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 256)] public string BalloonText; |
81 | 9bae55d1 | Panagiotis Kanavos | |
82 | 9bae55d1 | Panagiotis Kanavos | /// <summary> |
83 | 9bae55d1 | Panagiotis Kanavos | /// Mainly used to set the version when <see cref="WinApi.Shell_NotifyIcon"/> is invoked |
84 | 9bae55d1 | Panagiotis Kanavos | /// with <see cref="NotifyCommand.SetVersion"/>. However, for legacy operations, |
85 | 9bae55d1 | Panagiotis Kanavos | /// the same member is also used to set timouts for balloon ToolTips. |
86 | 9bae55d1 | Panagiotis Kanavos | /// </summary> |
87 | 9bae55d1 | Panagiotis Kanavos | public uint VersionOrTimeout; |
88 | 9bae55d1 | Panagiotis Kanavos | |
89 | 9bae55d1 | Panagiotis Kanavos | /// <summary> |
90 | 9bae55d1 | Panagiotis Kanavos | /// String containing a title for a balloon ToolTip. This title appears in boldface |
91 | 9bae55d1 | Panagiotis Kanavos | /// above the text. It can have a maximum of 63 characters. |
92 | 9bae55d1 | Panagiotis Kanavos | /// </summary> |
93 | 9bae55d1 | Panagiotis Kanavos | [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 64)] public string BalloonTitle; |
94 | 9bae55d1 | Panagiotis Kanavos | |
95 | 9bae55d1 | Panagiotis Kanavos | /// <summary> |
96 | 9bae55d1 | Panagiotis Kanavos | /// Adds an icon to a balloon ToolTip, which is placed to the left of the title. If the |
97 | 9bae55d1 | Panagiotis Kanavos | /// <see cref="BalloonTitle"/> member is zero-length, the icon is not shown. |
98 | 9bae55d1 | Panagiotis Kanavos | /// </summary> |
99 | 9bae55d1 | Panagiotis Kanavos | public BalloonFlags BalloonFlags; |
100 | 9bae55d1 | Panagiotis Kanavos | |
101 | 9bae55d1 | Panagiotis Kanavos | /// <summary> |
102 | 9bae55d1 | Panagiotis Kanavos | /// Windows XP (Shell32.dll version 6.0) and later.<br/> |
103 | 9bae55d1 | Panagiotis Kanavos | /// - Windows 7 and later: A registered GUID that identifies the icon. |
104 | 9bae55d1 | Panagiotis Kanavos | /// This value overrides uID and is the recommended method of identifying the icon.<br/> |
105 | 9bae55d1 | Panagiotis Kanavos | /// - Windows XP through Windows Vista: Reserved. |
106 | 9bae55d1 | Panagiotis Kanavos | /// </summary> |
107 | 9bae55d1 | Panagiotis Kanavos | public Guid TaskbarIconGuid; |
108 | 9bae55d1 | Panagiotis Kanavos | |
109 | 9bae55d1 | Panagiotis Kanavos | /// <summary> |
110 | 9bae55d1 | Panagiotis Kanavos | /// Windows Vista (Shell32.dll version 6.0.6) and later. The handle of a customized |
111 | 9bae55d1 | Panagiotis Kanavos | /// balloon icon provided by the application that should be used independently |
112 | 9bae55d1 | Panagiotis Kanavos | /// of the tray icon. If this member is non-NULL and the <see cref="Interop.BalloonFlags.User"/> |
113 | 9bae55d1 | Panagiotis Kanavos | /// flag is set, this icon is used as the balloon icon.<br/> |
114 | 9bae55d1 | Panagiotis Kanavos | /// If this member is NULL, the legacy behavior is carried out. |
115 | 9bae55d1 | Panagiotis Kanavos | /// </summary> |
116 | 9bae55d1 | Panagiotis Kanavos | public IntPtr CustomBalloonIconHandle; |
117 | 9bae55d1 | Panagiotis Kanavos | |
118 | 9bae55d1 | Panagiotis Kanavos | |
119 | 9bae55d1 | Panagiotis Kanavos | /// <summary> |
120 | 9bae55d1 | Panagiotis Kanavos | /// Creates a default data structure that provides |
121 | 9bae55d1 | Panagiotis Kanavos | /// a hidden taskbar icon without the icon being set. |
122 | 9bae55d1 | Panagiotis Kanavos | /// </summary> |
123 | 9bae55d1 | Panagiotis Kanavos | /// <param name="handle"></param> |
124 | 9bae55d1 | Panagiotis Kanavos | /// <returns></returns> |
125 | 9bae55d1 | Panagiotis Kanavos | public static NotifyIconData CreateDefault(IntPtr handle) |
126 | 9bae55d1 | Panagiotis Kanavos | { |
127 | 9bae55d1 | Panagiotis Kanavos | var data = new NotifyIconData(); |
128 | 9bae55d1 | Panagiotis Kanavos | |
129 | 9bae55d1 | Panagiotis Kanavos | if (Environment.OSVersion.Version.Major >= 6) |
130 | 9bae55d1 | Panagiotis Kanavos | { |
131 | 9bae55d1 | Panagiotis Kanavos | //use the current size |
132 | 9bae55d1 | Panagiotis Kanavos | data.cbSize = (uint)Marshal.SizeOf(data); |
133 | 9bae55d1 | Panagiotis Kanavos | } |
134 | 9bae55d1 | Panagiotis Kanavos | else |
135 | 9bae55d1 | Panagiotis Kanavos | { |
136 | 9bae55d1 | Panagiotis Kanavos | //we need to set another size on xp/2003- otherwise certain |
137 | 9bae55d1 | Panagiotis Kanavos | //features (e.g. balloon tooltips) don't work. |
138 | 9bae55d1 | Panagiotis Kanavos | data.cbSize = 504; |
139 | 9bae55d1 | Panagiotis Kanavos | |
140 | 9bae55d1 | Panagiotis Kanavos | //set to fixed timeout |
141 | 9bae55d1 | Panagiotis Kanavos | data.VersionOrTimeout = 10; |
142 | 9bae55d1 | Panagiotis Kanavos | } |
143 | 9bae55d1 | Panagiotis Kanavos | |
144 | 9bae55d1 | Panagiotis Kanavos | data.WindowHandle = handle; |
145 | 9bae55d1 | Panagiotis Kanavos | data.TaskbarIconId = 0x0; |
146 | 9bae55d1 | Panagiotis Kanavos | data.CallbackMessageId = WindowMessageSink.CallbackMessageId; |
147 | 9bae55d1 | Panagiotis Kanavos | data.VersionOrTimeout = (uint) NotifyIconVersion.Win95; |
148 | 9bae55d1 | Panagiotis Kanavos | |
149 | 9bae55d1 | Panagiotis Kanavos | data.IconHandle = IntPtr.Zero; |
150 | 9bae55d1 | Panagiotis Kanavos | |
151 | 9bae55d1 | Panagiotis Kanavos | //hide initially |
152 | 9bae55d1 | Panagiotis Kanavos | data.IconState = IconState.Hidden; |
153 | 9bae55d1 | Panagiotis Kanavos | data.StateMask = IconState.Hidden; |
154 | 9bae55d1 | Panagiotis Kanavos | |
155 | 9bae55d1 | Panagiotis Kanavos | //set flags |
156 | 9bae55d1 | Panagiotis Kanavos | data.ValidMembers = IconDataMembers.Message |
157 | 9bae55d1 | Panagiotis Kanavos | | IconDataMembers.Icon |
158 | 9bae55d1 | Panagiotis Kanavos | | IconDataMembers.Tip; |
159 | 9bae55d1 | Panagiotis Kanavos | |
160 | 9bae55d1 | Panagiotis Kanavos | //reset strings |
161 | 9bae55d1 | Panagiotis Kanavos | data.ToolTipText = data.BalloonText = data.BalloonTitle = String.Empty; |
162 | 9bae55d1 | Panagiotis Kanavos | |
163 | 9bae55d1 | Panagiotis Kanavos | return data; |
164 | 9bae55d1 | Panagiotis Kanavos | } |
165 | 9bae55d1 | Panagiotis Kanavos | } |
166 | 9bae55d1 | Panagiotis Kanavos | } |