コード例 #1
0
        /// <summary>
        /// Shows the TaskDialog.
        /// </summary>
        /// <returns>TaskDialogResult.</returns>
        public TaskDialogResult Show()
        {
            result = TaskDialogResult.Cancel;
            TaskDialogConfiguration nativeConfig = new TaskDialogConfiguration();

            nativeConfig.size            = (uint)Marshal.SizeOf(nativeConfig);
            nativeConfig.parentHandle    = hWndOwner;
            nativeConfig.commonButtons   = TaskDialogResult.Cancel;
            nativeConfig.content         = text;
            nativeConfig.windowTitle     = caption;
            nativeConfig.mainInstruction = instructionText;
            nativeConfig.taskDialogFlags = TaskDialogOptions.AllowCancel | TaskDialogOptions.ShowProgressBar | TaskDialogOptions.PositionRelativeToWindow | TaskDialogOptions.EnableHyperlinks;
            nativeConfig.callback        = new TaskDialogCallback(DialogProc);

            // Show the dialog.
            // NOTE: this is a BLOCKING call; the dialog proc callbacks
            // will be executed by the same thread as the
            // Show() call before the thread of execution
            // continues to the end of this method.
            showState = TaskDialogShowState.Showing;
            using (new EnableThemingInScope(true)) {     // Here is the way we use "vanilla" P/Invoke to call TaskDialogIndirect().
                TaskDialogIndirect(
                    nativeConfig,
                    out selectedButtonId,
                    IntPtr.Zero,
                    IntPtr.Zero);
            }
            showState = TaskDialogShowState.Closed;

            // Build and return dialog result to public API - leaving it
            // null after an exception is thrown is fine in this case
            if ((TaskDialogCommonButtonReturnId)selectedButtonId == TaskDialogCommonButtonReturnId.Ok)
            {
                result = TaskDialogResult.Ok;
            }

            // Reset progress bar.
            ProgressBarState = TaskDialogProgressBarState.Normal;
            ProgressBarValue = progressBarMinimum;

            // Free up strings.
            if (updatedStrings != null)
            {
                for (int i = 0; i < updatedStrings.Length; i++)
                {
                    if (updatedStrings[i] != IntPtr.Zero)
                    {
                        Marshal.FreeHGlobal(updatedStrings[i]);
                        updatedStrings[i] = IntPtr.Zero;
                    }
                }
            }

            return(result);
        }
コード例 #2
0
        /// <summary>
        /// Displays a TaskDialog-based error dialog with the error icon.
        /// </summary>
        /// <param name="title">The dialog's title.</param>
        /// <param name="text">The dialog's body.</param>
        /// <returns>TaskDialogResult.</returns>
        public TaskDialogResult ShowError(string title, string text)
        {
            result = TaskDialogResult.No;
            TaskDialogConfiguration nativeConfig = new TaskDialogConfiguration();

            Icon = TaskDialogStandardIcon.Error;

            nativeConfig.size            = (uint)Marshal.SizeOf(nativeConfig);
            nativeConfig.parentHandle    = hWndOwner;
            nativeConfig.commonButtons   = TaskDialogResult.Ok;
            nativeConfig.content         = text;
            nativeConfig.windowTitle     = title;
            nativeConfig.mainInstruction = instructionText;
            nativeConfig.taskDialogFlags = TaskDialogOptions.AllowCancel | TaskDialogOptions.PositionRelativeToWindow;
            nativeConfig.callback        = new TaskDialogCallback(DialogProc);

            showState = TaskDialogShowState.Showing;
            using (new EnableThemingInScope(true)) {     // Here is the way we use "vanilla" P/Invoke to call TaskDialogIndirect().
                TaskDialogIndirect(
                    nativeConfig,
                    out selectedButtonId,
                    IntPtr.Zero,
                    IntPtr.Zero);
            }
            showState = TaskDialogShowState.Closed;

            if ((TaskDialogCommonButtonReturnId)selectedButtonId == TaskDialogCommonButtonReturnId.Ok)
            {
                result = TaskDialogResult.Ok;
            }

            // Free up strings.
            if (updatedStrings != null)
            {
                for (int i = 0; i < updatedStrings.Length; i++)
                {
                    if (updatedStrings[i] != IntPtr.Zero)
                    {
                        Marshal.FreeHGlobal(updatedStrings[i]);
                        updatedStrings[i] = IntPtr.Zero;
                    }
                }
            }

            return(result);
        }
