Exemplo n.º 1
0
        /// <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] TaskDialogNotification msg, [In] UIntPtr wparam, [In] IntPtr lparam, [In] IntPtr refData)
        {
            TaskDialogCallback cb = this.callback;
            if (cb != 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.
                ActiveTaskDialog activeDialog = new ActiveTaskDialog(hwnd);
                TaskDialogNotificationArgs args = new TaskDialogNotificationArgs
                {
                    Notification = msg
                };

                switch (args.Notification)
                {
                    case TaskDialogNotification.ButtonClicked:
                    case TaskDialogNotification.RadioButtonClicked:
                        args.ButtonId = (int)wparam;
                        break;
                    case TaskDialogNotification.HyperlinkClicked:
                        args.Hyperlink = Marshal.PtrToStringUni(lparam);
                        break;
                    case TaskDialogNotification.Timer:
                        args.TimerTickCount = (uint)wparam;
                        break;
                    case TaskDialogNotification.VerificationClicked:
                        args.VerificationFlagChecked = (wparam != UIntPtr.Zero);
                        break;
                    case TaskDialogNotification.ExpandoButtonClicked:
                        args.Expanded = (wparam != UIntPtr.Zero);
                        break;
                }

                return (cb(activeDialog, args, this.callbackData) ? 1 : 0);
            }

            return 0; // false;
        }
Exemplo n.º 2
0
 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)
     {
         ActiveTaskDialog activeDialog = new ActiveTaskDialog(hwnd);
         TaskDialogNotificationArgs args = new TaskDialogNotificationArgs();
         args.Notification = (TaskDialogNotification)msg;
         switch (args.Notification)
         {
             case TaskDialogNotification.ButtonClicked:
             case TaskDialogNotification.RadioButtonClicked:
                 args.ButtonId = (int)wparam;
                 break;
             case TaskDialogNotification.HyperlinkClicked:
                 args.Hyperlink = Marshal.PtrToStringUni(lparam);
                 break;
             case TaskDialogNotification.Timer:
                 args.TimerTickCount = (uint)wparam;
                 break;
             case TaskDialogNotification.VerificationClicked:
                 args.VerificationFlagChecked = (wparam != UIntPtr.Zero);
                 break;
             case TaskDialogNotification.ExpandoButtonClicked:
                 args.Expanded = (wparam != UIntPtr.Zero);
                 break;
         }
         return (callback(activeDialog, args, this.callbackData) ? 1 : 0);
     }
     return 0;
 }