Search
Module:
Directory

   Desktop Functions:

   Smart Device Functions:


Show Recent Changes
Subscribe (RSS)
Misc. Pages
Comments
FAQ
Helpful Tools
Playground
Suggested Reading
Website TODO List
Download Visual Studio Add-In

TaskDialog (comctl32)
 
.
Summary
TaskDialogIndirect - Show a Vista TaskDialog with custom button names and many other features.
Summary
TaskDialog - Show a Windows Vista Task Dialog - like messagebox but much much better.

C# Signature:

[DllImport("comctl32.dll", SetLastError=true)]
static extern HRESULT TaskDialogIndirect
(
     in TASKDIALOGCONFIG pTaskConfig,
     out int pnButton,
     out int pnRadioButton,
     [MarshalAs( UnmanagedType.Bool ), Out] out bool pfverificationFlagChecked
);
[DllImport("comctl32.dll", CharSet = CharSet.Unicode,  EntryPoint="TaskDialog")]
static extern int TaskDialog(IntPtr hWndParent, IntPtr hInstance, String pszWindowTitle, String pszMainInstruction, String pszContent, int dwCommonButtons, IntPtr pszIcon, out int pnButton);

VB Signature:

Public Declare Auto Function TaskDialog Lib "comctl32.dll" (ByVal hWnd As IntPtr, ByVal hInstance As IntPtr, ByVal WindowTitle As String, ByVal MainInstruction As String, ByVal Content As String, ByVal CommonButton As Integer, ByVal DialogIcon As Integer, ByRef PushedButton As Integer) As Integer

User-Defined Types:

None.

//"Alternative (Error safe, legacy C# version)"

Notes:

None.

Tips & Tricks:

It only works with forms applications, wpf applications give a entry point not found exception.

To make it work with wpf applications you need to add the following to your app.manifest under asmv1:assembly

[DllImport("comctl32.dll", CharSet = CharSet.Unicode, PreserveSig = true)]
    public static extern IntPtr TaskDialogIndirect
       [In] ref TASKDIALOGCONFIG pTaskConfig,
       out int pnButton,
       out int pnRadioButton,
       [MarshalAs(UnmanagedType.Bool)] out bool pfVerificationFlagChecked
        );
  <dependency>
    <dependentAssembly>
      <assemblyIdentity type="win32" name="Microsoft.Windows.Common-Controls" version="6.0.0.0"
            processorArchitecture="X86" publicKeyToken="6595b64144ccf1df" language="*" />
    </dependentAssembly>
  </dependency>

For WPF:

This only appears to be an issue with VS2008, and it may have been fixed by the time you are reading this, so try to run the project first, and if you click on one of the 'TaskDialog' buttons and see it popup (ie you dont see an exception) then you do not need to take these steps, if you do get an exception, follow the steps below:

Task Dialog config structure c#

/// <summary>The Task Dialog config structure.</summary>
    [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode, Pack = 1)]
    public struct TaskDialogConfig
    {
        public uint cbSize;
        public IntPtr hwndParent;
        public IntPtr hInstance;
        public TaskDialogFlags dwFlags;
        public TaskDialogButton dwCommonButtons;
        [MarshalAs(UnmanagedType.LPWStr)]
        public string pszWindowTitle;
        public IntPtr hMainIcon;
        [MarshalAs(UnmanagedType.LPWStr)]
        public string pszMainInstruction;
        [MarshalAs(UnmanagedType.LPWStr)]
        public string pszContent;
        public uint cButtons;
        public IntPtr pButtons;
        public int nDefaultButton;
        public uint cRadioButtons;
        public IntPtr pRadioButtons;
        public int nDefaultRadioButton;
        [MarshalAs(UnmanagedType.LPWStr)]
        public string pszVerificationText;
        [MarshalAs(UnmanagedType.LPWStr)]
        public string pszExpandedInformation;
        [MarshalAs(UnmanagedType.LPWStr)]
        public string pszExpandedControlText;
        [MarshalAs(UnmanagedType.LPWStr)]
        public string pszCollapsedControlText;
        public IntPtr hFooterIcon;
        [MarshalAs(UnmanagedType.LPWStr)]
        public string pszFooter;
        public TaskDialogCallback pfCallback;
        public IntPtr lpCallbackData;
        public uint cxWidth;
    }

To Run the VistaBridge Project in Visual Studio 2008, you must re-create the Application Manifest file. To do this, open the manifest already in the project, copy all of the text from it to notepad and then delete the manifest file from the project. Next, right click on the "VistaBridgeDemoApp" project and select Add New Item. Choose an Application Manifest File and MAKE SURE you name it as follows: VistaBridgeDemoApp.exe.manifest and then press enter. Now double click on the new manifest file, select all the text and replace it with the text that was copied out of the old manifest. You can now Build the solution and the Demo App should now operate properly. If you still have problems, try closing Visual Studio and then Re-opening it.