コード例 #3
0
ファイル: TaskDialog.cs プロジェクト: Robpol86/UnofficialDDNS
        /// <summary>
        /// Displays a TaskDialog-based error dialog with the error icon.
        /// </summary>
        /// <param name="title">The dialog's title.</param>
        /// <param name="text">The dialog's body.</param>
        /// <returns>TaskDialogResult.</returns>
        public TaskDialogResult ShowError( string title, string text )
        {
            result = TaskDialogResult.No;
            TaskDialogConfiguration nativeConfig = new TaskDialogConfiguration();
            Icon = TaskDialogStandardIcon.Error;

            nativeConfig.size = (uint) Marshal.SizeOf( nativeConfig );
            nativeConfig.parentHandle = hWndOwner;
            nativeConfig.commonButtons = TaskDialogResult.Ok;
            nativeConfig.content = text;
            nativeConfig.windowTitle = title;
            nativeConfig.mainInstruction = instructionText;
            nativeConfig.taskDialogFlags = TaskDialogOptions.AllowCancel | TaskDialogOptions.PositionRelativeToWindow;
            nativeConfig.callback = new TaskDialogCallback( DialogProc );

            showState = TaskDialogShowState.Showing;
            using ( new EnableThemingInScope( true ) ) { // Here is the way we use "vanilla" P/Invoke to call TaskDialogIndirect().
                TaskDialogIndirect(
                    nativeConfig,
                    out selectedButtonId,
                    IntPtr.Zero,
                    IntPtr.Zero );
            }
            showState = TaskDialogShowState.Closed;

            if ( (TaskDialogCommonButtonReturnId) selectedButtonId == TaskDialogCommonButtonReturnId.Ok ) {
                result = TaskDialogResult.Ok;
            }

            // Free up strings.
            if ( updatedStrings != null ) {
                for ( int i = 0; i < updatedStrings.Length; i++ ) {
                    if ( updatedStrings[i] != IntPtr.Zero ) {
                        Marshal.FreeHGlobal( updatedStrings[i] );
                        updatedStrings[i] = IntPtr.Zero;
                    }
                }
            }

            return result;
        }
コード例 #4
0
ファイル: TaskDialog.cs プロジェクト: Robpol86/UnofficialDDNS
        /// <summary>
        /// Shows the TaskDialog.
        /// </summary>
        /// <returns>TaskDialogResult.</returns>
        public TaskDialogResult Show()
        {
            result = TaskDialogResult.Cancel;
            TaskDialogConfiguration nativeConfig = new TaskDialogConfiguration();

            nativeConfig.size = (uint) Marshal.SizeOf( nativeConfig );
            nativeConfig.parentHandle = hWndOwner;
            nativeConfig.commonButtons = TaskDialogResult.Cancel;
            nativeConfig.content = text;
            nativeConfig.windowTitle = caption;
            nativeConfig.mainInstruction = instructionText;
            nativeConfig.taskDialogFlags = TaskDialogOptions.AllowCancel | TaskDialogOptions.ShowProgressBar | TaskDialogOptions.PositionRelativeToWindow | TaskDialogOptions.EnableHyperlinks;
            nativeConfig.callback = new TaskDialogCallback( DialogProc );

            // Show the dialog.
            // NOTE: this is a BLOCKING call; the dialog proc callbacks
            // will be executed by the same thread as the
            // Show() call before the thread of execution
            // continues to the end of this method.
            showState = TaskDialogShowState.Showing;
            using ( new EnableThemingInScope( true ) ) { // Here is the way we use "vanilla" P/Invoke to call TaskDialogIndirect().
                TaskDialogIndirect(
                    nativeConfig,
                    out selectedButtonId,
                    IntPtr.Zero,
                    IntPtr.Zero );
            }
            showState = TaskDialogShowState.Closed;

            // Build and return dialog result to public API - leaving it
            // null after an exception is thrown is fine in this case
            if ( (TaskDialogCommonButtonReturnId) selectedButtonId == TaskDialogCommonButtonReturnId.Ok ) {
                result = TaskDialogResult.Ok;
            }

            // Reset progress bar.
            ProgressBarState = TaskDialogProgressBarState.Normal;
            ProgressBarValue = progressBarMinimum;

            // Free up strings.
            if ( updatedStrings != null ) {
                for ( int i = 0; i < updatedStrings.Length; i++ ) {
                    if ( updatedStrings[i] != IntPtr.Zero ) {
                        Marshal.FreeHGlobal( updatedStrings[i] );
                        updatedStrings[i] = IntPtr.Zero;
                    }
                }
            }

            return result;
        }
コード例 #5
0
 public static extern HResult TaskDialogIndirect(
     [In] TaskDialogConfiguration taskConfig,
     [Out] out int button,
     [Out] out int radioButton,
     [MarshalAs(UnmanagedType.Bool), Out] out bool verificationFlagChecked);
コード例 #6
0
 private static extern HResult TaskDialogIndirect(
     [In] TaskDialogConfiguration taskConfig,
     [Out] out int button,
     [Out] IntPtr radioButton,
     [Out] IntPtr verificationFlagChecked);