Click here to Skip to main content
11,927,422 members (47,614 online)
Click here to Skip to main content
Add your own
alternative version


37 bookmarked

Vista Task Dialog and Emulating It Redux

, 5 Oct 2008 BSD
Rate this:
Please Sign up or sign in to vote.
Revisiting Vista Task Dialog and emulating it.


This article intends to try and emulate the Task Dialog in the older Windows platform and not lose a lot of functionality of the Task Dialog. We will be using the excellent managed code of TaskDialog for WinForms by KevinGre. His article will be a required reading as this is not a wrapper of his code. Instead we will use his code then detect if Task Dialog is available. If it is not available, we will try to create our own Task Dialog.

This article also uses a class “CommandButton.cs” from Vista TaskDialog Wrapper and Emulator by Hedly Muscroft.

Since there is a Task Dialog emulator made by Hedly Muscroft, why make another? Don’t get me wrong, Hedly Muscroft’s emulator is very good. In fact I took some of his ideas to make this emulator.

But his emulator doesn’t provide a lot of functionality that the original Task Dialog has (unless I'm mistaken, my apologies), for example notifications (callback) and messages (actions), which gives feedback on links that was clicked or setting the progress bar value. I intend to try to solve it.

Emulating the Task Dialog

As you know Task Dialog supports notifications. This allows Task Dialog to inform the caller on the state of the Task Dialog, like how much time has passed since the Task Dialog is shown, or whether a user clicked a link. Note that I did not implement all the notifications. The basic ones implemented are link clicked and the timer.

The following code snippet will show you how notifications are used to send information back. 

private void timer_Tick ( object sender, EventArgs e )
    this.timerTickCount += (uint)this.timer.Interval;

    TaskDialogNotificationArgs notificationArgs = new TaskDialogNotificationArgs ( );
    notificationArgs.Notification = TaskDialogNotification.Timer;
    notificationArgs.TimerTickCount = this.timerTickCount;

    if ( this.taskDialog.Callback ( new ActiveTaskDialog ( this.Handle ),
         notificationArgs, null ) )
        // Reset timer.
        this.timerTickCount = 0;

Task Dialog also allows you to change the progress bar value, or change whether a button on the Task Dialog is enable or disable and so on. KevinGre’s code (“ActiveTaskDialog.cs”), or the MSDN documentation as referenced below, describes all the possible messages that the Task Dialog can receive.

Note that I have not implemented all the messages the emulated Task Dialog can receive. Only setting the progress bar value message is implemented.

If you need to recieve more messages, the following code snippet describes how to do so.

protected override void WndProc ( ref Message m )
    switch ( m.Msg )
        case (int)UnsafeNativeMethods.TASKDIALOG_MESSAGES.TDM_SET_PROGRESS_BAR_POS:
            if ( this.progressBar != null )
                if ( m.WParam.ToInt32 ( ) <= this.progressBar.Maximum )
                    this.progressBar.Value = m.WParam.ToInt32 ( );
            base.WndProc ( ref m );

Using the code

To call the Task dialog is EXACTLY the same as KevinGre’s article. In fact, the demo uses the exact same code as KevinGre’s. The difference is that I moved the check of whether the Vista Task Dialog is available to TaskDialog.Show () itself. If Vista Task Dialog is not supported, the emulated Task Dialog will be called instead.

What I will show is the emulated Task dialog on Windows XP, note that all screenshots in this article are taken in Windows XP. The simplest usage for the code:

TaskDialog taskDialog = new TaskDialog ( );
taskDialog.WindowTitle = "My Application";
taskDialog.MainInstruction = "Do you want to do this?";
taskDialog.CommonButtons = TaskDialogCommonButtons.Yes | TaskDialogCommonButtons.No;
int result = taskDialog.Show ( );
if ( result == (int)DialogResult.Yes )
   // Do it.


Complex usage:

TaskDialog taskDialog = new TaskDialog ( );
taskDialog.WindowTitle = "My Application";
taskDialog.MainInstruction = "Do you want to do this?";

taskDialog.EnableHyperlinks = true;
taskDialog.Content =
      "If you do this there could be all sorts of consequnces. "
      "If you don't there will be other consequences. "
      "You can <a href=''>"
      "learn more about those consequences</a> or more "
      "about <a href=''>"
      "blah blah blah</a>.";
taskDialog.Callback = new TaskDialogCallback ( this.MyTaskDialogCallback );

taskDialog.VerificationText = "Don't ask me this ever again.";
taskDialog.VerificationFlagChecked = false;
taskDialog.UseCommandLinks = true;

TaskDialogButton doItButton = new TaskDialogButton ( );
doItButton.ButtonId = 101;
doItButton.ButtonText = "Do It.\nThis is an extra line?";

TaskDialogButton dontDoItButton = new TaskDialogButton ( );
dontDoItButton.ButtonId = 102;
dontDoItButton.ButtonText = "Don't Do It";

taskDialog.Buttons = new TaskDialogButton[] { doItButton, dontDoItButton };

bool dontShowAgain;
int result = taskDialog.Show ( null, out dontShowAgain );
if ( dontShowAgain )
                // Suppress future asks.
if ( result == doItButton.ButtonId )
                // Do it.

More Screenshots





I hope this article will help someone who is looking in implementing a fully functional emulated Task Dialog.



2008 October 5

  • First published.

2008 October 7

  • Added VS2005 source files.
  • Added a new screenshot.

2008 October 9

  • Fixed a couple of bugs where a grey bar will be shown when not showing the sub controls area (custom/common buttons, verification checkbox, expanded info button) and/or footer area. (With thanks to Loic Berthollet)


This article, along with any associated source code and files, is licensed under The BSD License


About the Author

United States United States
No Biography provided

You may also be interested in...

Comments and Discussions

QuestionUndocumented Icon Styles Pin
Member 40572739-May-09 14:36
memberMember 40572739-May-09 14:36 
Awesome work! This is the code that is needed for .net apps to use the TaskDialog. Now I don't have to worry about XP/2K3/Mono. One question though, There are some undocumented Icons that add alot of additional style to the task dialog. Any possibility of supporting them?

Here are the relevant resource identifiers for the undocumented styles:

ShieldGradient = 0xFFFB,
WarningGradient = 0xFFFA,
ErrorGradient = 0xFFF9,
OkGradient = 0xFFF8,
GrayGradient = 0xFFF7,

This would be filed as a nice to have, but not necessary, as I can cause the undocumented styles to redirect to supported equivalents.

QuestionCustom Icon and image Pin
Holpit5-Apr-09 23:49
memberHolpit5-Apr-09 23:49 
GeneralSystem.EntryPointNotFoundException, "wrong" ComCtl32 loaded until a Form is up and running... Pin
Chris Richner18-Jan-09 21:07
memberChris Richner18-Jan-09 21:07 
GeneralRe: System.EntryPointNotFoundException, "wrong" ComCtl32 loaded until a Form is up and running... Pin
MarcDrexler7-Jun-09 6:37
memberMarcDrexler7-Jun-09 6:37 
GeneralRe: System.EntryPointNotFoundException, "wrong" ComCtl32 loaded until a Form is up and running... Pin
Member 393600516-Oct-09 5:15
memberMember 393600516-Oct-09 5:15 
QuestionCallback function Pin
melnac9-Jan-09 22:55
membermelnac9-Jan-09 22:55 
GeneralCongratulations & Remark Pin
Loic Berthollet9-Oct-08 2:51
memberLoic Berthollet9-Oct-08 2:51 
GeneralRe: Congratulations & Remark Pin
blindwaves9-Oct-08 4:44
memberblindwaves9-Oct-08 4:44 
GeneralUnable to open the solution in VS2005 Pin
ken.rountree6-Oct-08 15:20
memberken.rountree6-Oct-08 15:20 
GeneralRe: Unable to open the solution in VS2005 Pin
blindwaves7-Oct-08 6:15
memberblindwaves7-Oct-08 6:15 
QuestionDark colors? Pin
sk8er_boy2875-Oct-08 23:46
membersk8er_boy2875-Oct-08 23:46 
AnswerRe: Dark colors? Pin
blindwaves7-Oct-08 6:14
memberblindwaves7-Oct-08 6:14 
GeneralRe: Dark colors? Pin
sk8er_boy2877-Oct-08 21:20
membersk8er_boy2877-Oct-08 21:20 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.151126.1 | Last Updated 5 Oct 2008
Article Copyright 2008 by blindwaves
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid