Пример #1
0
        internal void NativeShow()
        {
            // Applies config struct and other settings, then
            // calls main Win32 function.
            if (settings == null)
            {
                throw new InvalidOperationException(LocalizedMessages.NativeTaskDialogConfigurationError);
            }

            // Do a last-minute parse of the various dialog control lists,
            // and only allocate the memory at the last minute.

            MarshalDialogControlStructs();

            // Make the call and show the dialog.
            // NOTE: this call is BLOCKING, though the thread
            // WILL re-enter via the DialogProc.
            try {
                ShowState = DialogShowState.Showing;

                int  selectedButtonId;
                int  selectedRadioButtonId;
                bool checkBoxChecked;

                // Here is the way we use "vanilla" P/Invoke to call TaskDialogIndirect().
                HResult hresult = TaskDialogNativeMethods.TaskDialogIndirect(
                    nativeDialogConfig,
                    out selectedButtonId,
                    out selectedRadioButtonId,
                    out checkBoxChecked);

                if (CoreErrorHelper.Failed(hresult))
                {
                    string msg;
                    switch (hresult)
                    {
                    case HResult.InvalidArguments:
                        msg = LocalizedMessages.NativeTaskDialogInternalErrorArgs;
                        break;

                    case HResult.OutOfMemory:
                        msg = LocalizedMessages.NativeTaskDialogInternalErrorComplex;
                        break;

                    default:
                        msg = string.Format(System.Globalization.CultureInfo.InvariantCulture,
                                            LocalizedMessages.NativeTaskDialogInternalErrorUnexpected,
                                            hresult);
                        break;
                    }
                    Exception e = Marshal.GetExceptionForHR((int)hresult);
                    throw new Win32Exception(msg, e);
                }

                SelectedButtonId      = selectedButtonId;
                SelectedRadioButtonId = selectedRadioButtonId;
                CheckBoxChecked       = checkBoxChecked;
            } catch (EntryPointNotFoundException exc) {
                throw new NotSupportedException(LocalizedMessages.NativeTaskDialogVersionError, exc);
            } finally {
                ShowState = DialogShowState.Closed;
            }
        }
Пример #2
0
		/// <summary>
		/// Sets important text properties.
		/// </summary>
		/// <param name="dialogConfig">An instance of a <see cref="TaskDialogNativeMethods.TaskDialogConfiguration"/> object.</param>
		private void ApplyTextConfiguration(TaskDialogNativeMethods.TaskDialogConfiguration dialogConfig) {
			// note that nulls or empty strings are fine here.
			dialogConfig.content = text;
			dialogConfig.windowTitle = caption;
			dialogConfig.mainInstruction = instructionText;
			dialogConfig.expandedInformation = detailsExpandedText;
			dialogConfig.expandedControlText = detailsExpandedLabel;
			dialogConfig.collapsedControlText = detailsCollapsedLabel;
			dialogConfig.footerText = footerText;
			dialogConfig.verificationText = checkBoxText;
		}
Пример #3
0
		private void ApplyOptionConfiguration(TaskDialogNativeMethods.TaskDialogConfiguration dialogConfig) {
			// Handle options - start with no options set.
			TaskDialogNativeMethods.TaskDialogOptions options = TaskDialogNativeMethods.TaskDialogOptions.None;
			if (cancelable) {
				options |= TaskDialogNativeMethods.TaskDialogOptions.AllowCancel;
			}
			if (footerCheckBoxChecked.HasValue && footerCheckBoxChecked.Value) {
				options |= TaskDialogNativeMethods.TaskDialogOptions.CheckVerificationFlag;
			}
			if (hyperlinksEnabled) {
				options |= TaskDialogNativeMethods.TaskDialogOptions.EnableHyperlinks;
			}
			if (detailsExpanded) {
				options |= TaskDialogNativeMethods.TaskDialogOptions.ExpandedByDefault;
			}
			if (Tick != null) {
				options |= TaskDialogNativeMethods.TaskDialogOptions.UseCallbackTimer;
			}
			if (startupLocation == TaskDialogStartupLocation.CenterOwner) {
				options |= TaskDialogNativeMethods.TaskDialogOptions.PositionRelativeToWindow;
			}

			// Note: no validation required, as we allow this to 
			// be set even if there is no expanded information 
			// text because that could be added later.
			// Default for Win32 API is to expand into (and after) 
			// the content area.
			if (expansionMode == TaskDialogExpandedDetailsLocation.ExpandFooter) {
				options |= TaskDialogNativeMethods.TaskDialogOptions.ExpandFooterArea;
			}

			// Finally, apply options to config.
			dialogConfig.taskDialogFlags = options;
		}
Пример #4
0
		private void ApplyGeneralNativeConfiguration(TaskDialogNativeMethods.TaskDialogConfiguration dialogConfig) {
			// If an owner wasn't specifically specified, 
			// we'll use the app's main window.
			if (ownerWindow != IntPtr.Zero) {
				dialogConfig.parentHandle = ownerWindow;
			}

			// Other miscellaneous sets.
			dialogConfig.mainIcon = new TaskDialogNativeMethods.IconUnion((int)icon);
			dialogConfig.footerIcon = new TaskDialogNativeMethods.IconUnion((int)footerIcon);
			dialogConfig.commonButtons = (TaskDialogNativeMethods.TaskDialogCommonButtons)standardButtons;
		}