コード例 #1
0
        internal static MessageBoxResult ShowCore(IntPtr owner, string messageBoxText, string caption, MessageBoxButton button, MessageBoxImage icon, MessageBoxResult defaultResult, MessageBoxOptions options)
        {
            if (!MessageBox.IsValidMessageBoxButton(button))
            {
                throw new InvalidEnumArgumentException("button", (int)button, typeof(MessageBoxButton));
            }
            if (!MessageBox.IsValidMessageBoxImage(icon))
            {
                throw new InvalidEnumArgumentException("icon", (int)icon, typeof(MessageBoxImage));
            }
            if (!MessageBox.IsValidMessageBoxResult(defaultResult))
            {
                throw new InvalidEnumArgumentException("defaultResult", (int)defaultResult, typeof(MessageBoxResult));
            }
            if (!MessageBox.IsValidMessageBoxOptions(options))
            {
                throw new InvalidEnumArgumentException("options", (int)options, typeof(MessageBoxOptions));
            }
            if ((options & (MessageBoxOptions.ServiceNotification | MessageBoxOptions.DefaultDesktopOnly)) != MessageBoxOptions.None)
            {
                SecurityHelper.DemandUnmanagedCode();
                if (owner != IntPtr.Zero)
                {
                    throw new ArgumentException(SR.Get("CantShowMBServiceWithOwner"));
                }
            }
            else if (owner == IntPtr.Zero)
            {
                owner = UnsafeNativeMethods.GetActiveWindow();
            }
            int type = (int)(button | (MessageBoxButton)icon | (MessageBoxButton)MessageBox.DefaultResultToButtonNumber(defaultResult, button) | (MessageBoxButton)options);

            return(MessageBox.Win32ToMessageBoxResult(UnsafeNativeMethods.MessageBox(new HandleRef(null, owner), messageBoxText, caption, type)));
        }