private void UpdateTextCore(string s, TaskDialogNativeMethods.TaskDialogElements element)
        {
            AssertCurrentlyShowing();

            FreeOldString(element);
            SendMessageHelper(
                TaskDialogNativeMethods.TaskDialogMessages.SetElementText,
                (int)element,
                (long)MakeNewString(s, element));
        }
 private void UpdateIconCore(TaskDialogStandardIcon icon, TaskDialogNativeMethods.TaskDialogIconElement element)
 {
     AssertCurrentlyShowing();
     SendMessageHelper(
         TaskDialogNativeMethods.TaskDialogMessages.UpdateIcon,
         (int)element,
         (long)icon);
 }
 private void UpdateIconCore(TaskDialogStandardIcon icon, TaskDialogNativeMethods.TASKDIALOG_ICON_ELEMENT element)
 {
     AssertCurrentlyShowing();
     SendMessageHelper(
         TaskDialogNativeMethods.TASKDIALOG_MESSAGES.TDM_UPDATE_ICON,
         (int)element,
         (long)icon);
 }
        private void UpdateTextCore(string s, TaskDialogNativeMethods.TASKDIALOG_ELEMENTS element)
        {
            AssertCurrentlyShowing();

            FreeOldString(element);
            SendMessageHelper(
                TaskDialogNativeMethods.TASKDIALOG_MESSAGES.TDM_SET_ELEMENT_TEXT,
                (int)element,
                (long)MakeNewString(s, element));
        }
        private static IntPtr AllocateAndMarshalButtons(TaskDialogNativeMethods.TaskDialogButton[] structs)
        {
            IntPtr initialPtr = Marshal.AllocHGlobal(
                Marshal.SizeOf(typeof(TaskDialogNativeMethods.TaskDialogButton)) * structs.Length);

            IntPtr currentPtr = initialPtr;
            bool is64Bit = Marshal.SizeOf(typeof (IntPtr)) == 8;
            foreach (TaskDialogNativeMethods.TaskDialogButton button in structs)
            {
                Marshal.StructureToPtr(button, currentPtr, false);
                currentPtr = (IntPtr)(is64Bit ? currentPtr.ToInt64() : currentPtr.ToInt32() + Marshal.SizeOf(button));
            }

            return initialPtr;
        }
示例#6
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;
 }
示例#7
0
        private void ApplyOptionConfiguration(TaskDialogNativeMethods.TASKDIALOGCONFIG dialogConfig)
        {
            // Handle options - start with no options set.
            TaskDialogNativeMethods.TASKDIALOG_FLAGS options = TaskDialogNativeMethods.TASKDIALOG_FLAGS.NONE;
            if (cancelable)
                options |= TaskDialogNativeMethods.TASKDIALOG_FLAGS.TDF_ALLOW_DIALOG_CANCELLATION;
            if (footerCheckBoxChecked.HasValue && footerCheckBoxChecked.Value)
                options |= TaskDialogNativeMethods.TASKDIALOG_FLAGS.TDF_VERIFICATION_FLAG_CHECKED;
            if (hyperlinksEnabled)
                options |= TaskDialogNativeMethods.TASKDIALOG_FLAGS.TDF_ENABLE_HYPERLINKS;
            if (detailsExpanded)
                options |= TaskDialogNativeMethods.TASKDIALOG_FLAGS.TDF_EXPANDED_BY_DEFAULT;
            if (Tick != null)
                options |= TaskDialogNativeMethods.TASKDIALOG_FLAGS.TDF_CALLBACK_TIMER;
            if (startupLocation == TaskDialogStartupLocation.CenterOwner)
                options |= TaskDialogNativeMethods.TASKDIALOG_FLAGS.TDF_POSITION_RELATIVE_TO_WINDOW;

            // 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.TASKDIALOG_FLAGS.TDF_EXPAND_FOOTER_AREA;

            // Finally, apply options to config.
            dialogConfig.dwFlags = options;
        }
        // Allocates a new string on the unmanaged heap, 
        // and stores the pointer so we can free it later.

        private IntPtr MakeNewString(string text, TaskDialogNativeMethods.TaskDialogElements element)
        {
            IntPtr newStringPtr = Marshal.StringToHGlobalUni(text);
            updatedStrings[(int)element] = newStringPtr;
            return newStringPtr;
        }
示例#9
0
 /// <summary>
 /// Sets important text properties.
 /// </summary>
 /// <param name="dialogConfig">An instance of a <see cref="TaskDialogNativeMethods.TASKDIALOGCONFIG"/> object.</param>
 private void ApplyTextConfiguration(TaskDialogNativeMethods.TASKDIALOGCONFIG dialogConfig)
 {
     // note that nulls or empty strings are fine here.
     dialogConfig.pszContent = text;
     dialogConfig.pszWindowTitle = caption;
     dialogConfig.pszMainInstruction = instructionText;
     dialogConfig.pszExpandedInformation = detailsExpandedText;
     dialogConfig.pszExpandedControlText = detailsExpandedLabel;
     dialogConfig.pszCollapsedControlText = detailsCollapsedLabel;
     dialogConfig.pszFooter = footerText;
     dialogConfig.pszVerificationText = checkBoxText;
 }
示例#10
0
        private void ApplyGeneralNativeConfiguration(TaskDialogNativeMethods.TASKDIALOGCONFIG dialogConfig)
        {
            // If an owner wasn't specifically specified,
            // we'll use the app's main window.
            if (ownerWindow != IntPtr.Zero)
                dialogConfig.hwndParent = ownerWindow;

            // Other miscellaneous sets.
            dialogConfig.MainIcon =
                new TaskDialogNativeMethods.TASKDIALOGCONFIG_ICON_UNION((int)icon);
            dialogConfig.FooterIcon =
                new TaskDialogNativeMethods.TASKDIALOGCONFIG_ICON_UNION((int)footerIcon);
            dialogConfig.dwCommonButtons =
                (TaskDialogNativeMethods.TASKDIALOG_COMMON_BUTTON_FLAGS)standardButtons;
        }
示例#11
0
        internal void NativeShow()
        {
            // Applies config struct and other settings, then
            // calls main Win32 function.
            if (settings == null)
            {
                throw new InvalidOperationException(
                          "An error has occurred in dialog configuration.");
            }

            // 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;

                // 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.E_INVALIDARG:
                        msg = "Invalid arguments to Win32 call.";
                        break;

                    case HRESULT.E_OUTOFMEMORY:
                        msg = "Dialog contents too complex.";
                        break;

                    default:
                        msg = String.Format(

                            "An unexpected internal error occurred in the Win32 call:{0:x}",
                            hresult);
                        break;
                    }
                    Exception e = Marshal.GetExceptionForHR((int)hresult);
                    throw new Win32Exception(msg, e);
                }
            }
            catch (EntryPointNotFoundException)
            {
                throw new NotSupportedException("TaskDialog feature needs to load version 6 of comctl32.dll but a different version is current loaded in memory.");
            }
            finally
            {
                showState = DialogShowState.Closed;
            }
        }
示例#12
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;
        }
示例#13
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;
        }
        private int SendMessageHelper(TaskDialogNativeMethods.TaskDialogMessages message, int wparam, long lparam)
        {
            // Be sure to at least assert here - 
            // messages to invalid handles often just disappear silently
            Debug.Assert(hWndDialog != null, "HWND for dialog is null during SendMessage");

            return (int)CoreNativeMethods.SendMessage(
                hWndDialog,
                (uint)message,
                (IntPtr)wparam,
                new IntPtr(lparam));
        }
        private static IntPtr AllocateAndMarshalButtons(TaskDialogNativeMethods.TASKDIALOG_BUTTON[] structs)
        {
            IntPtr initialPtr = Marshal.AllocHGlobal(
                Marshal.SizeOf(typeof(TaskDialogNativeMethods.TASKDIALOG_BUTTON)) * structs.Length);

            IntPtr currentPtr = initialPtr;
            foreach (TaskDialogNativeMethods.TASKDIALOG_BUTTON button in structs)
            {
                Marshal.StructureToPtr(button, currentPtr, false);
                currentPtr = (IntPtr)((int)currentPtr + Marshal.SizeOf(button));
            }

            return initialPtr;
        }
 private bool IsOptionSet(TaskDialogNativeMethods.TaskDialogOptions flag)
 {
     return ((nativeDialogConfig.taskDialogFlags & flag) == flag);
 }
 private bool IsOptionSet(TaskDialogNativeMethods.TASKDIALOG_FLAGS flag)
 {
     return ((nativeDialogConfig.dwFlags & flag) == flag);
 }
 // Checks to see if the given element already has an 
 // updated string, and if so, 
 // frees it. This is done in preparation for a call to 
 // MakeNewString(), to prevent
 // leaks from multiple updates calls on the same element 
 // within a single native dialog lifetime.
 private void FreeOldString(TaskDialogNativeMethods.TaskDialogElements element)
 {
     int elementIndex = (int)element;
     if (updatedStrings[elementIndex] != IntPtr.Zero)
     {
         Marshal.FreeHGlobal(updatedStrings[elementIndex]);
         updatedStrings[elementIndex] = IntPtr.Zero;
     }
 }
 // Allocates a new string on the unmanaged heap,
 // and stores the pointer so we can free it later.
 private IntPtr MakeNewString(string s,
     TaskDialogNativeMethods.TASKDIALOG_ELEMENTS element)
 {
     IntPtr newStringPtr = Marshal.StringToHGlobalUni(s);
     updatedStrings[(int)element] = newStringPtr;
     return newStringPtr;
 }
示例#20
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;
                using (new EnableThemingInScope(true))
                {
                    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;
                    }
                    var 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;
            }
        }
		private static IntPtr AllocateAndMarshalButtons(TaskDialogNativeMethods.TaskDialogButton[] buttons)
		{
			var buttonType = typeof(TaskDialogNativeMethods.TaskDialogButton);
			var buttonTypeSize = Marshal.SizeOf(buttonType);

			IntPtr result = Marshal.AllocHGlobal(buttonTypeSize * buttons.Length);

			for (int index = 0; index < buttons.Length; index++)
			{
				var button = buttons[index];
				var tmp = (IntPtr)(result.ToInt64() + buttonTypeSize * index);
				Marshal.StructureToPtr(button, tmp, false);
			}
			return result;
		}