Arguments passed to the TaskDialog callback.
        /// <summary>
        /// The callback from the native Task Dialog. This prepares the friendlier arguments and calls the simplier callback.
        /// </summary>
        /// <param name="hwnd">The window handle of the Task Dialog that is active.</param>
        /// <param name="msg">The notification. A TaskDialogNotification value.</param>
        /// <param name="wparam">Specifies additional noitification information.  The contents of this parameter depends on the value of the msg parameter.</param>
        /// <param name="lparam">Specifies additional noitification information.  The contents of this parameter depends on the value of the msg parameter.</param>
        /// <param name="refData">Specifies the application-defined value given in the call to TaskDialogIndirect.</param>
        /// <returns>A HRESULT. It's not clear in the spec what a failed result will do.</returns>
        private int PrivateCallback([In] IntPtr hwnd, [In] uint msg, [In] UIntPtr wparam, [In] IntPtr lparam, [In] IntPtr refData)
        {
            TaskDialogCallback callback = this.callback;
            if (callback != null)
            {
                // Prepare arguments for the callback to the user we are insulating from Interop casting sillyness.

                // Future: Consider reusing a single ActiveTaskDialog object and mark it as destroyed on the destry notification.
                VistaActiveTaskDialog activeDialog = new VistaActiveTaskDialog(hwnd);
                VistaTaskDialogNotificationArgs args = new VistaTaskDialogNotificationArgs();
                args.Config = this.config;
                args.Notification = (VistaTaskDialogNotification)msg;
                switch (args.Notification)
                {
                    case VistaTaskDialogNotification.ButtonClicked:
                    case VistaTaskDialogNotification.RadioButtonClicked:
                        args.ButtonId = (int)wparam;
                        break;
                    case VistaTaskDialogNotification.HyperlinkClicked:
                        args.Hyperlink = Marshal.PtrToStringUni(lparam);
                        break;
                    case VistaTaskDialogNotification.Timer:
                        args.TimerTickCount = (uint)wparam;
                        break;
                    case VistaTaskDialogNotification.VerificationClicked:
                        args.VerificationFlagChecked = (wparam != UIntPtr.Zero);
                        break;
                    case VistaTaskDialogNotification.ExpandoButtonClicked:
                        args.Expanded = (wparam != UIntPtr.Zero);
                        break;
                }

                bool result = callback(activeDialog, args, this.callbackData);

                return (result ? 1 : 0);
            }

            return 0; // false;
        }
        /// <summary>
        /// The callback from the native Task Dialog. This prepares the friendlier arguments and calls the simplier callback.
        /// </summary>
        /// <param name="hwnd">The window handle of the Task Dialog that is active.</param>
        /// <param name="msg">The notification. A TaskDialogNotification value.</param>
        /// <param name="wparam">Specifies additional noitification information.  The contents of this parameter depends on the value of the msg parameter.</param>
        /// <param name="lparam">Specifies additional noitification information.  The contents of this parameter depends on the value of the msg parameter.</param>
        /// <param name="refData">Specifies the application-defined value given in the call to TaskDialogIndirect.</param>
        /// <returns>A HRESULT. It's not clear in the spec what a failed result will do.</returns>
        private int PrivateCallback([In] IntPtr hwnd, [In] uint msg, [In] UIntPtr wparam, [In] IntPtr lparam, [In] IntPtr refData)
        {
            TaskDialogCallback callback = this.callback;
            if (callback != null)
            {
                // Prepare arguments for the callback to the user we are insulating from Interop casting sillyness.

                // Future: Consider reusing a single ActiveTaskDialog object and mark it as destroyed on the destry notification.
                VistaActiveTaskDialog activeDialog = new VistaActiveTaskDialog(hwnd);
                VistaTaskDialogNotificationArgs args = new VistaTaskDialogNotificationArgs();
                args.Config = this.config;
                args.Notification = (VistaTaskDialogNotification)msg;
                switch (args.Notification)
                {
                    case VistaTaskDialogNotification.ButtonClicked:
                    case VistaTaskDialogNotification.RadioButtonClicked:
                        args.ButtonId = (int)wparam;

                        // The index, ideally, should be -1 or something whenever the
                        //dialog was closed by non-common-button means such as Alt+F4
                        //or using the Close action on the System menu or the red X

                        // I can, with little trouble, detect this for the emulated dialog,
                        //however the native dialog gives me no indication and in fact
                        //simply reports a buttonId of 2 (Cancel) regardless of whether
                        //the actual Cancel button was used or one of the above alt methods.

                        // If I could hook into the native dialogs messages and detect:
                        // WM_SYSCOMMAND with WParam of SC_CLOSE
                        // ...then I could tell for sure, but I'm not sure how to listen
                        //in on its messages. My Win32-fu not good enough.

                        // For now, I will have the emulated dialog simply pretend like it
                        //cannot tell either until I can figure out a way to determine it
                        //with the native dialog, too.

                        if (args.ButtonId > 100)
                            args.ButtonIndex = args.ButtonId % 500;
                        else
                            args.ButtonIndex = TaskDialog.GetButtonIndexForCommonButton(args.Config.CommonButtons, args.ButtonId);
                        break;
                    case VistaTaskDialogNotification.HyperlinkClicked:
                        args.Hyperlink = Marshal.PtrToStringUni(lparam);
                        break;
                    case VistaTaskDialogNotification.Timer:
                        args.TimerTickCount = (uint)wparam;
                        break;
                    case VistaTaskDialogNotification.VerificationClicked:
                        args.VerificationFlagChecked = (wparam != UIntPtr.Zero);
                        break;
                    case VistaTaskDialogNotification.ExpandoButtonClicked:
                        args.Expanded = (wparam != UIntPtr.Zero);
                        break;
                }

                bool result = callback(activeDialog, args, this.callbackData);

                return (result ? 1 : 0);
            }

            return 0; // false;
        }
        private void CallbackTimer_Tick(object sender, EventArgs e)
        {
            var args = new VistaTaskDialogNotificationArgs();

            args.Config = this.options;
            args.Notification = VistaTaskDialogNotification.Timer;
            args.TimerTickCount = Convert.ToUInt32(Math.Round(DateTime.Now.Subtract(_callbackTimerStart).TotalMilliseconds, 0));

            OnCallback(args);
        }
 private void HandleCallbackReturn(VistaTaskDialogNotificationArgs e, bool returnValue)
 {
     switch (e.Notification)
     {
         default: // all others
             // Return value ignored according to MSDN
             break;
         case VistaTaskDialogNotification.ButtonClicked:
             // TRUE : prevent dialog from closing
             _preventClose = returnValue;
             break;
         case VistaTaskDialogNotification.Timer:
             // TRUE : reset tickcount
             if (returnValue)
                 _callbackTimerStart = DateTime.Now;
             break;
     }
 }
        /// <summary>
        /// Notifies any callback handlers that the dialog has been created but not yet shown.
        /// </summary>
        public void NotifyCreated()
        {
            var args = new VistaTaskDialogNotificationArgs();

            args.Config = this.options;
            args.Notification = VistaTaskDialogNotification.Created;

            OnCallback(args);
        }
 /// <summary>
 /// Raises a callback.
 /// </summary>
 /// <param name="e">The <see cref="VistaTaskDialogNotificationArgs"/> instance containing the event data.</param>
 protected void OnCallback(VistaTaskDialogNotificationArgs e)
 {
     if (options.Callback != null)
     {
         HandleCallbackReturn(e, options.Callback(this, e, options.CallbackData));
     }
 }
        /// <summary>
        /// Notifies any callback handlers that the close button was clicked.
        /// </summary>
        public void NotifyClosing()
        {
            // Caused by clicking X or Alt+F4 or Esc, so notify via callback
            if (!_requestingClose)
            {
                var args = new VistaTaskDialogNotificationArgs();

                args.Config = this.options;
                args.Notification = VistaTaskDialogNotification.ButtonClicked;
                args.ButtonId = (int)TaskDialogSimpleResult.Cancel;
                args.ButtonIndex = TaskDialog.GetButtonIndexForCommonButton(options.CommonButtons, args.ButtonId);
                //args.ButtonIndex = -1;
                // See TaskDialogInterop.cs PrivateCallback method for why
                //the above line is commented out

                OnCallback(args);
            }
        }
        /// <summary>
        /// Notifies any callback handlers that the dialog is destroyed.
        /// </summary>
        public void NotifyClosed()
        {
            if (options.EnableCallbackTimer)
            {
                _callbackTimer.Stop();
            }

            var args = new VistaTaskDialogNotificationArgs();

            args.Config = this.options;
            args.Notification = VistaTaskDialogNotification.Destroyed;

            OnCallback(args);
        }
        private bool taskDialog_Callback2(IActiveTaskDialog dialog, VistaTaskDialogNotificationArgs args, object callbackData)
        {
            bool result = false;

            switch (args.Notification)
            {
                case VistaTaskDialogNotification.Created:
                    _downloadedPercent = 0;
                    dialog.SetProgressBarRange(0, 100);
                    break;
                case VistaTaskDialogNotification.ButtonClicked:
                    if (args.ButtonId == 500)
                    {
                        _downloadTimerReset = true;
                        result = true; // prevent dialog from closing
                    }
                    break;
                case VistaTaskDialogNotification.Timer:
                    if (_downloadedPercent < 100 && _downloadRandomizer.Next(0, 10) == 0)
                    {
                        _downloadedPercent++;

                        dialog.SetProgressBarPosition(_downloadedPercent);
                        dialog.SetWindowTitle(
                            String.Format(
                                "{0:P0} Complete Downloading File...",
                                (Convert.ToDouble(_downloadedPercent) / 100d)));
                    }
                    else if (_downloadedPercent >= 100)
                    {
                        // Download finished
                        // Close the dialog by simulating a click on the cancel button
                        dialog.ClickButton(TaskDialog.GetButtonIdForCustomButton(1));
                    }

                    // 131072 = 1 MB in bytes
                    dialog.SetContent(
                        String.Format(
                            "Time elapsed: {0} | Download rate: {1}/s",
                            TimeSpan.FromMilliseconds(args.TimerTickCount).ToString(@"h\:mm\:ss"),
                            GetByteScaleSizeBinary(_downloadRandomizer.Next(0, 131072))));

                    if (_downloadTimerReset)
                    {
                        // TRUE: reset tick count (args.TimerTickCount)
                        result = true;
                        _downloadTimerReset = false;
                    }
                    break;
            }

            return result;
        }
        private bool taskDialog_Callback1(IActiveTaskDialog dialog, VistaTaskDialogNotificationArgs args, object callbackData)
        {
            bool result = false;

            switch (args.Notification)
            {
                case VistaTaskDialogNotification.HyperlinkClicked:
                    //result = true; // prevents HREF from being processed automatically by ShellExecute
                    MessageBox.Show("Hyperlink clicked: " + args.Hyperlink);
                    break;
            }

            return result;
        }
    private bool taskDialog_Callback(IActiveTaskDialog dialog, VistaTaskDialogNotificationArgs args, object callbackData) {
      bool result = false;

      switch (args.Notification) {
        case VistaTaskDialogNotification.ButtonClicked:
          if (args.ButtonId == 500) {
            this.autoUpdater.ReadyToBeInstalled += AutoUpdater_ReadyToBeInstalled;
            this.autoUpdater.InstallNow();
          } else if (args.ButtonId == 501) {
          }
          break;
      }

      return result;
    }