نوشته شده توسط
ahrimaneahurai
دوست عزیز این راه حل شما درسته و به ذهن خودم رسید اما می خوام از خود مسیج باکس دات نت استفاده کنم
این هم سورش کد net framework.:
به نظرتون ممکنه؟
private static DialogResult ShowCore(IWin32Window owner, string text, string caption, MessageBoxButtons buttons, MessageBoxIcon icon, MessageBoxDefaultButton defaultButton, MessageBoxOptions options, bool showHelp)
{
DialogResult result;
if (!ClientUtils.IsEnumValid(buttons, (int) buttons, 0, 5))
{
throw new InvalidEnumArgumentException("buttons", (int) buttons, typeof(MessageBoxButtons));
}
if (!WindowsFormsUtils.EnumValidator.IsEnumWithinShif tedRange(icon, 4, 0, 4))
{
throw new InvalidEnumArgumentException("icon", (int) icon, typeof(MessageBoxIcon));
}
if (!WindowsFormsUtils.EnumValidator.IsEnumWithinShif tedRange(defaultButton, 8, 0, 2))
{
throw new InvalidEnumArgumentException("defaultButton", (int) defaultButton, typeof(DialogResult));
}
if (!SystemInformation.UserInteractive && ((options & (MessageBoxOptions.ServiceNotification | MessageBoxOptions.DefaultDesktopOnly)) == 0))
{
throw new InvalidOperationException(SR.GetString("CantShowMo dalOnNonInteractive"));
}
if ((owner != null) && ((options & (MessageBoxOptions.ServiceNotification | MessageBoxOptions.DefaultDesktopOnly)) != 0))
{
throw new ArgumentException(SR.GetString("CantShowMBServiceW ithOwner"), "options");
}
if (showHelp && ((options & (MessageBoxOptions.ServiceNotification | MessageBoxOptions.DefaultDesktopOnly)) != 0))
{
throw new ArgumentException(SR.GetString("CantShowMBServiceW ithHelp"), "options");
}
if ((options & ~(MessageBoxOptions.RtlReading | MessageBoxOptions.RightAlign)) != 0)
{
IntSecurity.UnmanagedCode.Demand();
}
IntSecurity.SafeSubWindows.Demand();
int type = showHelp ? 0x4000 : 0;
type |= ((buttons | ((MessageBoxButtons) ((int) icon))) | ((MessageBoxButtons) ((int) defaultButton))) | ((MessageBoxButtons) ((int) options));
IntPtr zero = IntPtr.Zero;
if (showHelp || ((options & (MessageBoxOptions.ServiceNotification | MessageBoxOptions.DefaultDesktopOnly)) == 0))
{
if (owner == null)
{
zero = UnsafeNativeMethods.GetActiveWindow();
}
else
{
zero = Control.GetSafeHandle(owner);
}
}
IntPtr userCookie = IntPtr.Zero;
if (Application.UseVisualStyles)
{
userCookie = UnsafeNativeMethods.ThemingScope.Activate();
}
Application.BeginModalMessageLoop();
try
{
result = Win32ToDialogResult(SafeNativeMethods.MessageBox(n ew HandleRef(owner, zero), text, caption, type));
}
finally
{
Application.EndModalMessageLoop();
UnsafeNativeMethods.ThemingScope.Deactivate(userCo okie);
}
UnsafeNativeMethods.SendMessage(new HandleRef(owner, zero), 7, 0, 0);
return result;
}
[DllImport("user32.dll", CharSet=CharSet.Auto)]
public static extern int MessageBox(HandleRef hWnd, string text, string caption, int type);
[DllImport("user32.dll", CharSet=CharSet.Auto, ExactSpelling=true)]
public static extern IntPtr GetActiveWindow();
internal static IntPtr GetSafeHandle(IWin32Window window)
{
IntPtr zero = IntPtr.Zero;
Control control = window as Control;
if (control != null)
{
return control.Handle;
}
IntSecurity.AllWindows.Demand();
zero = window.Handle;
if (!(zero == IntPtr.Zero) && !UnsafeNativeMethods.IsWindow(new HandleRef(null, zero)))
{
throw new Win32Exception(6);
}
return zero;
}
[DllImport("user32.dll", CharSet=CharSet.Auto, ExactSpelling=true)]
public static extern bool IsWindow(HandleRef hWnd);