-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathVistaUnsafeNativeMethods.cs
447 lines (379 loc) · 17.4 KB
/
VistaUnsafeNativeMethods.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
//------------------------------------------------------------------
// <summary>
// A P/Invoke wrapper for TaskDialog. Usability was given preference to perf and size.
// </summary>
//
// <remarks/>
//------------------------------------------------------------------
namespace PSTaskDialog
{
using System;
using System.Drawing;
using System.Windows.Forms;
using System.Runtime.InteropServices;
using System.Diagnostics.CodeAnalysis;
/// <summary>
/// Class to hold native code interop declarations.
/// </summary>
internal static partial class VistaUnsafeNativeMethods
{
/// <summary>
/// WM_USER taken from WinUser.h
/// </summary>
internal const uint WM_USER = 0x0400;
/// <summary>
/// The signature of the callback that receives messages from the Task Dialog when various events occur.
/// </summary>
/// <param name="hwnd">The window handle of the </param>
/// <param name="msg">The message being passed.</param>
/// <param name="wParam">wParam which is interpreted differently depending on the message.</param>
/// <param name="lParam">wParam which is interpreted differently depending on the message.</param>
/// <param name="refData">The refrence data that was set to TaskDialog.CallbackData.</param>
/// <returns>A HRESULT value. The return value is specific to the message being processed. </returns>
internal delegate int VistaTaskDialogCallback([In] IntPtr hwnd, [In] uint msg, [In] UIntPtr wParam, [In] IntPtr lParam, [In] IntPtr refData);
/// <summary>
/// TASKDIALOG_FLAGS taken from CommCtrl.h.
/// </summary>
[Flags]
internal enum TASKDIALOG_FLAGS
{
/// <summary>
/// Enable hyperlinks.
/// </summary>
TDF_ENABLE_HYPERLINKS = 0x0001,
/// <summary>
/// Use icon handle for main icon.
/// </summary>
TDF_USE_HICON_MAIN = 0x0002,
/// <summary>
/// Use icon handle for footer icon.
/// </summary>
TDF_USE_HICON_FOOTER = 0x0004,
/// <summary>
/// Allow dialog to be cancelled, even if there is no cancel button.
/// </summary>
TDF_ALLOW_DIALOG_CANCELLATION = 0x0008,
/// <summary>
/// Use command links rather than buttons.
/// </summary>
TDF_USE_COMMAND_LINKS = 0x0010,
/// <summary>
/// Use command links with no icons rather than buttons.
/// </summary>
TDF_USE_COMMAND_LINKS_NO_ICON = 0x0020,
/// <summary>
/// Show expanded info in the footer area.
/// </summary>
TDF_EXPAND_FOOTER_AREA = 0x0040,
/// <summary>
/// Expand by default.
/// </summary>
TDF_EXPANDED_BY_DEFAULT = 0x0080,
/// <summary>
/// Start with verification flag already checked.
/// </summary>
TDF_VERIFICATION_FLAG_CHECKED = 0x0100,
/// <summary>
/// Show a progress bar.
/// </summary>
TDF_SHOW_PROGRESS_BAR = 0x0200,
/// <summary>
/// Show a marquee progress bar.
/// </summary>
TDF_SHOW_MARQUEE_PROGRESS_BAR = 0x0400,
/// <summary>
/// Callback every 200 milliseconds.
/// </summary>
TDF_CALLBACK_TIMER = 0x0800,
/// <summary>
/// Center the dialog on the owner window rather than the monitor.
/// </summary>
TDF_POSITION_RELATIVE_TO_WINDOW = 0x1000,
/// <summary>
/// Right to Left Layout.
/// </summary>
TDF_RTL_LAYOUT = 0x2000,
/// <summary>
/// No default radio button.
/// </summary>
TDF_NO_DEFAULT_RADIO_BUTTON = 0x4000,
/// <summary>
/// Task Dialog can be minimized.
/// </summary>
TDF_CAN_BE_MINIMIZED = 0x8000
}
/// <summary>
/// TASKDIALOG_ELEMENTS taken from CommCtrl.h
/// </summary>
internal enum TASKDIALOG_ELEMENTS
{
/// <summary>
/// The content element.
/// </summary>
TDE_CONTENT,
/// <summary>
/// Expanded Information.
/// </summary>
TDE_EXPANDED_INFORMATION,
/// <summary>
/// Footer.
/// </summary>
TDE_FOOTER,
/// <summary>
/// Main Instructions
/// </summary>
TDE_MAIN_INSTRUCTION
}
/// <summary>
/// TASKDIALOG_ICON_ELEMENTS taken from CommCtrl.h
/// </summary>
internal enum TASKDIALOG_ICON_ELEMENTS
{
/// <summary>
/// Main instruction icon.
/// </summary>
TDIE_ICON_MAIN,
/// <summary>
/// Footer icon.
/// </summary>
TDIE_ICON_FOOTER
}
/// <summary>
/// TASKDIALOG_MESSAGES taken from CommCtrl.h.
/// </summary>
internal enum TASKDIALOG_MESSAGES : uint
{
// Spec is not clear on what this is for.
///// <summary>
///// Navigate page.
///// </summary>
////TDM_NAVIGATE_PAGE = WM_USER + 101,
/// <summary>
/// Click button.
/// </summary>
TDM_CLICK_BUTTON = WM_USER + 102, // wParam = Button ID
/// <summary>
/// Set Progress bar to be marquee mode.
/// </summary>
TDM_SET_MARQUEE_PROGRESS_BAR = WM_USER + 103, // wParam = 0 (nonMarque) wParam != 0 (Marquee)
/// <summary>
/// Set Progress bar state.
/// </summary>
TDM_SET_PROGRESS_BAR_STATE = WM_USER + 104, // wParam = new progress state
/// <summary>
/// Set progress bar range.
/// </summary>
TDM_SET_PROGRESS_BAR_RANGE = WM_USER + 105, // lParam = MAKELPARAM(nMinRange, nMaxRange)
/// <summary>
/// Set progress bar position.
/// </summary>
TDM_SET_PROGRESS_BAR_POS = WM_USER + 106, // wParam = new position
/// <summary>
/// Set progress bar marquee (animation).
/// </summary>
TDM_SET_PROGRESS_BAR_MARQUEE = WM_USER + 107, // wParam = 0 (stop marquee), wParam != 0 (start marquee), lparam = speed (milliseconds between repaints)
/// <summary>
/// Set a text element of the Task Dialog.
/// </summary>
TDM_SET_ELEMENT_TEXT = WM_USER + 108, // wParam = element (TASKDIALOG_ELEMENTS), lParam = new element text (LPCWSTR)
/// <summary>
/// Click a radio button.
/// </summary>
TDM_CLICK_RADIO_BUTTON = WM_USER + 110, // wParam = Radio Button ID
/// <summary>
/// Enable or disable a button.
/// </summary>
TDM_ENABLE_BUTTON = WM_USER + 111, // lParam = 0 (disable), lParam != 0 (enable), wParam = Button ID
/// <summary>
/// Enable or disable a radio button.
/// </summary>
TDM_ENABLE_RADIO_BUTTON = WM_USER + 112, // lParam = 0 (disable), lParam != 0 (enable), wParam = Radio Button ID
/// <summary>
/// Check or uncheck the verfication checkbox.
/// </summary>
TDM_CLICK_VERIFICATION = WM_USER + 113, // wParam = 0 (unchecked), 1 (checked), lParam = 1 (set key focus)
/// <summary>
/// Update the text of an element (no effect if origially set as null).
/// </summary>
TDM_UPDATE_ELEMENT_TEXT = WM_USER + 114, // wParam = element (TASKDIALOG_ELEMENTS), lParam = new element text (LPCWSTR)
/// <summary>
/// Designate whether a given Task Dialog button or command link should have a User Account Control (UAC) shield icon.
/// </summary>
TDM_SET_BUTTON_ELEVATION_REQUIRED_STATE = WM_USER + 115, // wParam = Button ID, lParam = 0 (elevation not required), lParam != 0 (elevation required)
/// <summary>
/// Refreshes the icon of the task dialog.
/// </summary>
TDM_UPDATE_ICON = WM_USER + 116 // wParam = icon element (TASKDIALOG_ICON_ELEMENTS), lParam = new icon (hIcon if TDF_USE_HICON_* was set, PCWSTR otherwise)
}
///// <summary>
///// TaskDialog taken from commctrl.h.
///// </summary>
///// <param name="hwndParent">Parent window.</param>
///// <param name="hInstance">Module instance to get resources from.</param>
///// <param name="pszWindowTitle">Title of the Task Dialog window.</param>
///// <param name="pszMainInstruction">The main instructions.</param>
///// <param name="dwCommonButtons">Common push buttons to show.</param>
///// <param name="pszIcon">The main icon.</param>
///// <param name="pnButton">The push button pressed.</param>
////[DllImport("ComCtl32", CharSet = CharSet.Unicode, PreserveSig = false)]
////public static extern void TaskDialog(
//// [In] IntPtr hwndParent,
//// [In] IntPtr hInstance,
//// [In] String pszWindowTitle,
//// [In] String pszMainInstruction,
//// [In] TaskDialogCommonButtons dwCommonButtons,
//// [In] IntPtr pszIcon,
//// [Out] out int pnButton);
/// <summary>
/// TaskDialogIndirect taken from commctl.h
/// </summary>
/// <param name="pTaskConfig">All the parameters about the Task Dialog to Show.</param>
/// <param name="pnButton">The push button pressed.</param>
/// <param name="pnRadioButton">The radio button that was selected.</param>
/// <param name="pfVerificationFlagChecked">The state of the verification checkbox on dismiss of the Task Dialog.</param>
[DllImport("ComCtl32", CharSet = CharSet.Unicode, PreserveSig = false)]
internal static extern void TaskDialogIndirect(
[In] ref TASKDIALOGCONFIG pTaskConfig,
[Out] out int pnButton,
[Out] out int pnRadioButton,
[Out] out bool pfVerificationFlagChecked);
/// <summary>
/// Win32 SendMessage.
/// </summary>
/// <param name="hWnd">Window handle to send to.</param>
/// <param name="Msg">The windows message to send.</param>
/// <param name="wParam">Specifies additional message-specific information.</param>
/// <param name="lParam">Specifies additional message-specific information.</param>
/// <returns>The return value specifies the result of the message processing; it depends on the message sent.</returns>
[DllImport("user32.dll")]
internal static extern IntPtr SendMessage(IntPtr hWnd, uint Msg, IntPtr wParam, IntPtr lParam);
/// <summary>
/// Win32 SendMessage.
/// </summary>
/// <param name="hWnd">Window handle to send to.</param>
/// <param name="Msg">The windows message to send.</param>
/// <param name="wParam">Specifies additional message-specific information.</param>
/// <param name="lParam">Specifies additional message-specific information as a string.</param>
/// <returns>The return value specifies the result of the message processing; it depends on the message sent.</returns>
[DllImport("user32.dll", EntryPoint="SendMessage")]
internal static extern IntPtr SendMessageWithString(IntPtr hWnd, uint Msg, IntPtr wParam, [MarshalAs(UnmanagedType.LPWStr)] string lParam);
/// <summary>
/// TASKDIALOGCONFIG taken from commctl.h.
/// </summary>
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode, Pack = 1)]
internal struct TASKDIALOGCONFIG
{
/// <summary>
/// Size of the structure in bytes.
/// </summary>
public uint cbSize;
/// <summary>
/// Parent window handle.
/// </summary>
[SuppressMessage("Microsoft.Reliability", "CA2006:UseSafeHandleToEncapsulateNativeResources")] // Managed code owns actual resource. Passed to native in syncronous call. No lifetime issues.
public IntPtr hwndParent;
/// <summary>
/// Module instance handle for resources.
/// </summary>
[SuppressMessage("Microsoft.Reliability", "CA2006:UseSafeHandleToEncapsulateNativeResources")] // Managed code owns actual resource. Passed to native in syncronous call. No lifetime issues.
public IntPtr hInstance;
/// <summary>
/// Flags.
/// </summary>
public TASKDIALOG_FLAGS dwFlags; // TASKDIALOG_FLAGS (TDF_XXX) flags
/// <summary>
/// Bit flags for commonly used buttons.
/// </summary>
public VistaTaskDialogCommonButtons dwCommonButtons; // TASKDIALOG_COMMON_BUTTON (TDCBF_XXX) flags
/// <summary>
/// Window title.
/// </summary>
[MarshalAs(UnmanagedType.LPWStr)]
public string pszWindowTitle; // string or MAKEINTRESOURCE()
/// <summary>
/// The Main icon. Overloaded member. Can be string, a handle, a special value or a resource ID.
/// </summary>
[SuppressMessage("Microsoft.Reliability", "CA2006:UseSafeHandleToEncapsulateNativeResources")] // Managed code owns actual resource. Passed to native in syncronous call. No lifetime issues.
public IntPtr MainIcon;
/// <summary>
/// Main Instruction.
/// </summary>
[MarshalAs(UnmanagedType.LPWStr)]
public string pszMainInstruction;
/// <summary>
/// Content.
/// </summary>
[MarshalAs(UnmanagedType.LPWStr)]
public string pszContent;
/// <summary>
/// Count of custom Buttons.
/// </summary>
public uint cButtons;
/// <summary>
/// Array of custom buttons.
/// </summary>
[SuppressMessage("Microsoft.Reliability", "CA2006:UseSafeHandleToEncapsulateNativeResources")] // Managed code owns actual resource. Passed to native in syncronous call. No lifetime issues.
public IntPtr pButtons;
/// <summary>
/// ID of default button.
/// </summary>
public int nDefaultButton;
/// <summary>
/// Count of radio Buttons.
/// </summary>
public uint cRadioButtons;
/// <summary>
/// Array of radio buttons.
/// </summary>
[SuppressMessage("Microsoft.Reliability", "CA2006:UseSafeHandleToEncapsulateNativeResources")] // Managed code owns actual resource. Passed to native in syncronous call. No lifetime issues.
public IntPtr pRadioButtons;
/// <summary>
/// ID of default radio button.
/// </summary>
public int nDefaultRadioButton;
/// <summary>
/// Text for verification check box. often "Don't ask be again".
/// </summary>
[MarshalAs(UnmanagedType.LPWStr)]
public string pszVerificationText;
/// <summary>
/// Expanded Information.
/// </summary>
[MarshalAs(UnmanagedType.LPWStr)]
public string pszExpandedInformation;
/// <summary>
/// Text for expanded control.
/// </summary>
[MarshalAs(UnmanagedType.LPWStr)]
public string pszExpandedControlText;
/// <summary>
/// Text for expanded control.
/// </summary>
[MarshalAs(UnmanagedType.LPWStr)]
public string pszCollapsedControlText;
/// <summary>
/// Icon for the footer. An overloaded member link MainIcon.
/// </summary>
[SuppressMessage("Microsoft.Reliability", "CA2006:UseSafeHandleToEncapsulateNativeResources")] // Managed code owns actual resource. Passed to native in syncronous call. No lifetime issues.
public IntPtr FooterIcon;
/// <summary>
/// Footer Text.
/// </summary>
[MarshalAs(UnmanagedType.LPWStr)]
public string pszFooter;
/// <summary>
/// Function pointer for callback.
/// </summary>
public VistaTaskDialogCallback pfCallback;
/// <summary>
/// Data that will be passed to the call back.
/// </summary>
[SuppressMessage("Microsoft.Reliability", "CA2006:UseSafeHandleToEncapsulateNativeResources")] // Managed code owns actual resource. Passed to native in syncronous call. No lifetime issues.
public IntPtr lpCallbackData;
/// <summary>
/// Width of the Task Dialog's area in DLU's.
/// </summary>
public uint cxWidth; // width of the Task Dialog's client area in DLU's. If 0, Task Dialog will calculate the ideal width.
}
}
}