Skip to main content
Email Password   helpLost your password?

Windows Vista COMCTL32.dll v6 TaskDialog

PSTaskDialog - Windows Forms Emulated TaskDialog (Spot the difference!)

Introduction

After wasting innumerable hours hunting around the internet like a rabid squirrel for a way of using the Vista TaskDialog on pre-Vista versions of Windows, I decided to write one myself. "Necessity is the mother of invention." As I frequent The Code Project's website whenever I need help, I figured it was about time that I gave something back to the community. Hence, this article.

Background

Basically, I wanted a class that would wrap the TaskDialog so that on a Vista machine, it would invoke the native TaskDialog in COMCTL32.dll v6 (which ships with Vista), while on pre-Vista machines, it would emulate the TaskDialog with a near identical substitute. Massive credit must go to KevinGre for his superb article "TaskDialog for WinForms," which wraps the COMCTL32 TaskDialog API. The only changes made to his code were as follows:

  1. Prefixed class/enum/struct names with "VistaXxxx" (e.g. TaskDialog -> VistaTaskDialog) for the sake of clarity
  2. Implemented the bug fix for x64 machines mentioned in the comments section at the bottom of his article

This project takes Kevin's work a step further, in that the TaskDialog is no longer restricted to Windows Vista. You can now use the same code to display a TaskDialog without worrying about the Windows version.

Using the Code

The namespace for this project is PSTaskDialog (Pioneer Software is my company) and the only class that we really need to know about is the static public class cTaskDialog (conveniently located in cTaskDialog.cs). The cTaskDialog class contains a number of static public methods to execute a TaskDialog. The principle method is ShowTaskDialogBox. I say "principle" because this is the routine that does all the work and displays either the Vista TaskDialog or the emulated version. All the other methods in cTaskDialog end up calling this method to invoke the TaskDialog.

static public DialogResult ShowTaskDialogBox(IWin32Window ParentWindow,
                                             string Title,
                                             string MainInstruction,
                                             string Content,
                                             string ExpandedInfo,
                                             string Footer,
                                             string VerificationText,
                                             string RadioButtons,
                                             string CommandButtons,
                                             eTaskDialogButtons Buttons,
                                             eSysIcons MainIcon,
                                             eSysIcons FooterIcon)

Example 1: Using the Full ShowTaskDialogBox Method

DialogResult res =
  PSTaskDialog.cTaskDialog.ShowTaskDialogBox(this,
                                             "The main instruction text for
                                             the TaskDialog goes here.",
                                            "The content text for the task
                                             dialog is shown here and the
                                             text will automatically wrap as
                                             needed.",
                                            "Any expanded content text for
                                             the task dialog is shown here
                                             and the text will automatically
                                             wrap as needed.",
                                            "Optional footer text with an
                                             icon can be included",
                                            "Don't show me this message
                                             again",
                                            "Radio Option 1|Radio Option 2|
                                             Radio Option 3",
                                            "Command Button 1
                                             |Command Button 2\nLine 2\nLine 3
                                              |Command Button 3",
                                            PSTaskDialog.eTaskDialogButtons.
                                            OKCancel,
                                            PSTaskDialog.eSysIcons.
                                            Information,
                                            PSTaskDialog.eSysIcons.Warning);

Here's a screenshot of the above (this is on Vista running in Emulation mode).

Screenshot - demo1.png

A few things to note:

  1. The string RadioButtons and string CommandButtons parameters are pipe (|) delimited strings containing each item for the radio buttons and command buttons respectively.
  2. Sending in an empty string ("") to some of the parameters will disable (i.e. hide) certain features of the TaskDialog, namely:
  3. In addition to the DialogResult return value, other information that you may need to know after executing the TaskDialog are saved to the following static public variables of cTaskDialog:

    Please note: I realize that some may feel that ref parameters are a better way of retrieving these values as opposed to public static methods of the cTaskDialog class. Please feel free to change the code to your heart's content!

  4. cTaskDialog also has a few other static public variables to consider:

Example 2: Showing a MessageBox

PSTaskDialog.cTaskDialog.MessageBox(this,
                                   "MessageBox Title",
                                   "The main instruction text for the
                                    message box is shown here.",
                                   "The content text for the message box
                                    is shown here and the text will
                                    automatically wrap as needed.",
                                   "Any expanded content text for the
                                    message box is shown here and the text
                                    will automatically wrap as needed.",
                                   "Optional footer text with an icon can be
                                    included",
                                   PSTaskDialog.eTaskDialogButtons.YesNo,
                                   PSTaskDialog.eSysIcons.Information,
                                   PSTaskDialog.eSysIcons.Error);

Shown below is a screenshot of the above on Windows XP. Please compare this image against the top two in this article. The code is exactly the same to produce any of these dialogs.

Screenshot - demo2.png

Example 3: Showing an Even More Simple MessageBox

