-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathVistaTaskDialog.cs
1195 lines (1063 loc) · 48.8 KB
/
VistaTaskDialog.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
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
//------------------------------------------------------------------
// <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>
/// The signature of the callback that recieves notificaitons from the Task Dialog.
/// </summary>
/// <param name="taskDialog">The active task dialog which has methods that can be performed on an active Task Dialog.</param>
/// <param name="args">The notification arguments including the type of notification and information for the notification.</param>
/// <param name="callbackData">The value set on TaskDialog.CallbackData</param>
/// <returns>Return value meaning varies depending on the Notification member of args.</returns>
public delegate bool VistaTaskDialogCallback(VistaActiveTaskDialog taskDialog, VistaTaskDialogNotificationArgs args, object callbackData);
/// <summary>
/// The TaskDialog common button flags used to specify the builtin bottons to show in the TaskDialog.
/// </summary>
[Flags]
public enum VistaTaskDialogCommonButtons
{
/// <summary>
/// No common buttons.
/// </summary>
None = 0,
/// <summary>
/// OK common button. If selected Task Dialog will return DialogResult.OK.
/// </summary>
Ok = 0x0001,
/// <summary>
/// Yes common button. If selected Task Dialog will return DialogResult.Yes.
/// </summary>
Yes = 0x0002,
/// <summary>
/// No common button. If selected Task Dialog will return DialogResult.No.
/// </summary>
No = 0x0004,
/// <summary>
/// Cancel common button. If selected Task Dialog will return DialogResult.Cancel.
/// If this button is specified, the dialog box will respond to typical cancel actions (Alt-F4 and Escape).
/// </summary>
Cancel = 0x0008,
/// <summary>
/// Retry common button. If selected Task Dialog will return DialogResult.Retry.
/// </summary>
Retry = 0x0010,
/// <summary>
/// Close common button. If selected Task Dialog will return this value.
/// </summary>
Close = 0x0020,
}
/// <summary>
/// The System icons the TaskDialog supports.
/// </summary>
[SuppressMessage("Microsoft.Design", "CA1028:EnumStorageShouldBeInt32")] // Type comes from CommCtrl.h
public enum VistaTaskDialogIcon : uint
{
/// <summary>
/// No Icon.
/// </summary>
None = 0,
/// <summary>
/// System warning icon.
/// </summary>
Warning = 0xFFFF, // MAKEINTRESOURCEW(-1)
/// <summary>
/// System Error icon.
/// </summary>
Error = 0xFFFE, // MAKEINTRESOURCEW(-2)
/// <summary>
/// System Information icon.
/// </summary>
Information = 0xFFFD, // MAKEINTRESOURCEW(-3)
/// <summary>
/// Shield icon.
/// </summary>
Shield = 0xFFFC, // MAKEINTRESOURCEW(-4)
}
/// <summary>
/// Task Dialog callback notifications.
/// </summary>
public enum VistaTaskDialogNotification
{
/// <summary>
/// Sent by the Task Dialog once the dialog has been created and before it is displayed.
/// The value returned by the callback is ignored.
/// </summary>
Created = 0,
//// Spec is not clear what this is so not supporting it.
///// <summary>
///// Sent by the Task Dialog when a navigation has occurred.
///// The value returned by the callback is ignored.
///// </summary>
// Navigated = 1,
/// <summary>
/// Sent by the Task Dialog when the user selects a button or command link in the task dialog.
/// The button ID corresponding to the button selected will be available in the
/// TaskDialogNotificationArgs. To prevent the Task Dialog from closing, the application must
/// return true, otherwise the Task Dialog will be closed and the button ID returned to via
/// the original application call.
/// </summary>
ButtonClicked = 2, // wParam = Button ID
/// <summary>
/// Sent by the Task Dialog when the user clicks on a hyperlink in the Task Dialog’s content.
/// The string containing the HREF of the hyperlink will be available in the
/// TaskDialogNotificationArgs. To prevent the TaskDialog from shell executing the hyperlink,
/// the application must return TRUE, otherwise ShellExecute will be called.
/// </summary>
HyperlinkClicked = 3, // lParam = (LPCWSTR)pszHREF
/// <summary>
/// Sent by the Task Dialog approximately every 200 milliseconds when TaskDialog.CallbackTimer
/// has been set to true. The number of milliseconds since the dialog was created or the
/// notification returned true is available on the TaskDialogNotificationArgs. To reset
/// the tickcount, the application must return true, otherwise the tickcount will continue to
/// increment.
/// </summary>
Timer = 4, // wParam = Milliseconds since dialog created or timer reset
/// <summary>
/// Sent by the Task Dialog when it is destroyed and its window handle no longer valid.
/// The value returned by the callback is ignored.
/// </summary>
Destroyed = 5,
/// <summary>
/// Sent by the Task Dialog when the user selects a radio button in the task dialog.
/// The button ID corresponding to the button selected will be available in the
/// TaskDialogNotificationArgs.
/// The value returned by the callback is ignored.
/// </summary>
RadioButtonClicked = 6, // wParam = Radio Button ID
/// <summary>
/// Sent by the Task Dialog once the dialog has been constructed and before it is displayed.
/// The value returned by the callback is ignored.
/// </summary>
DialogConstructed = 7,
/// <summary>
/// Sent by the Task Dialog when the user checks or unchecks the verification checkbox.
/// The verificationFlagChecked value is available on the TaskDialogNotificationArgs.
/// The value returned by the callback is ignored.
/// </summary>
VerificationClicked = 8, // wParam = 1 if checkbox checked, 0 if not, lParam is unused and always 0
/// <summary>
/// Sent by the Task Dialog when the user presses F1 on the keyboard while the dialog has focus.
/// The value returned by the callback is ignored.
/// </summary>
Help = 9,
/// <summary>
/// Sent by the task dialog when the user clicks on the dialog's expando button.
/// The expanded value is available on the TaskDialogNotificationArgs.
/// The value returned by the callback is ignored.
/// </summary>
ExpandoButtonClicked = 10 // wParam = 0 (dialog is now collapsed), wParam != 0 (dialog is now expanded)
}
/// <summary>
/// Progress bar state.
/// </summary>
[SuppressMessage("Microsoft.Design", "CA1008:EnumsShouldHaveZeroValue")] // Comes from CommCtrl.h PBST_* values which don't have a zero.
public enum VistaProgressBarState
{
/// <summary>
/// Normal.
/// </summary>
Normal = 1,
/// <summary>
/// Error state.
/// </summary>
Error = 2,
/// <summary>
/// Paused state.
/// </summary>
Paused = 3
}
/// <summary>
/// A custom button for the TaskDialog.
/// </summary>
[SuppressMessage("Microsoft.Performance", "CA1815:OverrideEqualsAndOperatorEqualsOnValueTypes")] // Would be unused code as not required for usage.
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode, Pack = 1)]
public struct VistaTaskDialogButton
{
/// <summary>
/// The ID of the button. This value is returned by TaskDialog.Show when the button is clicked.
/// </summary>
private int buttonId;
/// <summary>
/// The string that appears on the button.
/// </summary>
[MarshalAs(UnmanagedType.LPWStr)]
private string buttonText;
/// <summary>
/// Initialize the custom button.
/// </summary>
/// <param name="id">The ID of the button. This value is returned by TaskDialog.Show when
/// the button is clicked. Typically this will be a value in the DialogResult enum.</param>
/// <param name="text">The string that appears on the button.</param>
public VistaTaskDialogButton(int id, string text)
{
this.buttonId = id;
this.buttonText = text;
}
/// <summary>
/// The ID of the button. This value is returned by TaskDialog.Show when the button is clicked.
/// </summary>
public int ButtonId
{
get { return this.buttonId; }
set { this.buttonId = value; }
}
/// <summary>
/// The string that appears on the button.
/// </summary>
public string ButtonText
{
get { return this.buttonText; }
set { this.buttonText = value; }
}
}
/// <summary>
/// A Task Dialog. This is like a MessageBox but with many more features. TaskDialog requires Windows Longhorn or later.
/// </summary>
public class VistaTaskDialog
{
/// <summary>
/// The string to be used for the dialog box title. If this parameter is NULL, the filename of the executable program is used.
/// </summary>
private string windowTitle;
/// <summary>
/// The string to be used for the main instruction.
/// </summary>
private string mainInstruction;
/// <summary>
/// The string to be used for the dialog’s primary content. If the EnableHyperlinks member is true,
/// then this string may contain hyperlinks in the form: <A HREF="executablestring">Hyperlink Text</A>.
/// WARNING: Enabling hyperlinks when using content from an unsafe source may cause security vulnerabilities.
/// </summary>
private string content;
/// <summary>
/// Specifies the push buttons displayed in the dialog box. This parameter may be a combination of flags.
/// If no common buttons are specified and no custom buttons are specified using the Buttons member, the
/// dialog box will contain the OK button by default.
/// </summary>
private VistaTaskDialogCommonButtons commonButtons;
/// <summary>
/// Specifies a built in icon for the main icon in the dialog. If this is set to none
/// and the CustomMainIcon is null then no main icon will be displayed.
/// </summary>
private VistaTaskDialogIcon mainIcon;
/// <summary>
/// Specifies a custom in icon for the main icon in the dialog. If this is set to none
/// and the CustomMainIcon member is null then no main icon will be displayed.
/// </summary>
private Icon customMainIcon;
/// <summary>
/// Specifies a built in icon for the icon to be displayed in the footer area of the
/// dialog box. If this is set to none and the CustomFooterIcon member is null then no
/// footer icon will be displayed.
/// </summary>
private VistaTaskDialogIcon footerIcon;
/// <summary>
/// Specifies a custom icon for the icon to be displayed in the footer area of the
/// dialog box. If this is set to none and the CustomFooterIcon member is null then no
/// footer icon will be displayed.
/// </summary>
private Icon customFooterIcon;
/// <summary>
/// Specifies the custom push buttons to display in the dialog. Use CommonButtons member for
/// common buttons; OK, Yes, No, Retry and Cancel, and Buttons when you want different text
/// on the push buttons.
/// </summary>
private VistaTaskDialogButton[] buttons;
/// <summary>
/// Specifies the radio buttons to display in the dialog.
/// </summary>
private VistaTaskDialogButton[] radioButtons;
/// <summary>
/// The flags passed to TaskDialogIndirect.
/// </summary>
private VistaUnsafeNativeMethods.TASKDIALOG_FLAGS flags;
/// <summary>
/// Indicates the default button for the dialog. This may be any of the values specified
/// in ButtonId members of one of the TaskDialogButton structures in the Buttons array,
/// or one a DialogResult value that corresponds to a buttons specified in the CommonButtons Member.
/// If this member is zero or its value does not correspond to any button ID in the dialog,
/// then the first button in the dialog will be the default.
/// </summary>
private int defaultButton;
/// <summary>
/// Indicates the default radio button for the dialog. This may be any of the values specified
/// in ButtonId members of one of the TaskDialogButton structures in the RadioButtons array.
/// If this member is zero or its value does not correspond to any radio button ID in the dialog,
/// then the first button in RadioButtons will be the default.
/// The property NoDefaultRadioButton can be set to have no default.
/// </summary>
private int defaultRadioButton;
/// <summary>
/// The string to be used to label the verification checkbox. If this member is null, the
/// verification checkbox is not displayed in the dialog box.
/// </summary>
private string verificationText;
/// <summary>
/// The string to be used for displaying additional information. The additional information is
/// displayed either immediately below the content or below the footer text depending on whether
/// the ExpandFooterArea member is true. If the EnableHyperlinks member is true, then this string
/// may contain hyperlinks in the form: <A HREF="executablestring">Hyperlink Text</A>.
/// WARNING: Enabling hyperlinks when using content from an unsafe source may cause security vulnerabilities.
/// </summary>
private string expandedInformation;
/// <summary>
/// The string to be used to label the button for collapsing the expanded information. This
/// member is ignored when the ExpandedInformation member is null. If this member is null
/// and the CollapsedControlText is specified, then the CollapsedControlText value will be
/// used for this member as well.
/// </summary>
private string expandedControlText;
/// <summary>
/// The string to be used to label the button for expanding the expanded information. This
/// member is ignored when the ExpandedInformation member is null. If this member is null
/// and the ExpandedControlText is specified, then the ExpandedControlText value will be
/// used for this member as well.
/// </summary>
private string collapsedControlText;
/// <summary>
/// The string to be used in the footer area of the dialog box. If the EnableHyperlinks member
/// is true, then this string may contain hyperlinks in the form: <A HREF="executablestring">
/// Hyperlink Text</A>.
/// WARNING: Enabling hyperlinks when using content from an unsafe source may cause security vulnerabilities.
/// </summary>
private string footer;
/// <summary>
/// The callback that receives messages from the Task Dialog when various events occur.
/// </summary>
private VistaTaskDialogCallback callback;
/// <summary>
/// Reference that is passed to the callback.
/// </summary>
private object callbackData;
/// <summary>
/// Specifies the width of the Task Dialog’s client area in DLU’s. If 0, Task Dialog will calculate the ideal width.
/// </summary>
private uint width;
/// <summary>
/// Creates a default Task Dialog.
/// </summary>
public VistaTaskDialog()
{
this.Reset();
}
/// <summary>
/// Returns true if the current operating system supports TaskDialog. If false TaskDialog.Show should not
/// be called as the results are undefined but often results in a crash.
/// </summary>
public static bool IsAvailableOnThisOS
{
get
{
OperatingSystem os = Environment.OSVersion;
if (os.Platform != PlatformID.Win32NT)
return false;
return (os.Version.CompareTo(VistaTaskDialog.RequiredOSVersion) >= 0);
}
}
/// <summary>
/// The minimum Windows version needed to support TaskDialog.
/// </summary>
public static Version RequiredOSVersion
{
get { return new Version(6, 0, 5243); }
}
/// <summary>
/// The string to be used for the dialog box title. If this parameter is NULL, the filename of the executable program is used.
/// </summary>
public string WindowTitle
{
get { return this.windowTitle; }
set { this.windowTitle = value; }
}
/// <summary>
/// The string to be used for the main instruction.
/// </summary>
public string MainInstruction
{
get { return this.mainInstruction; }
set { this.mainInstruction = value; }
}
/// <summary>
/// The string to be used for the dialog’s primary content. If the EnableHyperlinks member is true,
/// then this string may contain hyperlinks in the form: <A HREF="executablestring">Hyperlink Text</A>.
/// WARNING: Enabling hyperlinks when using content from an unsafe source may cause security vulnerabilities.
/// </summary>
public string Content
{
get { return this.content; }
set { this.content = value; }
}
/// <summary>
/// Specifies the push buttons displayed in the dialog box. This parameter may be a combination of flags.
/// If no common buttons are specified and no custom buttons are specified using the Buttons member, the
/// dialog box will contain the OK button by default.
/// </summary>
public VistaTaskDialogCommonButtons CommonButtons
{
get { return this.commonButtons; }
set { this.commonButtons = value; }
}
/// <summary>
/// Specifies a built in icon for the main icon in the dialog. If this is set to none
/// and the CustomMainIcon is null then no main icon will be displayed.
/// </summary>
public VistaTaskDialogIcon MainIcon
{
get { return this.mainIcon; }
set { this.mainIcon = value; }
}
/// <summary>
/// Specifies a custom in icon for the main icon in the dialog. If this is set to none
/// and the CustomMainIcon member is null then no main icon will be displayed.
/// </summary>
public Icon CustomMainIcon
{
get { return this.customMainIcon; }
set { this.customMainIcon = value; }
}
/// <summary>
/// Specifies a built in icon for the icon to be displayed in the footer area of the
/// dialog box. If this is set to none and the CustomFooterIcon member is null then no
/// footer icon will be displayed.
/// </summary>
public VistaTaskDialogIcon FooterIcon
{
get { return this.footerIcon; }
set { this.footerIcon = value; }
}
/// <summary>
/// Specifies a custom icon for the icon to be displayed in the footer area of the
/// dialog box. If this is set to none and the CustomFooterIcon member is null then no
/// footer icon will be displayed.
/// </summary>
public Icon CustomFooterIcon
{
get { return this.customFooterIcon; }
set { this.customFooterIcon = value; }
}
/// <summary>
/// Specifies the custom push buttons to display in the dialog. Use CommonButtons member for
/// common buttons; OK, Yes, No, Retry and Cancel, and Buttons when you want different text
/// on the push buttons.
/// </summary>
[SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly")] // Style of use is like single value. Array is of value types.
[SuppressMessage("Microsoft.Performance", "CA1819:PropertiesShouldNotReturnArrays")] // Returns a reference, not a copy.
public VistaTaskDialogButton[] Buttons
{
get
{
return this.buttons;
}
set
{
if (value == null)
{
throw new ArgumentNullException("value");
}
this.buttons = value;
}
}
/// <summary>
/// Specifies the radio buttons to display in the dialog.
/// </summary>
[SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly")] // Style of use is like single value. Array is of value types.
[SuppressMessage("Microsoft.Performance", "CA1819:PropertiesShouldNotReturnArrays")] // Returns a reference, not a copy.
public VistaTaskDialogButton[] RadioButtons
{
get
{
return this.radioButtons;
}
set
{
if (value == null)
{
throw new ArgumentNullException("value");
}
this.radioButtons = value;
}
}
/// <summary>
/// Enables hyperlink processing for the strings specified in the Content, ExpandedInformation
/// and FooterText members. When enabled, these members may be strings that contain hyperlinks
/// in the form: <A HREF="executablestring">Hyperlink Text</A>.
/// WARNING: Enabling hyperlinks when using content from an unsafe source may cause security vulnerabilities.
/// Note: Task Dialog will not actually execute any hyperlinks. Hyperlink execution must be handled
/// in the callback function specified by Callback member.
/// </summary>
public bool EnableHyperlinks
{
get { return (this.flags & VistaUnsafeNativeMethods.TASKDIALOG_FLAGS.TDF_ENABLE_HYPERLINKS) != 0; }
set { this.SetFlag(VistaUnsafeNativeMethods.TASKDIALOG_FLAGS.TDF_ENABLE_HYPERLINKS, value); }
}
/// <summary>
/// Indicates that the dialog should be able to be closed using Alt-F4, Escape and the title bar’s
/// close button even if no cancel button is specified in either the CommonButtons or Buttons members.
/// </summary>
public bool AllowDialogCancellation
{
get { return (this.flags & VistaUnsafeNativeMethods.TASKDIALOG_FLAGS.TDF_ALLOW_DIALOG_CANCELLATION) != 0; }
set { this.SetFlag(VistaUnsafeNativeMethods.TASKDIALOG_FLAGS.TDF_ALLOW_DIALOG_CANCELLATION, value); }
}
/// <summary>
/// Indicates that the buttons specified in the Buttons member should be displayed as command links
/// (using a standard task dialog glyph) instead of push buttons. When using command links, all
/// characters up to the first new line character in the ButtonText member (of the TaskDialogButton
/// structure) will be treated as the command link’s main text, and the remainder will be treated
/// as the command link’s note. This flag is ignored if the Buttons member has no entires.
/// </summary>
public bool UseCommandLinks
{
get { return (this.flags & VistaUnsafeNativeMethods.TASKDIALOG_FLAGS.TDF_USE_COMMAND_LINKS) != 0; }
set { this.SetFlag(VistaUnsafeNativeMethods.TASKDIALOG_FLAGS.TDF_USE_COMMAND_LINKS, value); }
}
/// <summary>
/// Indicates that the buttons specified in the Buttons member should be displayed as command links
/// (without a glyph) instead of push buttons. When using command links, all characters up to the
/// first new line character in the ButtonText member (of the TaskDialogButton structure) will be
/// treated as the command link’s main text, and the remainder will be treated as the command link’s
/// note. This flag is ignored if the Buttons member has no entires.
/// </summary>
public bool UseCommandLinksNoIcon
{
get { return (this.flags & VistaUnsafeNativeMethods.TASKDIALOG_FLAGS.TDF_USE_COMMAND_LINKS_NO_ICON) != 0; }
set { this.SetFlag(VistaUnsafeNativeMethods.TASKDIALOG_FLAGS.TDF_USE_COMMAND_LINKS_NO_ICON, value); }
}
/// <summary>
/// Indicates that the string specified by the ExpandedInformation member should be displayed at the
/// bottom of the dialog’s footer area instead of immediately after the dialog’s content. This flag
/// is ignored if the ExpandedInformation member is null.
/// </summary>
public bool ExpandFooterArea
{
get { return (this.flags & VistaUnsafeNativeMethods.TASKDIALOG_FLAGS.TDF_EXPAND_FOOTER_AREA) != 0; }
set { this.SetFlag(VistaUnsafeNativeMethods.TASKDIALOG_FLAGS.TDF_EXPAND_FOOTER_AREA, value); }
}
/// <summary>
/// Indicates that the string specified by the ExpandedInformation member should be displayed
/// when the dialog is initially displayed. This flag is ignored if the ExpandedInformation member
/// is null.
/// </summary>
public bool ExpandedByDefault
{
get { return (this.flags & VistaUnsafeNativeMethods.TASKDIALOG_FLAGS.TDF_EXPANDED_BY_DEFAULT) != 0; }
set { this.SetFlag(VistaUnsafeNativeMethods.TASKDIALOG_FLAGS.TDF_EXPANDED_BY_DEFAULT, value); }
}
/// <summary>
/// Indicates that the verification checkbox in the dialog should be checked when the dialog is
/// initially displayed. This flag is ignored if the VerificationText parameter is null.
/// </summary>
public bool VerificationFlagChecked
{
get { return (this.flags & VistaUnsafeNativeMethods.TASKDIALOG_FLAGS.TDF_VERIFICATION_FLAG_CHECKED) != 0; }
set { this.SetFlag(VistaUnsafeNativeMethods.TASKDIALOG_FLAGS.TDF_VERIFICATION_FLAG_CHECKED, value); }
}
/// <summary>
/// Indicates that a Progress Bar should be displayed.
/// </summary>
public bool ShowProgressBar
{
get { return (this.flags & VistaUnsafeNativeMethods.TASKDIALOG_FLAGS.TDF_SHOW_PROGRESS_BAR) != 0; }
set { this.SetFlag(VistaUnsafeNativeMethods.TASKDIALOG_FLAGS.TDF_SHOW_PROGRESS_BAR, value); }
}
/// <summary>
/// Indicates that an Marquee Progress Bar should be displayed.
/// </summary>
public bool ShowMarqueeProgressBar
{
get { return (this.flags & VistaUnsafeNativeMethods.TASKDIALOG_FLAGS.TDF_SHOW_MARQUEE_PROGRESS_BAR) != 0; }
set { this.SetFlag(VistaUnsafeNativeMethods.TASKDIALOG_FLAGS.TDF_SHOW_MARQUEE_PROGRESS_BAR, value); }
}
/// <summary>
/// Indicates that the TaskDialog’s callback should be called approximately every 200 milliseconds.
/// </summary>
public bool CallbackTimer
{
get { return (this.flags & VistaUnsafeNativeMethods.TASKDIALOG_FLAGS.TDF_CALLBACK_TIMER) != 0; }
set { this.SetFlag(VistaUnsafeNativeMethods.TASKDIALOG_FLAGS.TDF_CALLBACK_TIMER, value); }
}
/// <summary>
/// Indicates that the TaskDialog should be positioned (centered) relative to the owner window
/// passed when calling Show. If not set (or no owner window is passed), the TaskDialog is
/// positioned (centered) relative to the monitor.
/// </summary>
public bool PositionRelativeToWindow
{
get { return (this.flags & VistaUnsafeNativeMethods.TASKDIALOG_FLAGS.TDF_POSITION_RELATIVE_TO_WINDOW) != 0; }
set { this.SetFlag(VistaUnsafeNativeMethods.TASKDIALOG_FLAGS.TDF_POSITION_RELATIVE_TO_WINDOW, value); }
}
/// <summary>
/// Indicates that the TaskDialog should have right to left layout.
/// </summary>
public bool RightToLeftLayout
{
get { return (this.flags & VistaUnsafeNativeMethods.TASKDIALOG_FLAGS.TDF_RTL_LAYOUT) != 0; }
set { this.SetFlag(VistaUnsafeNativeMethods.TASKDIALOG_FLAGS.TDF_RTL_LAYOUT, value); }
}
/// <summary>
/// Indicates that the TaskDialog should have no default radio button.
/// </summary>
public bool NoDefaultRadioButton
{
get { return (this.flags & VistaUnsafeNativeMethods.TASKDIALOG_FLAGS.TDF_NO_DEFAULT_RADIO_BUTTON) != 0; }
set { this.SetFlag(VistaUnsafeNativeMethods.TASKDIALOG_FLAGS.TDF_NO_DEFAULT_RADIO_BUTTON, value); }
}
/// <summary>
/// Indicates that the TaskDialog can be minimised. Works only if there if parent window is null. Will enable cancellation also.
/// </summary>
public bool CanBeMinimized
{
get { return (this.flags & VistaUnsafeNativeMethods.TASKDIALOG_FLAGS.TDF_CAN_BE_MINIMIZED) != 0; }
set { this.SetFlag(VistaUnsafeNativeMethods.TASKDIALOG_FLAGS.TDF_CAN_BE_MINIMIZED, value); }
}
/// <summary>
/// Indicates the default button for the dialog. This may be any of the values specified
/// in ButtonId members of one of the TaskDialogButton structures in the Buttons array,
/// or one a DialogResult value that corresponds to a buttons specified in the CommonButtons Member.
/// If this member is zero or its value does not correspond to any button ID in the dialog,
/// then the first button in the dialog will be the default.
/// </summary>
public int DefaultButton
{
get { return this.defaultButton; }
set { this.defaultButton = value; }
}
/// <summary>
/// Indicates the default radio button for the dialog. This may be any of the values specified
/// in ButtonId members of one of the TaskDialogButton structures in the RadioButtons array.
/// If this member is zero or its value does not correspond to any radio button ID in the dialog,
/// then the first button in RadioButtons will be the default.
/// The property NoDefaultRadioButton can be set to have no default.
/// </summary>
public int DefaultRadioButton
{
get { return this.defaultRadioButton; }
set { this.defaultRadioButton = value; }
}
/// <summary>
/// The string to be used to label the verification checkbox. If this member is null, the
/// verification checkbox is not displayed in the dialog box.
/// </summary>
public string VerificationText
{
get { return this.verificationText; }
set { this.verificationText = value; }
}
/// <summary>
/// The string to be used for displaying additional information. The additional information is
/// displayed either immediately below the content or below the footer text depending on whether
/// the ExpandFooterArea member is true. If the EnameHyperlinks member is true, then this string
/// may contain hyperlinks in the form: <A HREF="executablestring">Hyperlink Text</A>.
/// WARNING: Enabling hyperlinks when using content from an unsafe source may cause security vulnerabilities.
/// </summary>
public string ExpandedInformation
{
get { return this.expandedInformation; }
set { this.expandedInformation = value; }
}
/// <summary>
/// The string to be used to label the button for collapsing the expanded information. This
/// member is ignored when the ExpandedInformation member is null. If this member is null
/// and the CollapsedControlText is specified, then the CollapsedControlText value will be
/// used for this member as well.
/// </summary>
public string ExpandedControlText
{
get { return this.expandedControlText; }
set { this.expandedControlText = value; }
}
/// <summary>
/// The string to be used to label the button for expanding the expanded information. This
/// member is ignored when the ExpandedInformation member is null. If this member is null
/// and the ExpandedControlText is specified, then the ExpandedControlText value will be
/// used for this member as well.
/// </summary>
public string CollapsedControlText
{
get { return this.collapsedControlText; }
set { this.collapsedControlText = value; }
}
/// <summary>
/// The string to be used in the footer area of the dialog box. If the EnableHyperlinks member
/// is true, then this string may contain hyperlinks in the form: <A HREF="executablestring">
/// Hyperlink Text</A>.
/// WARNING: Enabling hyperlinks when using content from an unsafe source may cause security vulnerabilities.
/// </summary>
public string Footer
{
get { return this.footer; }
set { this.footer = value; }
}
/// <summary>
/// width of the Task Dialog's client area in DLU's. If 0, Task Dialog will calculate the ideal width.
/// </summary>
public uint Width
{
get { return this.width; }
set { this.width = value; }
}
/// <summary>
/// The callback that receives messages from the Task Dialog when various events occur.
/// </summary>
public VistaTaskDialogCallback Callback
{
get { return this.callback; }
set { this.callback = value; }
}
/// <summary>
/// Reference that is passed to the callback.
/// </summary>
public object CallbackData
{
get { return this.callbackData; }
set { this.callbackData = value; }
}
/// <summary>
/// Resets the Task Dialog to the state when first constructed, all properties set to their default value.
/// </summary>
public void Reset()
{
this.windowTitle = null;
this.mainInstruction = null;
this.content = null;
this.commonButtons = 0;
this.mainIcon = VistaTaskDialogIcon.None;
this.customMainIcon = null;
this.footerIcon = VistaTaskDialogIcon.None;
this.customFooterIcon = null;
this.buttons = new VistaTaskDialogButton[0];
this.radioButtons = new VistaTaskDialogButton[0];
this.flags = 0;
this.defaultButton = 0;
this.defaultRadioButton = 0;
this.verificationText = null;
this.expandedInformation = null;
this.expandedControlText = null;
this.collapsedControlText = null;
this.footer = null;
this.callback = null;
this.callbackData = null;
this.width = 0;
}
/// <summary>
/// Creates, displays, and operates a task dialog. The task dialog contains application-defined messages, title,
/// verification check box, command links and push buttons, plus any combination of predefined icons and push buttons
/// as specified on the other members of the class before calling Show.
/// </summary>
/// <returns>The result of the dialog, either a DialogResult value for common push buttons set in the CommonButtons
/// member or the ButtonID from a TaskDialogButton structure set on the Buttons member.</returns>
public int Show()
{
bool verificationFlagChecked;
int radioButtonResult;
return this.Show(IntPtr.Zero, out verificationFlagChecked, out radioButtonResult);
}
/// <summary>
/// Creates, displays, and operates a task dialog. The task dialog contains application-defined messages, title,
/// verification check box, command links and push buttons, plus any combination of predefined icons and push buttons
/// as specified on the other members of the class before calling Show.
/// </summary>
/// <param name="owner">Owner window the task Dialog will modal to.</param>
/// <returns>The result of the dialog, either a DialogResult value for common push buttons set in the CommonButtons
/// member or the ButtonID from a TaskDialogButton structure set on the Buttons member.</returns>
public int Show(IWin32Window owner)
{
bool verificationFlagChecked;
int radioButtonResult;
return this.Show((owner == null ? IntPtr.Zero : owner.Handle), out verificationFlagChecked, out radioButtonResult);
}
/// <summary>
/// Creates, displays, and operates a task dialog. The task dialog contains application-defined messages, title,
/// verification check box, command links and push buttons, plus any combination of predefined icons and push buttons
/// as specified on the other members of the class before calling Show.
/// </summary>
/// <param name="hwndOwner">Owner window the task Dialog will modal to.</param>
/// <returns>The result of the dialog, either a DialogResult value for common push buttons set in the CommonButtons
/// member or the ButtonID from a TaskDialogButton structure set on the Buttons member.</returns>
public int Show(IntPtr hwndOwner)
{
bool verificationFlagChecked;
int radioButtonResult;
return this.Show(hwndOwner, out verificationFlagChecked, out radioButtonResult);
}
/// <summary>
/// Creates, displays, and operates a task dialog. The task dialog contains application-defined messages, title,
/// verification check box, command links and push buttons, plus any combination of predefined icons and push buttons
/// as specified on the other members of the class before calling Show.
/// </summary>
/// <param name="owner">Owner window the task Dialog will modal to.</param>
/// <param name="verificationFlagChecked">Returns true if the verification checkbox was checked when the dialog
/// was dismissed.</param>
/// <returns>The result of the dialog, either a DialogResult value for common push buttons set in the CommonButtons
/// member or the ButtonID from a TaskDialogButton structure set on the Buttons member.</returns>
public int Show(IWin32Window owner, out bool verificationFlagChecked)
{
int radioButtonResult;
return this.Show((owner == null ? IntPtr.Zero : owner.Handle), out verificationFlagChecked, out radioButtonResult);
}
/// <summary>
/// Creates, displays, and operates a task dialog. The task dialog contains application-defined messages, title,
/// verification check box, command links and push buttons, plus any combination of predefined icons and push buttons
/// as specified on the other members of the class before calling Show.
/// </summary>
/// <param name="hwndOwner">Owner window the task Dialog will modal to.</param>
/// <param name="verificationFlagChecked">Returns true if the verification checkbox was checked when the dialog
/// was dismissed.</param>
/// <returns>The result of the dialog, either a DialogResult value for common push buttons set in the CommonButtons
/// member or the ButtonID from a TaskDialogButton structure set on the Buttons member.</returns>
public int Show(IntPtr hwndOwner, out bool verificationFlagChecked)
{
// We have to call a private version or PreSharp gets upset about a unsafe
// block in a public method. (PreSharp error 56505)
int radioButtonResult;
return this.PrivateShow(hwndOwner, out verificationFlagChecked, out radioButtonResult);
}
/// <summary>
/// Creates, displays, and operates a task dialog. The task dialog contains application-defined messages, title,
/// verification check box, command links and push buttons, plus any combination of predefined icons and push buttons
/// as specified on the other members of the class before calling Show.
/// </summary>
/// <param name="owner">Owner window the task Dialog will modal to.</param>
/// <param name="verificationFlagChecked">Returns true if the verification checkbox was checked when the dialog
/// was dismissed.</param>
/// <param name="radioButtonResult">The radio botton selected by the user.</param>
/// <returns>The result of the dialog, either a DialogResult value for common push buttons set in the CommonButtons
/// member or the ButtonID from a TaskDialogButton structure set on the Buttons member.</returns>
public int Show(IWin32Window owner, out bool verificationFlagChecked, out int radioButtonResult)
{
return this.Show((owner == null ? IntPtr.Zero : owner.Handle), out verificationFlagChecked, out radioButtonResult);
}
/// <summary>
/// Creates, displays, and operates a task dialog. The task dialog contains application-defined messages, title,
/// verification check box, command links and push buttons, plus any combination of predefined icons and push buttons
/// as specified on the other members of the class before calling Show.
/// </summary>
/// <param name="hwndOwner">Owner window the task Dialog will modal to.</param>
/// <param name="verificationFlagChecked">Returns true if the verification checkbox was checked when the dialog
/// was dismissed.</param>
/// <param name="radioButtonResult">The radio botton selected by the user.</param>
/// <returns>The result of the dialog, either a DialogResult value for common push buttons set in the CommonButtons
/// member or the ButtonID from a TaskDialogButton structure set on the Buttons member.</returns>
public int Show(IntPtr hwndOwner, out bool verificationFlagChecked, out int radioButtonResult)
{
// We have to call a private version or PreSharp gets upset about a unsafe
// block in a public method. (PreSharp error 56505)
return this.PrivateShow(hwndOwner, out verificationFlagChecked, out radioButtonResult);
}
/// <summary>
/// Creates, displays, and operates a task dialog. The task dialog contains application-defined messages, title,
/// verification check box, command links and push buttons, plus any combination of predefined icons and push buttons
/// as specified on the other members of the class before calling Show.
/// </summary>
/// <param name="hwndOwner">Owner window the task Dialog will modal to.</param>
/// <param name="verificationFlagChecked">Returns true if the verification checkbox was checked when the dialog
/// was dismissed.</param>
/// <param name="radioButtonResult">The radio botton selected by the user.</param>
/// <returns>The result of the dialog, either a DialogResult value for common push buttons set in the CommonButtons
/// member or the ButtonID from a TaskDialogButton structure set on the Buttons member.</returns>
private int PrivateShow(IntPtr hwndOwner, out bool verificationFlagChecked, out int radioButtonResult)
{
verificationFlagChecked = false;
radioButtonResult = 0;
int result = 0;
VistaUnsafeNativeMethods.TASKDIALOGCONFIG config = new VistaUnsafeNativeMethods.TASKDIALOGCONFIG();
try
{
config.cbSize = (uint)Marshal.SizeOf(typeof(VistaUnsafeNativeMethods.TASKDIALOGCONFIG));
config.hwndParent = hwndOwner;
config.dwFlags = this.flags;
config.dwCommonButtons = this.commonButtons;
if (!string.IsNullOrEmpty(this.windowTitle))
{
config.pszWindowTitle = this.windowTitle;
}
config.MainIcon = (IntPtr)this.mainIcon;
if (this.customMainIcon != null)
{
config.dwFlags |= VistaUnsafeNativeMethods.TASKDIALOG_FLAGS.TDF_USE_HICON_MAIN;
config.MainIcon = this.customMainIcon.Handle;
}
if (!string.IsNullOrEmpty(this.mainInstruction))
{
config.pszMainInstruction = this.mainInstruction;