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

TaskDialogIndirect (comctl32)
 
.
Summary
TaskDialogIndirect - Show a Vista TaskDialog with custom button names and many other features.

C# Signature:

[DllImport("comctl32.dll", ExactSpelling=true, CharSet = CharSet.Unicode)]
static extern uint TaskDialogIndirect
(
   [In] ref TASKDIALOGCONFIG pTaskConfig,
   out int pnButton,
   out int pnRadioButton,
   [MarshalAs(UnmanagedType.Bool)] out bool pfverificationFlagChecked
);

Task Dialog config structure c#

[Flags]
public enum TASKDIALOG_COMMON_BUTTON_FLAGS
{
   /// <summary>The task dialog contains the push button: OK.</summary>
   TDCBF_OK_BUTTON = 0x0001,

   /// <summary>The task dialog contains the push button: Yes.</summary>
   TDCBF_YES_BUTTON = 0x0002,

   /// <summary>The task dialog contains the push button: No.</summary>
   TDCBF_NO_BUTTON = 0x0004,

   /// <summary>
   /// The task dialog contains the push button: Cancel. If this button is specified, the task dialog will respond to typical cancel actions (Alt-F4 and Escape).
   /// </summary>
   TDCBF_CANCEL_BUTTON = 0x0008,

   /// <summary>The task dialog contains the push button: Retry.</summary>
   TDCBF_RETRY_BUTTON = 0x0010,

   /// <summary>The task dialog contains the push button: Close.</summary>
   TDCBF_CLOSE_BUTTON = 0x0020,
}

[Flags]
public enum TASKDIALOG_FLAGS
{
   /// <summary>Enables hyperlink processing for the strings specified in the pszContent, pszExpandedInformation and pszFooter members. When enabled, these members may point to strings that contain hyperlinks in the following form:
   /// <code><![CDATA[<A HREF = "executablestring" > Hyperlink Text</A>]]></code>
   /// <note type="warning">Enabling hyperlinks when using content from an unsafe source may cause security vulnerabilities.</note>
   /// <note>Task Dialogs will not actually execute any hyperlinks.Hyperlink execution must be handled in the callback function specified by pfCallback.For more details, see TaskDialogCallbackProc.</note></summary>
   TDF_ENABLE_HYPERLINKS = 0x0001,

   /// <summary>Indicates that the dialog should use the icon referenced by the handle in the hMainIcon member as the primary icon in the task dialog. If this flag is specified, the pszMainIcon member is ignored.</summary>
   TDF_USE_HICON_MAIN = 0x0002,

   /// <summary>Indicates that the dialog should use the icon referenced by the handle in the hFooterIcon member as the footer icon in the task dialog. If this flag is specified, the pszFooterIcon member is ignored.</summary>
   TDF_USE_HICON_FOOTER = 0x0004,

   /// <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 dwCommonButtons or pButtons members.</summary>
   TDF_ALLOW_DIALOG_CANCELLATION = 0x0008,

   /// <summary>Indicates that the buttons specified in the pButtons member are to 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 pszButtonText member 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 cButtons member is zero.</summary>
   TDF_USE_COMMAND_LINKS = 0x0010,

   /// <summary>Indicates that the buttons specified in the pButtons member are to 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 pszButtonText member 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 cButtons member is zero.</summary>
   TDF_USE_COMMAND_LINKS_NO_ICON = 0x0020,

   /// <summary>Indicates that the string specified by the pszExpandedInformation member is displayed at the bottom of the dialog's footer area instead of immediately after the dialog's content. This flag is ignored if the pszExpandedInformation member is NULL.</summary>
   TDF_EXPAND_FOOTER_AREA = 0x0040,

   /// <summary>Indicates that the string specified by the pszExpandedInformation member is displayed when the dialog is initially displayed. This flag is ignored if the pszExpandedInformation member is NULL.</summary>
   TDF_EXPANDED_BY_DEFAULT = 0x0080,

   /// <summary>Indicates that the verification checkbox in the dialog is checked when the dialog is initially displayed. This flag is ignored if the pszVerificationText parameter is NULL.</summary>
   TDF_VERIFICATION_FLAG_CHECKED = 0x0100,

   /// <summary>Indicates that a Progress Bar is to be displayed.</summary>
   TDF_SHOW_PROGRESS_BAR = 0x0200,