Notes

If you get Entry not found / Sig Errors,Do following:

Sample Code:

Please add some!

1-make sure your invoke has "[PreserveSig = true]" tag

2-Add this lines to your app.manifestAccording to WindowsAPICodePack)

    <dependentAssembly>
      <assemblyIdentity
      type="win32"
      name="Microsoft.Windows.Common-Controls"
      version="6.0.0.0"
      processorArchitecture="*"
      publicKeyToken="6595b64144ccf1df"
      language="*"
    />
    </dependentAssembly>

C# Usage

TaskDialogIndirect(ref config, out ret, out selRadio, out setVerification);

VB Signature:

Declare Function TaskDialogIndirect Lib "comctl32.dll" (TODO) As TODO

<DllImport("comctl32.dll", SetLastError := True)> _
Private Shared Function TaskDialogIndirect(<[In]> pTaskConfig As TASKDIALOGCONFIG, <Out> ByRef pnButton As Integer, <Out> ByRef pnRadioButton As Integer, <MarshalAs(UnmanagedType.Bool), Out> ByRef pfverificationFlagChecked As Boolean) As HRESULT
End Function

User-Defined Types:

None.

Alternative Managed API:

A full wrapper for Vista's TaskDialog & TaskDialogIndirect can be found here:

http://code.msdn.microsoft.com/WindowsAPICodePack

For WPF use the following:

Download the 'VistaBridge Sample Library' from http://code.msdn.microsoft.com/VistaBridge once downloaded, open the project and then build it (if you want to look through all the code, examine the files in the \Library or \Interop folders). You can now take the DLL from VistaBridge\bin\debug\ and add a reference to it in your project, as well you must add a using statement for each of the different VistaBridge modules. For Example:

using Microsoft.SDK.Samples.VistaBridge.Interop or .Library or .Properties or .Services - Depending on your needs.

The VistaBridge project includes API's for many other Vista Features (such as the TaskDialog, Vista OpenFile and SaveFile Dialogs, and of course the Aero Glass Effects) to try these out, run the VistaBridge Project.

Notes:

This only appears to be an issue with VS2008, and it may have been fixed by the time you are reading this, so try to run the project first, and if you click on one of the 'TaskDialog' buttons and see it popup (ie you dont see an exception) then you do not need to take these steps, if you do get an exception, follow the steps below:

To Run the VistaBridge Project in Visual Studio 2008, you must re-create the Application Manifest file. To do this, open the manifest already in the project, copy all of the text from it to notepad and then delete the manifest file from the project. Next, right click on the "VistaBridgeDemoApp" project and select Add New Item. Choose an Application Manifest File and MAKE SURE you name it as follows: VistaBridgeDemoApp.exe.manifest and then press enter. Now double click on the new manifest file, select all the text and replace it with the text that was copied out of the old manifest. You can now Build the solution and the Demo App should now operate properly. If you still have problems, try closing Visual Studio and then Re-opening it.

Tips & Tricks:

Please add some!

Sample Code:

    /// <summary>The TaskDialogIndirect function creates, displays, and operates a task dialog. The task dialog contains application-defined icons, messages, title, verification check box, command links, push buttons, and radio buttons. This function can register a callback function to receive notification messages.</summary>
    /// <param name="taskConfig">A pointer to a <see cref="TaskDialogConfig"/> structure that contains information used to display the task dialog.</param>
    /// <param name="button">Address of a variable that receives one of the button IDs specified in the <paramref name="button"/> member of the <paramref name="taskConfig"/> parameter. If this parameter is <see langword="null"/>, no value is returned.</param>
    /// <param name="radioButton">Address of a variable that receives one of the button IDs specified in the <paramref name="radioButton"/> member of the <paramref name="taskConfig"/> parameter. If this parameter is <see langword="null"/>, no value is returned.</param>
    /// <param name="verificationFlagChecked"><see langword="true"/> if the verification <see cref="CheckBox"/> was checked when the dialog was dismissed; otherwise, false</param>
    /// <returns>The result</returns>
    [DllImport(@"comctl32.dll", CharSet = CharSet.Unicode, PreserveSig = false)]
    internal static extern Result TaskDialogIndirect([In] TaskDialogConfig taskConfig, [Out] out int button, [Out] out int radioButton, [MarshalAs(UnmanagedType.Bool), Out] out bool verificationFlagChecked);

Documentation
Documentation
TaskDialog on MSDN Kundan

Please edit this page!

Do you have...

  • helpful tips or sample code to share for using this API in managed code?
  • corrections to the existing content?
  • variations of the signature you want to share?
  • additional languages you want to include?

Select "Edit This Page" on the right hand toolbar and edit it! Or add new pages containing supporting types needed for this API (structures, delegates, and more).

 
Access PInvoke.net directly from VS:
Terms of Use
Edit This Page
Find References
Show Printable Version
Revisions