using System; using System.Diagnostics.CodeAnalysis; using System.Runtime.InteropServices; using Vanara.Extensions; using static Vanara.PInvoke.User32; namespace Vanara.PInvoke { public static partial class ComCtl32 { /// The signature of the callback that receives messages from the Task Dialog when various events occur. /// The window handle of the /// The message being passed. /// wParam which is interpreted differently depending on the message. /// wParam which is interpreted differently depending on the message. /// The reference data that was set to TaskDialog.CallbackData. /// A HRESULT value. The return value is specific to the message being processed. [PInvokeData("Commctrl.h", MSDNShortId = "bb760542")] [UnmanagedFunctionPointer(CallingConvention.Winapi)] public delegate HRESULT TaskDialogCallbackProc([In] HWND hwnd, [In] TaskDialogNotification msg, [In] IntPtr wParam, [In] IntPtr lParam, [In] IntPtr refData); /// /// Specifies the push buttons displayed in the task dialog. If no common buttons are specified and no custom buttons are specified /// using the cButtons and pButtons members, the task dialog will contain the OK button by default. This parameter may be a /// combination of flags /// [PInvokeData("Commctrl.h", MSDNShortId = "bb760540")] [Flags] public enum TASKDIALOG_COMMON_BUTTON_FLAGS { /// The task dialog contains the push button: OK. TDCBF_OK_BUTTON = 0x0001, /// The task dialog contains the push button: Yes. TDCBF_YES_BUTTON = 0x0002, /// The task dialog contains the push button: No. TDCBF_NO_BUTTON = 0x0004, /// /// 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). /// TDCBF_CANCEL_BUTTON = 0x0008, /// The task dialog contains the push button: Retry. TDCBF_RETRY_BUTTON = 0x0010, /// The task dialog contains the push button: Close. TDCBF_CLOSE_BUTTON = 0x0020, } /// Indicates element to update for the TDM_UPDATE_ELEMENT_TEXT message. [PInvokeData("Commctrl.h", MSDNShortId = "bb760536")] public enum TASKDIALOG_ELEMENTS { /// The content element. TDE_CONTENT, /// Expanded Information. TDE_EXPANDED_INFORMATION, /// Footer. TDE_FOOTER, /// Main Instructions TDE_MAIN_INSTRUCTION } /// Specifies the behavior of the task dialog. [PInvokeData("Commctrl.h", MSDNShortId = "bb787473")] [Flags] public enum TASKDIALOG_FLAGS { /// /// 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: /// /// Hyperlink Text]]> /// /// Enabling hyperlinks when using content from an unsafe source may cause security /// vulnerabilities.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. /// TDF_ENABLE_HYPERLINKS = 0x0001, /// /// 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. /// TDF_USE_HICON_MAIN = 0x0002, /// /// 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. /// TDF_USE_HICON_FOOTER = 0x0004, /// /// 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. /// TDF_ALLOW_DIALOG_CANCELLATION = 0x0008, /// /// 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. /// TDF_USE_COMMAND_LINKS = 0x0010, /// /// 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. /// TDF_USE_COMMAND_LINKS_NO_ICON = 0x0020, /// /// 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. /// TDF_EXPAND_FOOTER_AREA = 0x0040, /// /// 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. /// TDF_EXPANDED_BY_DEFAULT = 0x0080, /// /// 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. /// TDF_VERIFICATION_FLAG_CHECKED = 0x0100, /// Indicates that a Progress Bar is to be displayed. TDF_SHOW_PROGRESS_BAR = 0x0200, /// Indicates that an Marquee Progress Bar is to be displayed. TDF_SHOW_MARQUEE_PROGRESS_BAR = 0x0400, /// Indicates that the task dialog's callback is to be called approximately every 200 milliseconds. TDF_CALLBACK_TIMER = 0x0800, /// /// 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. /// TDF_POSITION_RELATIVE_TO_WINDOW = 0x1000, /// Indicates that text is displayed reading right to left. TDF_RTL_LAYOUT = 0x2000, /// Indicates that no default item will be selected. TDF_NO_DEFAULT_RADIO_BUTTON = 0x4000, /// Indicates that the task dialog can be minimized. TDF_CAN_BE_MINIMIZED = 0x8000, /// Don't call SetForegroundWindow() when activating the dialog. TDF_NO_SET_FOREGROUND = 0x00010000, /// /// 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. /// TDF_SIZE_TO_CONTENT = 0x01000000 } /// Indicates which icon element to update for the TDM_UPDATE_ICON message. [PInvokeData("Commctrl.h", MSDNShortId = "bb760538")] public enum TASKDIALOG_ICON_ELEMENTS { /// Main instruction icon. TDIE_ICON_MAIN, /// Footer icon. TDIE_ICON_FOOTER } /// The System icons the TaskDialog supports for and . [PInvokeData("Commctrl.h", MSDNShortId = "bb787473")] [SuppressMessage("Microsoft.Design", "CA1028:EnumStorageShouldBeInt32")] // Type comes from CommCtrl.h public enum TaskDialogIcon : uint { /// An exclamation-point icon appears in the task dialog. TD_WARNING_ICON = 0xFFFF, // MAKEINTRESOURCEW(-1) /// A stop-sign icon appears in the task dialog. TD_ERROR_ICON = 0xFFFE, // MAKEINTRESOURCEW(-2) /// An icon consisting of a lowercase letter i in a circle appears in the task dialog. TD_INFORMATION_ICON = 0xFFFD, // MAKEINTRESOURCEW(-3) /// A shield icon appears in the task dialog. TD_SHIELD_ICON = 0xFFFC, // MAKEINTRESOURCEW(-4) /// Shield icon on a blue background. Only available on Windows 8 and later. TD_SHIELDBLUE_ICON = 0xFFFB, // MAKEINTRESOURCEW(-5) /// Warning Shield icon on a yellow background. Only available on Windows 8 and later. TD_SECURITYWARNING_ICON = 0xFFFA, // MAKEINTRESOURCEW(-6) /// Error Shield icon on a red background. Only available on Windows 8 and later. TD_SECURITYERROR_ICON = 0xFFF9, // MAKEINTRESOURCEW(-7) /// Success Shield icon on a green background. Only available on Windows 8 and later. TD_SECURITYSUCCESS_ICON = 0xFFF8, // MAKEINTRESOURCEW(-8) /// Shield icon on a gray background. Only available on Windows 8 and later. TD_SHIELDGRAY_ICON = 0xFFF7, // MAKEINTRESOURCEW(-9) } /// TaskDialogMessage taken from CommCtrl.h. [PInvokeData("Commctrl.h", MSDNShortId = "bb787473")] public enum TaskDialogMessage : uint { /// Recreates a task dialog with new contents, simulating the functionality of a multi-page wizard. /// Parameters /// wParam /// Not used. Must be zero. /// lParam /// /// A pointer to a TASKDIALOGCONFIG structure that describes the task dialog to create. The calling application must /// allocate this structure and set its members. The values of the members vary depending on the kind of page the user navigates to. /// /// Returns /// The return value is ignored. /// /// /// /// To launch a wizard task dialog, use the TaskDialogIndirect function. As the user navigates using the wizard, send this /// message to the task dialog to display the next page. A new task dialog (looks like a new page) is created with the elements /// specified in the structure pointed to by lParam. At creation, the entire contents of the dialog frame are destroyed and /// reconstructed. As a result, any state information held by controls (for example, a progress bar, expando button, or /// verification checkbox) in the dialog is lost. /// /// /// The layout of the task dialog may fail and this may not be reflected in the return value. A return value of S_OK reflects /// only that the task dialog received the message and attempted to process it. If the layout of the task dialog fails (the task /// dialog cannot be displayed), the dialog will close and an HRESULT code is returned at the registered callback /// function. For more information on the callback function syntax, see TaskDialogCallbackProc. /// /// // https://docs.microsoft.com/en-us/windows/win32/controls/tdm-navigate-page TDM_NAVIGATE_PAGE = WindowMessage.WM_USER + 101, /// Simulates the action of a button click in a task dialog. /// Parameters /// wParam /// An int that specifies the ID of the button to be clicked. /// lParam /// Must be zero. /// Returns /// The return value is ignored. /// /// /// The button ID specified by wParam is sent to the TaskDialogCallbackProc callback function as part of a /// TDN_BUTTON_CLICKED notification code. After the callback function returns, the task dialog is closed if S_OK was returned /// from the callback function. If S_FALSE was returned from the callback function, the task dialog remains active. /// // https://docs.microsoft.com/en-us/windows/win32/controls/tdm-click-button TDM_CLICK_BUTTON = WindowMessage.WM_USER + 102, // wParam = Button ID /// Indicates whether the hosted progress bar of a task dialog should be displayed in marquee mode. /// Parameters /// wParam /// /// A BOOL that indicates whether the progress bar should be shown in marquee mode. A value of TRUE turns on /// marquee mode, and a value of FALSE turns off marquee mode. /// /// lParam /// Must be zero. /// Returns /// The return value is ignored. /// /// For information on marquee mode, see Progress Bar Control. // https://docs.microsoft.com/en-us/windows/win32/controls/tdm-set-marquee-progress-bar TDM_SET_MARQUEE_PROGRESS_BAR = WindowMessage.WM_USER + 103, // wParam = 0 (nonMarque) wParam != 0 (Marquee) /// Sets the state of the progress bar in a task dialog. /// Parameters /// wParam /// An int that specifies the state of the progress bar. This parameter can be one of the following values. /// /// /// Value /// Meaning /// /// /// PBST_NORMAL /// Sets the progress bar to the normal state. /// /// /// PBST_PAUSED /// Sets the progress bar to the paused state. /// /// /// PBST_ERROR /// Set the progress bar to the error state. /// /// /// lParam /// Must be zero. /// Returns /// If the function succeeds, the return value is non zero. /// If the function fails, the return value is zero. To get extended error information call GetLastError. /// // https://docs.microsoft.com/en-us/windows/win32/controls/tdm-set-progress-bar-state TDM_SET_PROGRESS_BAR_STATE = WindowMessage.WM_USER + 104, // wParam = new progress state /// Sets the minimum and maximum values for the progress bar in a task dialog. /// Parameters /// wParam /// Must be zero. /// lParam /// /// The LOWORD specifies the minimum value. By default, the minimum value is zero. The HIWORD specifies the maximum /// value. By default, the maximum value is 100. /// /// Returns /// /// Returns the previous minimum and maximum values, if successful, or zero otherwise. The LOWORD contains the minimum /// value, and the HIWORD contains the maximum value. /// /// // https://docs.microsoft.com/en-us/windows/win32/controls/tdm-set-progress-bar-range TDM_SET_PROGRESS_BAR_RANGE = WindowMessage.WM_USER + 105, // lParam = MAKELPARAM(nMinRange, nMaxRange) /// Sets the position of the progress bar in a task dialog. /// Parameters /// wParam /// An int that specifies the new position. /// lParam /// Must be zero. /// Returns /// Returns the previous position. /// // https://docs.microsoft.com/en-us/windows/win32/controls/tdm-set-progress-bar-pos TDM_SET_PROGRESS_BAR_POS = WindowMessage.WM_USER + 106, // wParam = new position /// Starts and stops the marquee display of the progress bar in a task dialog, and sets the speed of the marquee. /// Parameters /// wParam /// /// A BOOL that indicates whether to turn the marquee display on or off. Use TRUE to turn on the marquee display, /// or FALSE to turn it off. /// /// lParam /// /// A UINT that specifies the time, in milliseconds, between marquee animation updates. If this parameter is zero, the /// marquee animation is updated every 30 milliseconds. /// /// Returns /// The return value is ignored. /// /// For information on marquee mode, see Progress Bar Control. // https://docs.microsoft.com/en-us/windows/win32/controls/tdm-set-progress-bar-marquee TDM_SET_PROGRESS_BAR_MARQUEE = WindowMessage.WM_USER + 107, // wParam = 0 (stop marquee), wParam != 0 (start marquee), lparam = speed (milliseconds between repaints) /// Updates a text element in a task dialog. /// Parameters /// wParam /// /// Indicates the element to update. (For an illustration, see About Task Dialogs.) This parameter must be one of the following values. /// /// /// /// Value /// Meaning /// /// /// TDE_CONTENT /// Content. /// /// /// TDE_EXPANDED_INFORMATION /// Expanded information. /// /// /// TDE_FOOTER /// Footer text. /// /// /// TDE_MAIN_INSTRUCTION /// Main instruction. /// /// /// lParam /// The new text to use. /// Returns /// The return value is ignored. /// /// The size or layout of the task dialog may change to accommodate the new text. // https://docs.microsoft.com/en-us/windows/win32/controls/tdm-set-element-text TDM_SET_ELEMENT_TEXT = WindowMessage.WM_USER + 108, // wParam = element (TASKDIALOG_ELEMENTS), lParam = new element text (LPCWSTR) /// Simulates the action of a radio button click in a task dialog. /// Parameters /// wParam /// An int value that specifies the ID of the radio button to be clicked. /// lParam /// Must be zero. /// Returns /// The return value is ignored. /// /// /// The specified radio button ID is sent to the TaskDialogCallbackProc callback function as part of a /// TDN_RADIO_BUTTON_CLICKED notification code. After the callback function returns, the radio button will be selected. /// // https://docs.microsoft.com/en-us/windows/win32/controls/tdm-click-radio-button TDM_CLICK_RADIO_BUTTON = WindowMessage.WM_USER + 110, // wParam = Radio Button ID /// Enables or disables a push button in a task dialog. /// Parameters /// wParam /// An int value that specifies the ID of the push button to be enabled or disabled. /// lParam /// Specifies button state. Set to 0 to disable the button; set to nonzero to enable the button. /// Returns /// The return value is ignored. /// // https://docs.microsoft.com/en-us/windows/win32/controls/tdm-enable-button TDM_ENABLE_BUTTON = WindowMessage.WM_USER + 111, // lParam = 0 (disable), lParam != 0 (enable), wParam = Button ID /// Enables or disables a radio button in a task dialog. /// Parameters /// wParam /// An int value that specifies the ID of the radio button to be enabled or disabled. /// lParam /// Specifies button state. Set to 0 to disable the button; set to nonzero to enable the button. /// Returns /// The return value is ignored. /// // https://docs.microsoft.com/en-us/windows/win32/controls/tdm-enable-radio-button TDM_ENABLE_RADIO_BUTTON = WindowMessage.WM_USER + 112, // lParam = 0 (disable), lParam != 0 (enable), wParam = Radio Button ID /// Simulates a click of the verification checkbox of a task dialog, if it exists. /// Parameters /// wParam /// TRUE to set the state of the checkbox to be checked; FALSE to set it to be unchecked. /// lParam /// TRUE to set the keyboard focus to the checkbox; FALSE otherwise. /// Returns /// The return value is ignored. /// // https://docs.microsoft.com/en-us/windows/win32/controls/tdm-click-verification TDM_CLICK_VERIFICATION = WindowMessage.WM_USER + 113, // wParam = 0 (unchecked), 1 (checked), lParam = 1 (set key focus) /// Updates a text element in a task dialog. /// Parameters /// wParam /// /// Indicates the element to update. (For an illustration of the elements, see About Task Dialogs.) This parameter must be one of /// the following values: /// /// /// /// Value /// Meaning /// /// /// TDE_CONTENT /// Content. /// /// /// TDE_EXPANDED_INFORMATION /// Expanded information. /// /// /// TDE_FOOTER /// Footer text. /// /// /// TDE_MAIN_INSTRUCTION /// Main instruction. /// /// /// lParam /// Pointer to a Unicode string that contains the new text. /// Returns /// The return value is ignored. /// /// /// /// To avoid clipping, the new text must be no longer than the existing text. Setting the text to a shorter string does not cause /// the dialog box to resize. /// /// /// If the pszExpandedInformation member of the TASKDIALOGCONFIG structure used to create the task dialog was /// NULL, and you send a TDM_UPDATE_ELEMENT_TEXT message with TDE_EXPANDED_INFORMATION, nothing will happen. /// /// The above also applies to the footer and TDE_FOOTER. /// // https://docs.microsoft.com/en-us/windows/win32/controls/tdm-update-element-text TDM_UPDATE_ELEMENT_TEXT = WindowMessage.WM_USER + 114, // wParam = element (TASKDIALOG_ELEMENTS), lParam = new element text (LPCWSTR) /// /// Specifies whether a given task dialog button or command link should have a User Account Control (UAC) shield icon; that is, /// whether the action invoked by the button requires elevation. /// Parameters /// wParam /// The ID of the push button or command link to be updated. /// lParam /// /// Set to 0 to designate that the action invoked by the button does not require elevation. Set to nonzero to designate that the /// action requires elevation. /// /// Returns /// The return value is ignored. /// // https://docs.microsoft.com/en-us/windows/win32/controls/tdm-set-button-elevation-required-state TDM_SET_BUTTON_ELEVATION_REQUIRED_STATE = WindowMessage.WM_USER + 115, // wParam = Button ID, lParam = 0 (elevation not required), lParam != 0 (elevation required) /// Refreshes the icon of a task dialog. /// Parameters /// wParam /// Indicates which icon element to update. This parameter must be one of the following values: /// /// /// Value /// Meaning /// /// /// TDIE_ICON_MAIN /// Main icon. /// /// /// TDIE_ICON_FOOTER /// Footer icon. /// /// /// lParam /// /// A pointer to a string (PCWSTR) or handle to an icon (HICON) to display. If lParam is NULL, no icon is displayed, /// regardless of the value of wParam. /// /// /// If the value of wParam is TDIE_ICON_MAIN and the TDF_USE_HICON_MAIN flag is set on the dwFlags member of the /// TASKDIALOGCONFIG structure used to create the task dialog, lParam must contain a handle to an icon (HICON) to display. /// /// /// If the value of wParam is TDIE_ICON_FOOTER and the TDF_USE_HICON_FOOTER flag is set on the dwFlags member of the /// TASKDIALOGCONFIG structure used to create the task dialog, lParam must contain a handle to an icon (HICON) to display. /// /// /// If the TDF_USE_HICON_MAIN or TDF_USE_HICON_FOOTER flags are not set on the dwFlags member, lParam must point to /// a null-terminated, Unicode string (PCWSTR) that contains a valid resource identifier passed through the /// MAKEINTRESOURCE macro. The icon is displayed based on the value of wParam: if the value is TDIE_ICON_MAIN, the icon is /// displayed in the header; if the value is TDIE_ICON_FOOTER, the icon is displayed in the footer. The resource must be either /// from the application's resource module (specified in the hInstance member of the TASKDIALOGCONFIG structure), /// or if hInstance is NULL, from the system's resource module (imageres.dll). To identify a system resource, use a /// valid system identifier passed through the MAKEINTRESOURCE macro or one of the following predefined values from commctrl.h: /// /// /// /// Value /// Meaning /// /// /// TD_ERROR_ICON /// A stop sign icon. /// /// /// TD_WARNING_ICON /// An exclamation point icon. /// /// /// TD_INFORMATION_ICON /// A lowercase letter "i" in a circle icon. /// /// /// TD_SHIELD_ICON /// A security shield icon. /// /// /// Returns /// The return value is ignored. /// /// /// /// The layout of the task dialog with the icon may fail and this may not be reflected in the return value. A return value of /// S_OK reflects only that the task dialog received the message and attempted to process it. If the layout of the task dialog /// fails, the dialog will close and an HRESULT code is returned at the registered callback function. For more information /// on the callback function syntax, see TaskDialogCallbackProc. /// /// /// If the task dialog is created without a footer (that is, the appropriate footer members of the TASKDIALOGCONFIG /// structure used to create the task dialog are NULL) and this message is sent, a footer is not dynamically added to the /// task dialog. The same is true for sending this message to update a header icon when a task dialog is created without a /// header. To add a header or footer at run time, use the TDM_NAVIGATE_PAGE functionality. /// /// // https://docs.microsoft.com/en-us/windows/win32/controls/tdm-update-icon TDM_UPDATE_ICON = WindowMessage.WM_USER + 116 // wParam = icon element (TASKDIALOG_ICON_ELEMENTS), lParam = new icon (hIcon if TDF_USE_HICON_* was set, PCWSTR otherwise) } /// Task Dialog callback notifications. [PInvokeData("Commctrl.h", MSDNShortId = "bb787473")] public enum TaskDialogNotification : uint { /// /// /// Sent by the task dialog after the dialog has been created and before it is displayed. This notification code is received only /// through the task dialog callback function, which can be registered using the TaskDialogIndirect method. /// /// /// TDN_CREATED WPARAM wParam; LPARAM lParam; /// /// Parameters /// wParam /// Must be zero. /// lParam /// Must be zero. /// Returns /// The return value is ignored. /// // https://docs.microsoft.com/en-us/windows/win32/controls/tdn-created TDN_CREATED = 0, /// /// /// Sent by a task dialog when navigation has occurred. This notification code is received only through the task dialog callback /// function, which can be registered using the TaskDialogIndirect method. /// /// /// TDN_NAVIGATED WPARAM wParam; LPARAM lParam; /// /// Parameters /// wParam /// Must be zero. /// lParam /// Must be zero. /// Returns /// The return value is ignored. /// // https://docs.microsoft.com/en-us/windows/win32/controls/tdn-navigated TDN_NAVIGATED = 1, /// /// /// Sent by a task dialog when the user selects a button or command link in the task dialog. This notification code is received /// only through the task dialog callback function, which can be registered using the TaskDialogIndirect method. /// /// /// TDN_BUTTON_CLICKED WPARAM wParam; LPARAM lParam; /// /// Parameters /// wParam /// An int that specifies the ID of the button or comand link that was selected. /// lParam /// Must be zero. /// Returns /// /// To prevent the task dialog from closing, the application must return S_FALSE, otherwise the task dialog is closed and /// the button ID is returned via the original application call. /// /// // https://docs.microsoft.com/en-us/windows/win32/controls/tdn-button-clicked TDN_BUTTON_CLICKED = 2, /// /// /// Sent by a task dialog when the user clicks a hyperlink in the task dialog content. This notification code is received only /// through the task dialog callback function, which can be registered using the TaskDialogIndirect method. /// /// /// TDN_HYPERLINK_CLICKED WPARAM wParam; LPARAM lParam; /// /// Parameters /// wParam /// Must be zero. /// lParam /// Pointer to a wide-character string containing the URL of the hyperlink. /// Returns /// The return value is ignored. /// // https://docs.microsoft.com/en-us/windows/win32/controls/tdn-hyperlink-clicked TDN_HYPERLINK_CLICKED = 3, /// /// /// Sent by a task dialog approximately every 200 milliseconds. This notification code is sent when the TDF_CALLBACK_TIMER flag /// has been set in the dwFlags member of the TASKDIALOGCONFIG structure that was passed to the /// TaskDialogIndirect function. This notification code is received only through the task dialog callback function, which /// can be registered using the TaskDialogIndirect method. /// /// /// TDN_TIMER WPARAM wParam; LPARAM lParam; /// /// Parameters /// wParam /// /// A DWORD that specifies the number of milliseconds since the dialog was created or this notification code returned S_FALSE. /// /// lParam /// Must be zero. /// Returns /// To reset the tickcount, the application must return S_FALSE, otherwise the tickcount will continue to increment. /// // https://docs.microsoft.com/en-us/windows/win32/controls/tdn-timer TDN_TIMER = 4, /// /// /// Sent by a task dialog when it is destroyed and its window handle is no longer valid. This notification code is received only /// through the task dialog callback function, which can be registered using the TaskDialogIndirect method. /// /// /// TDN_DESTROYED WPARAM wParam; LPARAM lParam; /// /// Parameters /// wParam /// Must be zero. /// lParam /// Must be zero. /// Returns /// The return value is ignored. /// // https://docs.microsoft.com/en-us/windows/win32/controls/tdn-destroyed TDN_DESTROYED = 5, /// /// /// Sent by a task dialog when the user selects a radio button or command link in the task dialog. This notification code is /// received only through the task dialog callback function, which can be registered using the TaskDialogIndirect method. /// /// /// TDN_RADIO_BUTTON_CLICKED WPARAM wParam; LPARAM lParam; /// /// Parameters /// wParam /// An int that specifies the ID corresponding to the radio button that was clicked. /// lParam /// Must be zero. /// Returns /// The return value is ignored. /// // https://docs.microsoft.com/en-us/windows/win32/controls/tdn-radio-button-clicked TDN_RADIO_BUTTON_CLICKED = 6, /// /// /// Sent by a task dialog after the dialog has been created and before it is displayed. This notification code is received only /// through the task dialog callback function, which can be registered using the TaskDialogIndirect method. /// /// /// TDN_DIALOG_CONSTRUCTED WPARAM wParam; LPARAM lParam; /// /// Parameters /// wParam /// Must be zero. /// lParam /// Must be zero. /// Returns /// The return value is ignored. /// // https://docs.microsoft.com/en-us/windows/win32/controls/tdn-dialog-constructed TDN_DIALOG_CONSTRUCTED = 7, /// /// /// Sent by a task dialog when the user clicks the task dialog verification check box. This notification code is received only /// through the task dialog callback function, which can be registered using the TaskDialogIndirect method. /// /// /// TDN_VERIFICATION_CLICKED WPARAM wParam; LPARAM lParam; /// /// Parameters /// wParam /// /// A BOOL that specifies the status of the verification checkbox. It is TRUE if the verification checkbox is /// checked, or FALSE if it is unchecked. /// /// lParam /// Must be zero. /// Returns /// The return value is ignored. /// // https://docs.microsoft.com/en-us/windows/win32/controls/tdn-verification-clicked TDN_VERIFICATION_CLICKED = 8, /// /// /// Sent by a task dialog when the user presses F1 on the keyboard while the dialog has focus. This notification code is received /// only through the task dialog callback function, which can be registered using the TaskDialogIndirect method. /// /// /// TDN_HELP WPARAM wParam; LPARAM lParam; /// /// Parameters /// wParam /// Must be zero. /// lParam /// Must be zero. /// Returns /// The return value is ignored. /// // https://docs.microsoft.com/en-us/windows/win32/controls/tdn-help TDN_HELP = 9, /// /// /// Sent by the task dialog when the user clicks on the dialog's expando button. This notification is received only through the /// task dialog callback function, which can be registered using the TaskDialogIndirect method. /// /// /// TDN_EXPANDO_BUTTON_CLICKED WPARAM wParam; LPARAM lParam; /// /// Parameters /// wParam /// A BOOL that is TRUE if the dialog is expanded, or FALSE if not. /// lParam /// Must be zero. /// Returns /// The return value is ignored. /// /// /// The example in the Syntax section shows the cast to wParam before sending the notification. LPARAM is not used and /// must be zero. /// // https://docs.microsoft.com/en-us/windows/win32/controls/tdn-expando-button-clicked TDN_EXPANDO_BUTTON_CLICKED = 10 } /// /// The TaskDialog function creates, displays, and operates a task dialog. The task dialog contains application-defined message text /// and title, icons, and any combination of predefined push buttons. This function does not support the registration of a callback /// function to receive notifications. /// /// /// Handle to the owner window of the task dialog to be created. If this parameter is NULL, the task dialog has no owner window. /// /// /// Handle to the module that contains the icon resource identified by the pszIcon member, and the string resources identified by the /// pszWindowTitle and pszMainInstruction members. If this parameter is NULL, pszIcon must be NULL or a pointer to a null-terminated, /// Unicode string that contains a system resource identifier, for example, TD_ERROR_ICON. /// /// /// Pointer to the string to be used for the task dialog title. This parameter is a null-terminated, Unicode string that contains /// either text, or an integer resource identifier passed through the MAKEINTRESOURCE macro. If this parameter is NULL, the filename /// of the executable program is used. /// /// /// Pointer to the string to be used for the main instruction. This parameter is a null-terminated, Unicode string that contains /// either text, or an integer resource identifier passed through the MAKEINTRESOURCE macro. This parameter can be NULL if no main /// instruction is wanted. /// /// /// Pointer to a string used for additional text that appears below the main instruction, in a smaller font. This parameter is a /// null-terminated, Unicode string that contains either text, or an integer resource identifier passed through the MAKEINTRESOURCE /// macro. Can be NULL if no additional text is wanted. /// /// /// Specifies the push buttons displayed in the dialog box. This parameter may be a combination of flags from the following group. /// /// /// Pointer to a string that identifies the icon to display in the task dialog. This parameter must be an integer resource identifier /// passed to the MAKEINTRESOURCE macro or one of the following predefined values. If this parameter is NULL, no icon will be /// displayed. If the hInstance parameter is NULL and one of the predefined values is not used, the TaskDialog function fails. /// /// /// When this function returns, contains a pointer to an integer location that receives one of the standard button result values. /// /// /// This function can return one of these values. /// /// /// Return code /// Description /// /// /// S_OK /// The operation completed successfully. /// /// /// E_OUTOFMEMORY /// There is insufficient memory to complete the operation. /// /// /// E_INVALIDARG /// One or more arguments are not valid. /// /// /// E_FAIL /// The operation failed. /// /// /// [PInvokeData("Commctrl.h", MSDNShortId = "bb760540")] [DllImport(Lib.ComCtl32, CharSet = CharSet.Unicode, ExactSpelling = true)] public static extern HRESULT TaskDialog(HWND hwndParent, HINSTANCE hInstance, string pszWindowTitle, string pszMainInstruction, string pszContent, TASKDIALOG_COMMON_BUTTON_FLAGS dwCommonButtons, SafeResourceId pszIcon, out int pnButton); /// /// 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. /// /// Pointer to a TASKDIALOGCONFIG structure that contains information used to display the task dialog. /// /// Address of a variable that receives one of the button IDs specified in the pButtons member of the pTaskConfig parameter or a /// standard button ID value. /// /// /// Address of a variable that receives one of the button IDs specified in the pRadioButtons member of the pTaskConfig parameter. If /// this parameter is NULL, no value is returned. /// /// /// Address of a variable that receives a value indicating if the verification checkbox was checked when the dialog was dismissed. /// /// /// This function can return one of these values. /// /// /// Return code /// Description /// /// /// S_OK /// The operation completed successfully. /// /// /// E_OUTOFMEMORY /// There is insufficient memory to complete the operation. /// /// /// E_INVALIDARG /// One or more arguments are not valid. /// /// /// E_FAIL /// The operation failed. /// /// /// [PInvokeData("Commctrl.h", MSDNShortId = "bb760544")] [DllImport(Lib.ComCtl32, CharSet = CharSet.Unicode, ExactSpelling = true)] public static extern HRESULT TaskDialogIndirect([In] TASKDIALOGCONFIG pTaskConfig, out int pnButton, out int pnRadioButton, [MarshalAs(UnmanagedType.Bool)] out bool pfVerificationFlagChecked); /// /// The TASKDIALOG_BUTTON structure contains information used to display a button in a task dialog. The TASKDIALOGCONFIG structure /// uses this structure. /// [PInvokeData("Commctrl.h", MSDNShortId = "bb787475")] [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)] public struct TASKDIALOG_BUTTON { /// Indicates the value to be returned when this button is selected. public int nButtonID; /// /// Pointer that references the string to be used to label the button. This parameter can be either a null-terminated string or /// an integer resource identifier passed to the MAKEINTRESOURCE macro. When using Command Links, you delineate the command from /// the note by placing a new line character in the string. /// public IntPtr pszButtonText; } /// /// The TASKDIALOGCONFIG structure contains information used to display a task dialog. The TaskDialogIndirect function uses /// this structure. /// // https://docs.microsoft.com/en-us/windows/desktop/api/commctrl/ns-commctrl-_taskdialogconfig [PInvokeData("commctrl.h", MSDNShortId = "bb787473")] [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode, Pack = 1)] public class TASKDIALOGCONFIG : IDisposable { /// Specifies the structure size, in bytes. public uint cbSize; /// Handle to the parent window. This member can be NULL. public HWND hwndParent; /// /// Handle to the module that contains the icon resource identified by the pszMainIcon or pszFooterIcon members, and the string /// resources identified by the pszWindowTitle, pszMainInstruction, pszContent, pszVerificationText, pszExpandedInformation, /// pszExpandedControlText, pszCollapsedControlText or pszFooter members. /// public HINSTANCE hInstance; /// Specifies the behavior of the task dialog. This parameter can be a combination of flags. public TASKDIALOG_FLAGS dwFlags; /// /// Specifies the push buttons displayed in the task dialog. If no common buttons are specified and no custom buttons are /// specified using the cButtons and pButtons members, the task dialog will contain the OK button by default. This parameter may /// be a combination of flags. /// public TASKDIALOG_COMMON_BUTTON_FLAGS dwCommonButtons; /// /// Pointer that references the string to be used for the task dialog title. This parameter can be either a null-terminated /// string or an integer resource identifier passed to the MAKEINTRESOURCE macro. If this parameter is NULL, the filename of the /// executable program is used. /// public IntPtr pszWindowTitle; /// /// A handle to an Icon that is to be displayed in the task dialog. This member is ignored unless the TDF_USE_HICON_MAIN flag is /// specified. If this member is NULL and the TDF_USE_HICON_MAIN is specified, no icon will be displayed. /// OR /// /// Pointer that references the icon to be displayed in the task dialog. This parameter is ignored if the USE_HICON_MAIN flag is /// specified. Otherwise, if this parameter is NULL or the hInstance parameter is NULL, no icon will be displayed. This parameter /// must be an integer resource identifier passed to the MAKEINTRESOURCE macro. /// /// public IntPtr mainIcon; /// /// Pointer that references the string to be used for the main instruction. This parameter can be either a null-terminated string /// or an integer resource identifier passed to the MAKEINTRESOURCE macro. /// public IntPtr pszMainInstruction; /// /// Pointer that references the string to be used for the dialog's primary content. This parameter can be either a /// null-terminated string or an integer resource identifier passed to the MAKEINTRESOURCE macro. If the ENABLE_HYPERLINKS flag /// is specified for the dwFlags member, then this string may contain hyperlinks in the form: Hyperlink Text. WARNING: Enabling hyperlinks when using content from an unsafe source may cause /// security vulnerabilities. /// public IntPtr pszContent; /// /// The number of entries in the pButtons array that is used to create buttons or command links in the task dialog. If this /// member is zero and no common buttons have been specified using the dwCommonButtons member, then the task dialog will have a /// single OK button displayed. /// public uint cButtons; /// /// Pointer to an array of TASKDIALOG_BUTTON structures containing the definition of the custom buttons that are to be displayed /// in the task dialog. This array must contain at least the number of entries that are specified by the cButtons member. /// public IntPtr pButtons; /// /// The default button for the task dialog. This may be any of the values specified in nButtonID members of one of the /// TASKDIALOG_BUTTON structures in the pButtons array, or one of the IDs corresponding to the buttons specified in the /// dwCommonButtons member. If this member is zero or its value does not correspond to any button ID in the dialog, then the /// first button in the dialog will be the default. /// public int nDefaultButton; /// The number of entries in the pRadioButtons array that is used to create radio buttons in the task dialog. public uint cRadioButtons; /// /// Pointer to an array of TASKDIALOG_BUTTON structures containing the definition of the radio buttons that are to be displayed /// in the task dialog. This array must contain at least the number of entries that are specified by the cRadioButtons member. /// This parameter can be NULL. /// public IntPtr pRadioButtons; /// /// The button ID of the radio button that is selected by default. If this value does not correspond to a button ID, the first /// button in the array is selected by default. /// public int nDefaultRadioButton; /// /// Pointer that references the string to be used to label the verification checkbox. This parameter can be either a /// null-terminated string or an integer resource identifier passed to the MAKEINTRESOURCE macro. If this parameter is NULL, the /// verification checkbox is not displayed in the task dialog. If the pfVerificationFlagChecked parameter of TaskDialogIndirect /// is NULL, the checkbox is not enabled. /// public IntPtr pszVerificationText; /// /// Pointer that references the string to be used for displaying additional information. This parameter can be either a /// null-terminated string or an integer resource identifier passed to the MAKEINTRESOURCE macro. The additional information is /// displayed either immediately below the content or below the footer text depending on whether the TDF_EXPAND_FOOTER_AREA flag /// is specified. If the TDF_ENABLE_HYPERLINKS flag is specified for the dwFlags member, then this string may contain hyperlinks /// in the form: Hyperlink Text. WARNING: Enabling hyperlinks when using content from an unsafe /// source may cause security vulnerabilities. /// public IntPtr pszExpandedInformation; /// /// Pointer that references the string to be used to label the button for collapsing the expandable information. This parameter /// can be either a null-terminated string or an integer resource identifier passed to the MAKEINTRESOURCE macro. This member is /// ignored when the pszExpandedInformation member is NULL. If this member is NULL and the pszCollapsedControlText is specified, /// then the pszCollapsedControlText value will be used for this member as well. /// public IntPtr pszExpandedControlText; /// /// Pointer that references the string to be used to label the button for expanding the expandable information. This parameter /// can be either a null-terminated string or an integer resource identifier passed to the MAKEINTRESOURCE macro. This member is /// ignored when the pszExpandedInformation member is NULL. If this member is NULL and the pszCollapsedControlText is specified, /// then the pszCollapsedControlText value will be used for this member as well. /// public IntPtr pszCollapsedControlText; /// /// A handle to an Icon that is to be displayed in the footer of the task dialog. This member is ignored unless the /// TDF_USE_HICON_FOOTER flag is specified and the pszFooterIcon is not. If this member is NULL and the TDF_USE_HICON_FOOTER is /// specified, no icon is displayed. /// OR /// /// Pointer that references the icon to be displayed in the footer area of the task dialog. This parameter is ignored if the /// TDF_USE_HICON_FOOTER flag is specified, or if pszFooter is NULL. Otherwise, if this parameter is NULL or the hInstance /// parameter is NULL, no icon is displayed. This parameter must be an integer resource identifier passed to the MAKEINTRESOURCE /// macro or one of the predefined values listed for pszMainIcon. /// /// public IntPtr footerIcon; /// /// Pointer to the string to be used in the footer area of the task dialog. This parameter can be either a null-terminated string /// or an integer resource identifier passed to the MAKEINTRESOURCE macro. If the TDF_ENABLE_HYPERLINKS flag is specified for the /// dwFlags member, then this string may contain hyperlinks in this form. /// <A HREF="executablestring">Hyperlink Text</A> /// Enabling hyperlinks when using content from an unsafe source may cause security vulnerabilities. /// public IntPtr pszFooter; /// Pointer to an application-defined callback function. For more information see TaskDialogCallbackProc. [MarshalAs(UnmanagedType.FunctionPtr)] public TaskDialogCallbackProc pfCallbackProc; /// A pointer to application-defined reference data. This value is defined by the caller. public IntPtr lpCallbackData; /// /// The width of the task dialog's client area, in dialog units. If 0, the task dialog manager will calculate the ideal width. /// public uint cxWidth; /// /// Initializes a new instance of the class setting the field properly. /// public TASKDIALOGCONFIG() { cbSize = (uint)Marshal.SizeOf(typeof(TASKDIALOGCONFIG)); } /// /// The string to be used for the task dialog title. If this parameter is NULL, the filename of the executable program is used. /// public string WindowTitle { get => SafeResourceId.GetString(pszWindowTitle, CharSet.Unicode); set => StringHelper.RefreshString(ref pszWindowTitle, out var _, value, CharSet.Unicode); } /// The string to be used for the main instruction. public string MainInstruction { get => SafeResourceId.GetString(pszMainInstruction, CharSet.Unicode); set => StringHelper.RefreshString(ref pszMainInstruction, out var _, value, CharSet.Unicode); } /// /// The string to be used for the dialog's primary content. If the ENABLE_HYPERLINKS flag is specified for the dwFlags member, /// then this string may contain hyperlinks in the form: <A HREF="executablestring">Hyperlink Text</A>. WARNING: /// Enabling hyperlinks when using content from an unsafe source may cause security vulnerabilities. /// public string Content { get => SafeResourceId.GetString(pszContent, CharSet.Unicode); set => StringHelper.RefreshString(ref pszContent, out var _, value, CharSet.Unicode); } /// /// The string to be used to label the verification checkbox. If this parameter is NULL, the verification checkbox is not /// displayed in the task dialog. If the pfVerificationFlagChecked parameter of TaskDialogIndirect is NULL, the checkbox is not enabled. /// public string VerificationText { get => SafeResourceId.GetString(pszVerificationText, CharSet.Unicode); set => StringHelper.RefreshString(ref pszVerificationText, out var _, value, CharSet.Unicode); } /// /// The string to be used for displaying additional information. The additional information is displayed either immediately below /// the content or below the footer text depending on whether the TDF_EXPAND_FOOTER_AREA flag is specified. If the /// TDF_ENABLE_HYPERLINKS flag is specified for the dwFlags member, then this string may contain hyperlinks in the form: <A /// HREF="executablestring">Hyperlink Text</A>. WARNING: Enabling hyperlinks when using content from an unsafe source /// may cause security vulnerabilities. /// public string ExpandedInformation { get => SafeResourceId.GetString(pszExpandedInformation, CharSet.Unicode); set => StringHelper.RefreshString(ref pszExpandedInformation, out var _, value, CharSet.Unicode); } /// /// The string to be used to label the button for collapsing the expandable information. This member is ignored when the /// pszExpandedInformation member is NULL. If this member is NULL and the pszCollapsedControlText is specified, then the /// pszCollapsedControlText value will be used for this member as well. /// public string ExpandedControlText { get => SafeResourceId.GetString(pszExpandedControlText, CharSet.Unicode); set => StringHelper.RefreshString(ref pszExpandedControlText, out var _, value, CharSet.Unicode); } /// /// The string to be used to label the button for expanding the expandable information. This member is ignored when the /// pszExpandedInformation member is NULL. If this member is NULL and the pszCollapsedControlText is specified, then the /// pszCollapsedControlText value will be used for this member as well. /// public string CollapsedControlText { get => SafeResourceId.GetString(pszCollapsedControlText, CharSet.Unicode); set => StringHelper.RefreshString(ref pszCollapsedControlText, out var _, value, CharSet.Unicode); } /// /// The string to be used in the footer area of the task dialog. If the TDF_ENABLE_HYPERLINKS flag is specified for the dwFlags /// member, then this string may contain hyperlinks in this form. /// <A HREF="executablestring">Hyperlink Text</A> /// Enabling hyperlinks when using content from an unsafe source may cause security vulnerabilities. /// public string Footer { get => SafeResourceId.GetString(pszFooter, CharSet.Unicode); set => StringHelper.RefreshString(ref pszFooter, out var _, value, CharSet.Unicode); } /// void IDisposable.Dispose() { FreeResource(ref pszWindowTitle); FreeResource(ref pszMainInstruction); FreeResource(ref pszContent); FreeResource(ref pszVerificationText); FreeResource(ref pszExpandedInformation); FreeResource(ref pszExpandedControlText); FreeResource(ref pszCollapsedControlText); FreeResource(ref pszFooter); } private static void FreeResource(ref IntPtr ptr) { StringHelper.FreeString(ptr, CharSet.Unicode); ptr = IntPtr.Zero; } } } }