Click here to Skip to main content
Click here to Skip to main content

Vista Task Dialog and Emulating It Redux

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

Introduction

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 ( );
                }
            }
            break;
        default:
            base.WndProc ( ref m );
            break;
    }
}

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.
}

TaskDialogRedux03.png

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='http://www.codeproject.com/Learn/'>"
      +
      "learn more about those consequences</a> or more "
      +
      "about <a href='http://www.codeproject.com/blah/'>"
      +
      "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.
}
TaskDialogRedux04.png

More Screenshots

TaskDialogRedux01.png

TaskDialogRedux05.png

TaskDialogRedux02.png

Conclusion

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

References

History

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)

License

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

About the Author

blindwaves

United States United States
No Biography provided

Comments and Discussions

 
QuestionUndocumented Icon Styles PinmemberMember 40572739-May-09 13:36 
QuestionCustom Icon and image PinmemberHolpit5-Apr-09 22:49 
GeneralSystem.EntryPointNotFoundException, "wrong" ComCtl32 loaded until a Form is up and running... PinmemberChris Richner18-Jan-09 20:07 
GeneralRe: System.EntryPointNotFoundException, "wrong" ComCtl32 loaded until a Form is up and running... PinmemberMarcDrexler7-Jun-09 5:37 
GeneralRe: System.EntryPointNotFoundException, "wrong" ComCtl32 loaded until a Form is up and running... PinmemberMember 393600516-Oct-09 4:15 
QuestionCallback function Pinmembermelnac9-Jan-09 21:55 
GeneralCongratulations & Remark PinmemberLoic Berthollet9-Oct-08 1:51 
GeneralRe: Congratulations & Remark Pinmemberblindwaves9-Oct-08 3:44 
GeneralUnable to open the solution in VS2005 Pinmemberken.rountree6-Oct-08 14:20 
GeneralRe: Unable to open the solution in VS2005 Pinmemberblindwaves7-Oct-08 5:15 
QuestionDark colors? Pinmembersk8er_boy2875-Oct-08 22:46 
AnswerRe: Dark colors? Pinmemberblindwaves7-Oct-08 5:14 
GeneralRe: Dark colors? Pinmembersk8er_boy2877-Oct-08 20:20 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    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 | Mobile
Web04 | 2.8.140721.1 | Last Updated 5 Oct 2008
Article Copyright 2008 by blindwaves
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid