Exemplo n.º 1
0
        Int32 TaskDialogProc(IntPtr hwnd, UInt32 uNotification, UIntPtr wParam, IntPtr lParam,
			                 IntPtr dwRefData)
        {
            Int32 result = NativeMethods.S_OK;

            // Cast notification value
            NativeMethods.TASKDIALOG_NOTIFICATIONS notification =
                (NativeMethods.TASKDIALOG_NOTIFICATIONS)uNotification;

            // Handle notification
            switch (notification) {
                case NativeMethods.TASKDIALOG_NOTIFICATIONS.TDN_BUTTON_CLICKED:
                    // Get button ID
                    Int32 buttonID = (Int32)wParam;

                    // Lookup button instance from collection, if necessary
                    if (Buttons.Count != 0 && buttonID < Buttons.Count) {
                        TaskDialogButton button = Buttons[buttonID];

                        // Raise Click event on button
                        button.RaiseClickEvent();

                        // Does the button prevent the dialog from closing?
                        if (button.PreventClose) {
                            // Note: According to MSDN, one has to return E_FAIL to prevent the task
                            // dialog from closing, but actually you have to return S_FALSE as using
                            // E_FAIL will cause the task dialog function to fail.
                            result = NativeMethods.S_FALSE;
                        }
                    }

                    break;

                case NativeMethods.TASKDIALOG_NOTIFICATIONS.TDN_CREATED:
                    // Set IsActivated property
                    IsActivated = true;

                    // Raise Activated event
                    OnActivated(EventArgs.Empty);

                    break;

                case NativeMethods.TASKDIALOG_NOTIFICATIONS.TDN_DESTROYED:
                    // Remove handle reference
                    Handle = IntPtr.Zero;

                    // Mark as inactive and uninitialized
                    IsActivated = false;
                    IsInitialized = false;

                    // Raise Closed event
                    OnClosed(EventArgs.Empty);

                    break;

                case NativeMethods.TASKDIALOG_NOTIFICATIONS.TDN_DIALOG_CONSTRUCTED:
                    // Set Handle property
                    Handle = hwnd;

                    // Initialize elements and set IsInitialized property
                    InitializeElements();
                    IsInitialized = true;

                    // Raise Initialized event
                    OnInitialized(EventArgs.Empty);

                    break;

                case NativeMethods.TASKDIALOG_NOTIFICATIONS.TDN_EXPANDO_BUTTON_CLICKED:
                    // Set IsExpanded property
                    IsExpanded = ((Int32)wParam != 0);

                    // Raise Expanded/Collapsed event according to expansion state
                    if (expanded) {
                        OnExpanded(EventArgs.Empty);
                    } else {
                        OnCollapsed(EventArgs.Empty);
                    }

                    break;

                case NativeMethods.TASKDIALOG_NOTIFICATIONS.TDN_HELP:
                    // Raise Help event
                    OnHelp(EventArgs.Empty);

                    break;

                case NativeMethods.TASKDIALOG_NOTIFICATIONS.TDN_HYPERLINK_CLICKED:
                    // Marshal URL string
                    String url = Marshal.PtrToStringUni(lParam);

                    // Find corresponding link and raise its Click event
                    Boolean eventRaised = false;
                    TaskDialogText taskDialogText;
                    TaskDialogLink taskDialogLink;

                    if (Content is TaskDialogText) {
                        // Check Content for event source
                        taskDialogText = (TaskDialogText)Content;
                        foreach (TaskDialogTextElement element in taskDialogText.Contents) {
                            if (element is TaskDialogLink) {
                                taskDialogLink = (TaskDialogLink)element;
                                if (url.Equals(taskDialogLink.Uri.ToString())) {
                                    taskDialogLink.RaiseClickEvent();
                                    eventRaised = true;
                                    break;
                                }
                            }
                        }
                        if (eventRaised) {
                            break;
                        }
                    }

                    if (ExpandedInformation is TaskDialogText) {
                        // Check ExpandedInformation for event source
                        taskDialogText = (TaskDialogText)ExpandedInformation;
                        foreach (TaskDialogTextElement element in taskDialogText.Contents) {
                            if (element is TaskDialogLink) {
                                taskDialogLink = (TaskDialogLink)element;
                                if (url.Equals(taskDialogLink.Uri.ToString())) {
                                    taskDialogLink.RaiseClickEvent();
                                    eventRaised = true;
                                    break;
                                }
                            }
                        }
                        if (eventRaised) {
                            break;
                        }
                    }

                    if (Footer is TaskDialogText) {
                        // Check Footer for event source
                        taskDialogText = (TaskDialogText)Footer;
                        foreach (TaskDialogTextElement element in taskDialogText.Contents) {
                            if (element is TaskDialogLink) {
                                taskDialogLink = (TaskDialogLink)element;
                                if (url.Equals(taskDialogLink.Uri.ToString())) {
                                    taskDialogLink.RaiseClickEvent();
                                    break;
                                }
                            }
                        }
                    }

                    break;

                case NativeMethods.TASKDIALOG_NOTIFICATIONS.TDN_RADIO_BUTTON_CLICKED:
                    // Get radio button ID
                    Int32 radioButtonID = (Int32)wParam;

                    // Lookup radio button instance from collection
                    TaskDialogRadioButton radioButton = RadioButtons[radioButtonID];

                    // Update IsChecked property
                    foreach (TaskDialogRadioButton radioBtn in RadioButtons) {
                        // Remove check state from all but the clicked radio button
                        if (radioButton != radioBtn) {
                            radioBtn.IsChecked = false;
                        }
                    }

                    radioButton.IsChecked = true;

                    // Raise Click event on radio button
                    radioButton.RaiseClickEvent();

                    break;

                case NativeMethods.TASKDIALOG_NOTIFICATIONS.TDN_TIMER:
                    // Create and initialize event arguments object
                    Int32 tickCount = (Int32)wParam;
                    TaskDialogTimerEventArgs timerEventArgs = new TaskDialogTimerEventArgs(tickCount);

                    // Raise Timer event
                    OnTimer(timerEventArgs);

                    // Check reset property of event arguments
                    // If set to true by the callee, the timer will be reset
                    if (timerEventArgs.Reset) {
                        // Reset indicated by S_FALSE result
                        result = NativeMethods.S_FALSE;
                    }

                    break;

                case NativeMethods.TASKDIALOG_NOTIFICATIONS.TDN_VERIFICATION_CLICKED:
                    // Check verification property
                    verificationChecked = ((Int32)wParam != 0);

                    // Raise VerificationChanged event
                    OnVerificationChanged(EventArgs.Empty);

                    break;
            }

            return result;
        }
Exemplo n.º 2
0
        /// <summary>
        /// Raises the <see cref="Timer"/> event.
        /// </summary>
        /// <param name="e">An <see cref="TaskDialogTimerEventArgs"/> object that contains the
        /// timer event data.</param>
        protected virtual void OnTimer(TaskDialogTimerEventArgs e)
        {
            EventHandler<TaskDialogTimerEventArgs> handler = timerEventHandler;

            if (handler != null) {
                handler(this, e);
            }
        }