public static MessageBoxResult ShowError(object errorObject, string infoMessage = null, string title = null, IntPtr parentHwnd = default(IntPtr), MessageBoxFlags flags = MessageBoxFlags.MB_OK | MessageBoxFlags.MB_ICONERROR | MessageBoxFlags.MB_SYSTEMMODAL) { const string defaultTitle = "Error"; const string defaultInfoMessage = "Oh snap! Something went wrong."; title = title ?? defaultTitle; var ex = errorObject as Exception; if (ex == null) { return(User32Helpers.MessageBox(parentHwnd, infoMessage ?? defaultInfoMessage + $"\n\n{errorObject?.ToString() ?? "No additional information available."}", title, flags)); } var exMessage = ex.Message ?? "No information message available."; string msg; if (infoMessage != null) { msg = infoMessage + "\n\n" + exMessage; } else { msg = defaultInfoMessage + "\n\n" + exMessage; } return(User32Helpers.MessageBox(parentHwnd, $"{msg}" + $"\n\nStackTrace:\n\n{ex.StackTrace}", title, flags)); }
public static void ShowMessageBox(MessageBoxFlags flags, string title, string message) { if (SDL.SDL_ShowSimpleMessageBox((SDL.SDL_MessageBoxFlags)flags, title, message, IntPtr.Zero) != 0) { throw new SDLException(); } }
public static int MessageBoxRect(Rect R, string Msg, MessageBoxFlags AOptions, params object[] Params) { string[] ButtonName = new string[4] { "~Y~es", "~N~o", "O~K~", "Cancel" }; int[] Commands = new int[4] { View.cmYes, View.cmNo, View.cmOk, View.cmCancel }; string[] Titles = new string[4] { "Warning", "Error", "Information", "Confirm" }; int X, ButtonCount; Dialog Dialog; View Control; View[] ButtonList = new View[4]; string S; Dialog = new Dialog(R, Titles[(int)AOptions & 0x03]); R = new Rect(3, 2, Dialog.Size.X - 2, Dialog.Size.Y - 3); S = string.Format(Msg, Params); Control = new StaticText(R, S); Dialog.Insert(Control); X = -2; ButtonCount = 0; for (int i = 0; i < 4; i++) { if (((int)AOptions & (0x0100 << i)) != 0) { R = new Rect(0, 0, 12, 2); Control = new Button(R, ButtonName[i], Commands[i], Button.ButtonFlags.Normal); X += Control.Size.X + 2; ButtonList[ButtonCount] = Control; ButtonCount++; } } X = (Dialog.Size.X - X) >> 1; for (int i = 0; i < ButtonCount; i++) { Control = ButtonList[i]; Dialog.Insert(Control); Control.MoveTo(X, Dialog.Size.Y - 3); X += Control.Size.X + 2; } Dialog.SelectNext(false); if ((AOptions & MessageBoxFlags.mfCentered) != 0) { Dialog.Options |= View.OptionFlags.ofCentered; } if ((AOptions & MessageBoxFlags.mfInsertInApp) == 0) { return(Program.Desktop.ExecView(Dialog)); } else { return(Program.Application.ExecView(Dialog)); } }
public static MessageBoxResult Show(string message, string title = null, IntPtr parentHwnd = default(IntPtr), MessageBoxFlags flags = MessageBoxFlags.MB_OK | MessageBoxFlags.MB_ICONINFORMATION) { const string defaultTitle = "Information"; title = title ?? defaultTitle; return(User32Helpers.MessageBox(parentHwnd, message, title, flags)); }
public static int MessageBox(string Msg, MessageBoxFlags AOptions, params object[] Params) { Rect R = new Rect(0, 0, 40, 12); if ((AOptions & MessageBoxFlags.mfInsertInApp) == 0) { R.Move((Program.Desktop.Size.X - R.B.X) / 2, (Program.Desktop.Size.Y - R.B.Y) / 2); } else { R.Move((Program.Application.Size.X - R.B.X) / 2, (Program.Application.Size.Y - R.B.Y) / 2); } return(MessageBoxRect(R, Msg, AOptions, Params)); }
private static unsafe void Show(MessageBoxFlags flags, string title, string message, Window?parent) { Span <byte> tbuf = stackalloc byte[SL(title)]; Span <byte> msgbuf = stackalloc byte[SL(message)]; StringToUTF8(title, tbuf); StringToUTF8(message, msgbuf); fixed(byte *t = &MemoryMarshal.GetReference(tbuf)) fixed(byte *msg = &MemoryMarshal.GetReference(msgbuf)) { if (parent == null) { ErrorIfNegative(SDL_ShowSimpleMessageBox((uint)flags, t, msg, IntPtr.Zero)); } else { ErrorIfNegative(SDL_ShowSimpleMessageBox((uint)flags, t, msg, parent)); } } }
/// <summary> /// shows a message box /// </summary> /// <param name="flags">type of message box</param> /// <param name="title">title for the message box</param> /// <param name="message">body of the message box</param> /// <param name="shouldPause">should the game engine wait for message box to be closed?</param> public static unsafe void ShowMessageBox( MessageBoxFlags flags, string title, string message, bool shouldPause = false ) { var t1 = Task.Run(() => { SDL2Native.SDL_ShowSimpleMessageBox( (uint)flags, title, message ); }); if (shouldPause) { t1.Wait(); } }
/// <summary> /// shows a message box that is parented to this window /// </summary> /// <param name="flags">type of message box</param> /// <param name="title">title for the message box</param> /// <param name="message">body of the message box</param> /// <param name="shouldPause">should the game engine wait for message box to be closed?</param> public unsafe void ShowParentedMessageBox( MessageBoxFlags flags, string title, string message, bool shouldPause = false ) { var t1 = Task.Run(() => { SDL2Native.SDL_ShowSimpleMessageBox( (uint)flags, title, message, (SDL_Window *)_nativeWindow.Handle.NativePointer ); }); if (shouldPause) { t1.Wait(); } }
public static int ShowMessageBoxEx(MessageBoxFlags flags, string title, string message, string[] buttons, SDLWindow window = null, int btnEnter = -1, int btnEscape = -1) { SDL.SDL_MessageBoxData data = new SDL.SDL_MessageBoxData(); data.title = title; data.message = message; if (window != null) { data.window = window.GetPointer(); } else { data.window = IntPtr.Zero; } data.numbuttons = buttons.Length; data.flags = (SDL.SDL_MessageBoxFlags)flags; SDL.SDL_MessageBoxButtonData[] buttonStructs = new SDL.SDL_MessageBoxButtonData[buttons.Length]; for (var i = 0; i < buttons.Length; i++) { buttonStructs[i].buttonid = i; buttonStructs[i].text = buttons[i]; if (i == btnEnter) { buttonStructs[i].flags = SDL.SDL_MessageBoxButtonFlags.SDL_MESSAGEBOX_BUTTON_RETURNKEY_DEFAULT; } else if (i == btnEscape) { buttonStructs[i].flags = SDL.SDL_MessageBoxButtonFlags.SDL_MESSAGEBOX_BUTTON_ESCAPEKEY_DEFAULT; } } data.buttons = buttonStructs; if (SDL.SDL_ShowMessageBox(ref data, out int btnClicked) != 0) { throw new SDLException(); } return(btnClicked); }
public static int MessageBox(string Msg, MessageBoxFlags AOptions) { return(MessageBox(Msg, AOptions, new object[0])); }
internal static extern int MessageBox(System.IntPtr hWnd, string lpText, string lpCaption, [MarshalAs(UnmanagedType.U4)] MessageBoxFlags uType);
private static unsafe int Show( MessageBoxFlags flags, string title, string message, IEnumerable <MessageBoxButton> buttons, MessageBoxColors?colorScheme = null, Window?parent = null ) { int clicked; Span <byte> tbuf = stackalloc byte[SL(title)]; Span <byte> msgbuf = stackalloc byte[SL(message)]; StringToUTF8(title, tbuf); StringToUTF8(message, msgbuf); fixed(byte *t = tbuf) fixed(byte *msg = msgbuf) { Span <SDL_MessageBoxButtonData> btns = new SDL_MessageBoxButtonData[16]; SDL_MessageBoxData data; data.flags = (uint)flags; data.window = IntPtr.Zero; data.title = t; data.message = msg; data.numbuttons = 0; data.buttons = null; data.colorScheme = null; try { SDL_MessageBoxColorScheme scheme; if (colorScheme != null) { scheme = MarshalColors(colorScheme); data.colorScheme = &scheme; } if (parent != null) { bool ok = false; parent.DangerousAddRef(ref ok); if (ok) { data.window = parent.DangerousGetHandle(); } } data.numbuttons = MarshalButtons(buttons, btns); fixed(SDL_MessageBoxButtonData *bptr = &MemoryMarshal.GetReference(btns)) { data.buttons = bptr; ErrorIfNegative(SDL_ShowMessageBox(data, out clicked)); } } finally { if (parent != null && data.window != IntPtr.Zero) { parent.DangerousRelease(); } if (data.numbuttons > 0) { for (var i = 0; i < data.numbuttons; ++i) { Marshal.FreeHGlobal((IntPtr)btns[i].text); } } } } return(clicked); }
public static MessageBoxResult MessageBox(string message, string title = "Info", MessageBoxFlags flags = MessageBoxFlags.MB_OK, IntPtr parent = default(IntPtr)) { return(MessageBox(parent, message, title, flags)); }
public static MessageBoxResult MessageBox(IntPtr hWnd, string lpText, string lpCaption, MessageBoxFlags type) { return(User32Methods.MessageBox(hWnd, lpText, lpCaption, (uint)type)); }
public static MessageBoxButton Show(string text, string caption, MessageBoxFlags flags, IWin32Window parent = null) { IntPtr parentHandle = parent?.Handle ?? IntPtr.Zero; return((MessageBoxButton)NativeMessageBox(parentHandle, text, caption, (uint)flags)); }
public static int Show(MessageBoxFlags flags, string title, string message) { return(SDL_ShowSimpleMessageBox((uint)flags, title, message, new IntPtr(0))); }