   /// <summary>Indicates that an Marquee Progress Bar is to be displayed.</summary>
   TDF_SHOW_MARQUEE_PROGRESS_BAR = 0x0400,

   /// <summary>Indicates that the task dialog's callback is to be called approximately every 200 milliseconds.</summary>
   TDF_CALLBACK_TIMER = 0x0800,

   /// <summary>Indicates that the task dialog is positioned (centered) relative to the window specified by hwndParent. If the flag is not supplied (or no hwndParent member is specified), the task dialog is positioned (centered) relative to the monitor.</summary>
   TDF_POSITION_RELATIVE_TO_WINDOW = 0x1000,

   /// <summary>Indicates that text is displayed reading right to left.</summary>
   TDF_RTL_LAYOUT = 0x2000,

   /// <summary>Indicates that no default item will be selected.</summary>
   TDF_NO_DEFAULT_RADIO_BUTTON = 0x4000,

   /// <summary>Indicates that the task dialog can be minimized.</summary>
   TDF_CAN_BE_MINIMIZED = 0x8000,

   /// <summary>Don't call SetForegroundWindow() when activating the dialog.</summary>
   TDF_NO_SET_FOREGROUND = 0x00010000,

   /// <summary>
   /// Indicates that the width of the task dialog is determined by the width of its content area. This flag is ignored if cxWidth is not set to 0.
   /// </summary>
   TDF_SIZE_TO_CONTENT = 0x01000000
}

[UnmanagedFunctionPointer(CallingConvention.Winapi)]
public delegate HRESULT TaskDialogCallbackProc([In] IntPtr hwnd, [In] TaskDialogNotification msg, [In] IntPtr wParam, [In] IntPtr lParam, [In] IntPtr refData);

[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
public struct TASKDIALOGCONFIG
{
   public uint cbSize;
   public IntPtr hwndParent;
   public IntPtr hInstance;
   public TASKDIALOG_FLAGS dwFlags;
   public TASKDIALOG_COMMON_BUTTON_FLAGS dwCommonButtons;
   public string pszWindowTitle;      // This can also be IntPtr if you need to pass in a Resource ID
   public IntPtr hMainIcon;
   public string pszMainInstruction;      // This can also be IntPtr if you need to pass in a Resource ID
   public string pszContent;          // This can also be IntPtr if you need to pass in a Resource ID
   public uint cButtons;
   public IntPtr pButtons;
   public int nDefaultButton;
   public uint cRadioButtons;
   public IntPtr pRadioButtons;
   public int nDefaultRadioButton;
   public string pszVerificationText;     // This can also be IntPtr if you need to pass in a Resource ID
   public string pszExpandedInformation;  // This can also be IntPtr if you need to pass in a Resource ID
   public string pszExpandedControlText;  // This can also be IntPtr if you need to pass in a Resource ID
   public string pszCollapsedControlText; // This can also be IntPtr if you need to pass in a Resource ID
   public IntPtr hFooterIcon;
   public string pszFooter;           // This can also be IntPtr if you need to pass in a Resource ID
   public TaskDialogCallbackProc pfCallback;
   public IntPtr lpCallbackData;
   public uint cxWidth;
}

This code all pulled from https://github.com/dahall/Vanara/blob/master/PInvoke/ComCtl32/CommCtrl.TaskDialog.cs

Notes

According to WindowsAPICodePack, if you get Entry not found / Sig Errors, add this lines to your app.manifest:

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

C# Usage

var config = new TASKDIALOGCONFIG {
   cbSize = Marshal.SizeOf(typeof(TASKDIALOGCONFIG)),
   pszWindowTitle = "Invitation",
   pszMainInstruction = "Do you want to?",
   dwCommonButtons = TASKDIALOG_COMMON_BUTTON_FLAGS.TDCBF_YES_BUTTON | TASKDIALOG_COMMON_BUTTON_FLAGS.TDCBF_NO_BUTTON
};
TaskDialogIndirect(ref config, out var ret, out var selRadio, out var setVerification);

VB Signature:

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

<DllImport("comctl32.dll", ExactSpelling := True)> _
Private Shared Function TaskDialogIndirect(<[In]> ByRef 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:

Please add some!

Documentation

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