PSTaskDialog.cTaskDialog.MessageBox(this,
                                   "MessageBox Title",
                                   "The main instruction text for the
                                    message box is shown here.",
                                   "The content text for the message box
                                    is shown here and the text will
                                    automatically wrap as needed.",
                                    PSTaskDialog.eTaskDialogButtons.OK,
                                    PSTaskDialog.eSysIcons.Warning);

if (PSTaskDialog.cTaskDialog.VerificationChecked)
{
  // persist the user's choice here

  // e.g. write a registry entry to remember not to show this next time

}

Screenshot - demo3.png

Example 4: Showing a Radio Listbox

PSTaskDialog.cTaskDialog.ShowRadioBox(this,
                                       "RadioBox Title",
                                       "The main instruction text for the
                                       radiobox is shown here.",
                                      "The content text for the radiobox is
                                       shown here and the text will
                                       automatically wrap as needed.",
                                      "Any expanded content text for the
                                       radiobox is shown here and the text
                                       will automatically wrap as needed.",
                                      "Optional footer text with an icon
                                       can be included",
                                      "Don't show this message again",
                                      "Radio Option 1|Radio Option 2|
                                       Radio Option 3|Radio Option 4|
                                       Radio Option 5",
                                      PSTaskDialog.eSysIcons.Information,
                                      PSTaskDialog.eSysIcons.Warning);

Screenshot - demo4.png

Example 5: Showing a Command Button

PSTaskDialog.cTaskDialog.ShowCommandBox(this,
                                        "CommandBox Title",
                                       "The main instruction text for the
                                        commandbox is shown here.",
                                       "The content text for the commandbox
                                        is shown here and the text will
                                        automatically wrap as needed.",
                                       "Any expanded content text for the
                                        commandbox is shown here and the text
                                        will automatically wrap as needed.",
                                       "Optional footer text with an icon
                                        can be included",
                                       "Don't show this message again",
                                       "Command Button 1|Command Button 2|
                                        Command Button 3|Command Button 4",
                                       true,
                                       PSTaskDialog.eSysIcons.Information,
                                       PSTaskDialog.eSysIcons.Warning);

Screenshot - demo5.png

Please take a look at the source code in Form1.cs in the TaskDialogTest folder to see exactly how cTaskDialog can be used in your code.

Known Limitations

History

You must Sign In to use this message board.
 
 
Per page   
 FirstPrevNext
GeneralHow to get it to work on Windows 7 64-bit? Pin
Thorsten Dittmar
11:59 2 Nov '09  
GeneralRe: How to get it to work on Windows 7 64-bit? Pin
Hedley Muscroft
0:38 3 Nov '09  
GeneralRe: How to get it to work on Windows 7 64-bit? Pin
Thorsten Dittmar
1:58 3 Nov '09  
GeneralLast line from details not showing Pin
tienus
4:06 10 Sep '09  
QuestionError Using Chr(13) on Emulation Mode Pin
rodrilobo02
6:24 5 Sep '09  
AnswerRe: Error Using Chr(13) on Emulation Mode Pin
tienus
22:50 9 Sep '09  
GeneralRe: Error Using Chr(13) on Emulation Mode Pin
rodrilobo02
5:42 12 Sep '09  
GeneralThumbnail Quality in WinForms Version Pin
TheDesertFox
9:01 12 May '09  
GeneralRe: Thumbnail Quality in WinForms Version Pin
Hedley Muscroft
23:27 5 Jul '09  
GeneralWhen VB code??? Pin
rodrilobo02
6:06 16 Apr '09  
GeneralRe: When VB code??? Pin
rodrilobo02
9:46 19 Apr '09  
GeneralRe: When VB code??? Pin
Hedley Muscroft
23:18 5 Jul '09  
GeneralGreat control + one quick question Pin
veki-peki
0:15 9 Apr '09  
GeneralRe: Great control + one quick question Pin
Hedley Muscroft
23:17 5 Jul '09  
GeneralExcellent, I made one fix to specify Owning Form Pin
grahamoneale
15:45 25 Feb '09  
GeneralRe: Excellent, I made one fix to specify Owning Form Pin
MarcDrexler
6:06 7 Jun '09  
GeneralRe: Excellent, I made one fix to specify Owning Form Pin
Hedley Muscroft
0:07 6 Jul '09  
GeneralOwner window? Pin
jsadeli
6:01 4 Dec '08  
GeneralRe: Owner window? Pin
Hedley Muscroft
22:00 18 Dec '08  
GeneralRe: Owner window? Pin
jsadeli
5:49 22 Dec '08  
GeneralBug in the CommandButton class Pin
SDragon42
8:04 23 Oct '08  
GeneralRe: Bug in the CommandButton class Pin
Hedley Muscroft
21:52 18 Dec '08  
GeneralCustom text on buttons Pin
sevenalive
19:09 29 Sep '08  
GeneralRe: Custom text on buttons Pin
Hedley Muscroft
11:17 6 Oct '08  
GeneralRe: Custom text on buttons [Solution] Pin
TheDesertFox
11:47 12 May '09  


Last Updated 7 Jul 2009 | Advertise | Privacy | Terms of Use | Copyright © CodeProject, 1999-2009