Statistics
| Branch: | Revision:

root / trunk / Pithos.Client.WPF / NativeMethods.cs @ 255f5f86

History | View | Annotate | Download (14.2 kB)

1
#region
2
/* -----------------------------------------------------------------------
3
 * <copyright file="NativeMethods.cs" company="GRNet">
4
 * 
5
 * Copyright 2011-2012 GRNET S.A. All rights reserved.
6
 *
7
 * Redistribution and use in source and binary forms, with or
8
 * without modification, are permitted provided that the following
9
 * conditions are met:
10
 *
11
 *   1. Redistributions of source code must retain the above
12
 *      copyright notice, this list of conditions and the following
13
 *      disclaimer.
14
 *
15
 *   2. Redistributions in binary form must reproduce the above
16
 *      copyright notice, this list of conditions and the following
17
 *      disclaimer in the documentation and/or other materials
18
 *      provided with the distribution.
19
 *
20
 *
21
 * THIS SOFTWARE IS PROVIDED BY GRNET S.A. ``AS IS'' AND ANY EXPRESS
22
 * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
23
 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
24
 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GRNET S.A OR
25
 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
28
 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
29
 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
31
 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32
 * POSSIBILITY OF SUCH DAMAGE.
33
 *
34
 * The views and conclusions contained in the software and
35
 * documentation are those of the authors and should not be
36
 * interpreted as representing official policies, either expressed
37
 * or implied, of GRNET S.A.
38
 * </copyright>
39
 * -----------------------------------------------------------------------
40
 */
41
#endregion
42
using System;
43
using System.Runtime.InteropServices;
44

    
45
namespace Pithos.Client.WPF
46
{
47
    #region Enums & Structs
48

    
49
    #region enum HChangeNotifyEventID
50
    /// <summary>
51
    /// Describes the event that has occurred. 
52
    /// Typically, only one event is specified at a time. 
53
    /// If more than one event is specified, the values contained 
54
    /// in the <i>dwItem1</i> and <i>dwItem2</i> 
55
    /// parameters must be the same, respectively, for all specified events. 
56
    /// This parameter can be one or more of the following values. 
57
    /// </summary>
58
    /// <remarks>
59
    /// <para><b>Windows NT/2000/XP:</b> <i>dwItem2</i> contains the index 
60
    /// in the system image list that has changed. 
61
    /// <i>dwItem1</i> is not used and should be <see langword="null"/>.</para>
62
    /// <para><b>Windows 95/98:</b> <i>dwItem1</i> contains the index 
63
    /// in the system image list that has changed. 
64
    /// <i>dwItem2</i> is not used and should be <see langword="null"/>.</para>
65
    /// </remarks>
66
    [Flags]
67
    enum HChangeNotifyEventID
68
    {
69
        /// <summary>
70
        /// All events have occurred. 
71
        /// </summary>
72
        SHCNE_ALLEVENTS = 0x7FFFFFFF,
73

    
74
        /// <summary>
75
        /// A file type association has changed. <see cref="HChangeNotifyFlags.SHCNF_IDLIST"/> 
76
        /// must be specified in the <i>uFlags</i> parameter. 
77
        /// <i>dwItem1</i> and <i>dwItem2</i> are not used and must be <see langword="null"/>. 
78
        /// </summary>
79
        SHCNE_ASSOCCHANGED = 0x08000000,
80

    
81
        /// <summary>
82
        /// The attributes of an item or folder have changed. 
83
        /// <see cref="HChangeNotifyFlags.SHCNF_IDLIST"/> or 
84
        /// <see cref="HChangeNotifyFlags.SHCNF_PATH"/> must be specified in <i>uFlags</i>. 
85
        /// <i>dwItem1</i> contains the item or folder that has changed. 
86
        /// <i>dwItem2</i> is not used and should be <see langword="null"/>.
87
        /// </summary>
88
        SHCNE_ATTRIBUTES = 0x00000800,
89

    
90
        /// <summary>
91
        /// A nonfolder item has been created. 
92
        /// <see cref="HChangeNotifyFlags.SHCNF_IDLIST"/> or 
93
        /// <see cref="HChangeNotifyFlags.SHCNF_PATH"/> must be specified in <i>uFlags</i>. 
94
        /// <i>dwItem1</i> contains the item that was created. 
95
        /// <i>dwItem2</i> is not used and should be <see langword="null"/>.
96
        /// </summary>
97
        SHCNE_CREATE = 0x00000002,
98

    
99
        /// <summary>
100
        /// A nonfolder item has been deleted. 
101
        /// <see cref="HChangeNotifyFlags.SHCNF_IDLIST"/> or 
102
        /// <see cref="HChangeNotifyFlags.SHCNF_PATH"/> must be specified in <i>uFlags</i>. 
103
        /// <i>dwItem1</i> contains the item that was deleted. 
104
        /// <i>dwItem2</i> is not used and should be <see langword="null"/>. 
105
        /// </summary>
106
        SHCNE_DELETE = 0x00000004,
107

    
108
        /// <summary>
109
        /// A drive has been added. 
110
        /// <see cref="HChangeNotifyFlags.SHCNF_IDLIST"/> or 
111
        /// <see cref="HChangeNotifyFlags.SHCNF_PATH"/> must be specified in <i>uFlags</i>. 
112
        /// <i>dwItem1</i> contains the root of the drive that was added. 
113
        /// <i>dwItem2</i> is not used and should be <see langword="null"/>. 
114
        /// </summary>
115
        SHCNE_DRIVEADD = 0x00000100,
116

    
117
        /// <summary>
118
        /// A drive has been added and the Shell should create a new window for the drive. 
119
        /// <see cref="HChangeNotifyFlags.SHCNF_IDLIST"/> or 
120
        /// <see cref="HChangeNotifyFlags.SHCNF_PATH"/> must be specified in <i>uFlags</i>. 
121
        /// <i>dwItem1</i> contains the root of the drive that was added. 
122
        /// <i>dwItem2</i> is not used and should be <see langword="null"/>. 
123
        /// </summary>
124
        SHCNE_DRIVEADDGUI = 0x00010000,
125

    
126
        /// <summary>
127
        /// A drive has been removed. <see cref="HChangeNotifyFlags.SHCNF_IDLIST"/> or 
128
        /// <see cref="HChangeNotifyFlags.SHCNF_PATH"/> must be specified in <i>uFlags</i>. 
129
        /// <i>dwItem1</i> contains the root of the drive that was removed.
130
        /// <i>dwItem2</i> is not used and should be <see langword="null"/>. 
131
        /// </summary>
132
        SHCNE_DRIVEREMOVED = 0x00000080,
133

    
134
        /// <summary>
135
        /// Not currently used. 
136
        /// </summary>
137
        SHCNE_EXTENDED_EVENT = 0x04000000,
138

    
139
        /// <summary>
140
        /// The amount of free space on a drive has changed. 
141
        /// <see cref="HChangeNotifyFlags.SHCNF_IDLIST"/> or 
142
        /// <see cref="HChangeNotifyFlags.SHCNF_PATH"/> must be specified in <i>uFlags</i>. 
143
        /// <i>dwItem1</i> contains the root of the drive on which the free space changed.
144
        /// <i>dwItem2</i> is not used and should be <see langword="null"/>. 
145
        /// </summary>
146
        SHCNE_FREESPACE = 0x00040000,
147

    
148
        /// <summary>
149
        /// Storage media has been inserted into a drive. 
150
        /// <see cref="HChangeNotifyFlags.SHCNF_IDLIST"/> or 
151
        /// <see cref="HChangeNotifyFlags.SHCNF_PATH"/> must be specified in <i>uFlags</i>. 
152
        /// <i>dwItem1</i> contains the root of the drive that contains the new media. 
153
        /// <i>dwItem2</i> is not used and should be <see langword="null"/>. 
154
        /// </summary>
155
        SHCNE_MEDIAINSERTED = 0x00000020,
156

    
157
        /// <summary>
158
        /// Storage media has been removed from a drive. 
159
        /// <see cref="HChangeNotifyFlags.SHCNF_IDLIST"/> or 
160
        /// <see cref="HChangeNotifyFlags.SHCNF_PATH"/> must be specified in <i>uFlags</i>. 
161
        /// <i>dwItem1</i> contains the root of the drive from which the media was removed. 
162
        /// <i>dwItem2</i> is not used and should be <see langword="null"/>. 
163
        /// </summary>
164
        SHCNE_MEDIAREMOVED = 0x00000040,
165

    
166
        /// <summary>
167
        /// A folder has been created. <see cref="HChangeNotifyFlags.SHCNF_IDLIST"/> 
168
        /// or <see cref="HChangeNotifyFlags.SHCNF_PATH"/> must be specified in <i>uFlags</i>. 
169
        /// <i>dwItem1</i> contains the folder that was created. 
170
        /// <i>dwItem2</i> is not used and should be <see langword="null"/>. 
171
        /// </summary>
172
        SHCNE_MKDIR = 0x00000008,
173

    
174
        /// <summary>
175
        /// A folder on the local computer is being shared via the network. 
176
        /// <see cref="HChangeNotifyFlags.SHCNF_IDLIST"/> or 
177
        /// <see cref="HChangeNotifyFlags.SHCNF_PATH"/> must be specified in <i>uFlags</i>. 
178
        /// <i>dwItem1</i> contains the folder that is being shared. 
179
        /// <i>dwItem2</i> is not used and should be <see langword="null"/>. 
180
        /// </summary>
181
        SHCNE_NETSHARE = 0x00000200,
182

    
183
        /// <summary>
184
        /// A folder on the local computer is no longer being shared via the network. 
185
        /// <see cref="HChangeNotifyFlags.SHCNF_IDLIST"/> or 
186
        /// <see cref="HChangeNotifyFlags.SHCNF_PATH"/> must be specified in <i>uFlags</i>. 
187
        /// <i>dwItem1</i> contains the folder that is no longer being shared. 
188
        /// <i>dwItem2</i> is not used and should be <see langword="null"/>. 
189
        /// </summary>
190
        SHCNE_NETUNSHARE = 0x00000400,
191

    
192
        /// <summary>
193
        /// The name of a folder has changed. 
194
        /// <see cref="HChangeNotifyFlags.SHCNF_IDLIST"/> or 
195
        /// <see cref="HChangeNotifyFlags.SHCNF_PATH"/> must be specified in <i>uFlags</i>. 
196
        /// <i>dwItem1</i> contains the previous pointer to an item identifier list (PIDL) or name of the folder. 
197
        /// <i>dwItem2</i> contains the new PIDL or name of the folder. 
198
        /// </summary>
199
        SHCNE_RENAMEFOLDER = 0x00020000,
200

    
201
        /// <summary>
202
        /// The name of a nonfolder item has changed. 
203
        /// <see cref="HChangeNotifyFlags.SHCNF_IDLIST"/> or 
204
        /// <see cref="HChangeNotifyFlags.SHCNF_PATH"/> must be specified in <i>uFlags</i>. 
205
        /// <i>dwItem1</i> contains the previous PIDL or name of the item. 
206
        /// <i>dwItem2</i> contains the new PIDL or name of the item. 
207
        /// </summary>
208
        SHCNE_RENAMEITEM = 0x00000001,
209

    
210
        /// <summary>
211
        /// A folder has been removed. 
212
        /// <see cref="HChangeNotifyFlags.SHCNF_IDLIST"/> or 
213
        /// <see cref="HChangeNotifyFlags.SHCNF_PATH"/> must be specified in <i>uFlags</i>. 
214
        /// <i>dwItem1</i> contains the folder that was removed. 
215
        /// <i>dwItem2</i> is not used and should be <see langword="null"/>. 
216
        /// </summary>
217
        SHCNE_RMDIR = 0x00000010,
218

    
219
        /// <summary>
220
        /// The computer has disconnected from a server. 
221
        /// <see cref="HChangeNotifyFlags.SHCNF_IDLIST"/> or 
222
        /// <see cref="HChangeNotifyFlags.SHCNF_PATH"/> must be specified in <i>uFlags</i>. 
223
        /// <i>dwItem1</i> contains the server from which the computer was disconnected. 
224
        /// <i>dwItem2</i> is not used and should be <see langword="null"/>. 
225
        /// </summary>
226
        SHCNE_SERVERDISCONNECT = 0x00004000,
227

    
228
        /// <summary>
229
        /// The contents of an existing folder have changed, 
230
        /// but the folder still exists and has not been renamed. 
231
        /// <see cref="HChangeNotifyFlags.SHCNF_IDLIST"/> or 
232
        /// <see cref="HChangeNotifyFlags.SHCNF_PATH"/> must be specified in <i>uFlags</i>. 
233
        /// <i>dwItem1</i> contains the folder that has changed. 
234
        /// <i>dwItem2</i> is not used and should be <see langword="null"/>. 
235
        /// If a folder has been created, deleted, or renamed, use SHCNE_MKDIR, SHCNE_RMDIR, or 
236
        /// SHCNE_RENAMEFOLDER, respectively, instead. 
237
        /// </summary>
238
        SHCNE_UPDATEDIR = 0x00001000,
239

    
240
        SHCNE_UPDATEITEM = 0x00002000,
241

    
242
        /// <summary>
243
        /// An image in the system image list has changed. 
244
        /// <see cref="HChangeNotifyFlags.SHCNF_DWORD"/> must be specified in <i>uFlags</i>. 
245
        /// </summary>
246
        SHCNE_UPDATEIMAGE = 0x00008000,
247

    
248
    }
249
    #endregion // enum HChangeNotifyEventID
250

    
251
    #region public enum HChangeNotifyFlags
252
    /// <summary>
253
    /// Flags that indicate the meaning of the <i>dwItem1</i> and <i>dwItem2</i> parameters. 
254
    /// The uFlags parameter must be one of the following values.
255
    /// </summary>
256
    [Flags]
257
    public enum HChangeNotifyFlags
258
    {
259
        /// <summary>
260
        /// The <i>dwItem1</i> and <i>dwItem2</i> parameters are DWORD values. 
261
        /// </summary>
262
        SHCNF_DWORD = 0x0003,
263
        /// <summary>
264
        /// <i>dwItem1</i> and <i>dwItem2</i> are the addresses of ITEMIDLIST structures that 
265
        /// represent the item(s) affected by the change. 
266
        /// Each ITEMIDLIST must be relative to the desktop folder. 
267
        /// </summary>
268
        SHCNF_IDLIST = 0x0000,
269
        /// <summary>
270
        /// <i>dwItem1</i> and <i>dwItem2</i> are the addresses of null-terminated strings of 
271
        /// maximum length MAX_PATH that contain the full path names 
272
        /// of the items affected by the change. 
273
        /// </summary>
274
        SHCNF_PATHA = 0x0001,
275
        /// <summary>
276
        /// <i>dwItem1</i> and <i>dwItem2</i> are the addresses of null-terminated strings of 
277
        /// maximum length MAX_PATH that contain the full path names 
278
        /// of the items affected by the change. 
279
        /// </summary>
280
        SHCNF_PATHW = 0x0005,
281
        /// <summary>
282
        /// <i>dwItem1</i> and <i>dwItem2</i> are the addresses of null-terminated strings that 
283
        /// represent the friendly names of the printer(s) affected by the change. 
284
        /// </summary>
285
        SHCNF_PRINTERA = 0x0002,
286
        /// <summary>
287
        /// <i>dwItem1</i> and <i>dwItem2</i> are the addresses of null-terminated strings that 
288
        /// represent the friendly names of the printer(s) affected by the change. 
289
        /// </summary>
290
        SHCNF_PRINTERW = 0x0006,
291
        /// <summary>
292
        /// The function should not return until the notification 
293
        /// has been delivered to all affected components. 
294
        /// As this flag modifies other data-type flags, it cannot by used by itself.
295
        /// </summary>
296
        SHCNF_FLUSH = 0x1000,
297
        /// <summary>
298
        /// The function should begin delivering notifications to all affected components 
299
        /// but should return as soon as the notification process has begun. 
300
        /// As this flag modifies other data-type flags, it cannot by used by itself.
301
        /// </summary>
302
        SHCNF_FLUSHNOWAIT = 0x2000
303
    }
304
    #endregion // enum HChangeNotifyFlags
305

    
306

    
307
    #endregion
308

    
309

    
310
    internal static class NativeMethods
311
    {
312
        [DllImport("shell32.dll")]
313
        public static extern void SHChangeNotify(HChangeNotifyEventID wEventId,
314
                                           HChangeNotifyFlags uFlags,
315
                                           IntPtr dwItem1,
316
                                           IntPtr dwItem2);
317

    
318
    }
319
}