From b01ac18771a8eb8a23e6845afffc70abdd6d72ee Mon Sep 17 00:00:00 2001 From: Jared Goodwin Date: Wed, 22 Apr 2020 08:58:05 -0700 Subject: [PATCH] Add Windows native message box. --- Shared/Win32/User32.cs | 47 ++++++++++++++++++++++++++++++++++++ Shared/Win32/Win32Interop.cs | 7 ++++++ 2 files changed, 54 insertions(+) diff --git a/Shared/Win32/User32.cs b/Shared/Win32/User32.cs index df23acd9a..90e3ab32d 100644 --- a/Shared/Win32/User32.cs +++ b/Shared/Win32/User32.cs @@ -1000,6 +1000,51 @@ public enum InputType : uint KEYBOARD = 1, HARDWARE = 2 } + public enum MessageBoxType : long + { + MB_ABORTRETRYIGNORE = 0x00000002L, + MB_CANCELTRYCONTINUE = 0x00000006L, + MB_HELP = 0x00004000L, + MB_OK = 0x00000000L, + MB_OKCANCEL = 0x00000001L, + MB_RETRYCANCEL = 0x00000005L, + MB_YESNO = 0x00000004L, + MB_YESNOCANCEL = 0x00000003L, + MB_ICONEXCLAMATION = 0x00000030L, + MB_ICONWARNING = 0x00000030L, + MB_ICONINFORMATION = 0x00000040L, + MB_ICONASTERISK = 0x00000040L, + MB_ICONQUESTION = 0x00000020L, + MB_ICONSTOP = 0x00000010L, + MB_ICONERROR = 0x00000010L, + MB_ICONHAND = 0x00000010L, + MB_DEFBUTTON1 = 0x00000000L, + MB_DEFBUTTON2 = 0x00000100L, + MB_DEFBUTTON3 = 0x00000200L, + MB_DEFBUTTON4 = 0x00000300L, + MB_APPLMODAL = 0x00000000L, + MB_SYSTEMMODAL = 0x00001000L, + MB_TASKMODAL = 0x00002000L, + MB_DEFAULT_DESKTOP_ONLY = 0x00020000L, + MB_RIGHT = 0x00080000L, + MB_RTLREADING = 0x00100000L, + MB_SETFOREGROUND = 0x00010000L, + MB_TOPMOST = 0x00040000L, + MB_SERVICE_NOTIFICATION = 0x00200000L + } + + public enum MessageBoxResult : int + { + IDABORT = 3, + IDCANCEL = 2, + IDCONTINUE = 11, + IDIGNORE = 5, + IDNO = 7, + IDOK = 1, + IDRETRY = 4, + IDTRYAGAIN = 10, + IDYES = 6, + } #endregion #region Structs @@ -1249,6 +1294,8 @@ public static extern int SystemParametersInfo( [return: MarshalAs(UnmanagedType.Bool)] public static extern bool BlockInput([MarshalAs(UnmanagedType.Bool)] bool fBlockIt); + [DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Auto)] + public static extern int MessageBox(IntPtr hWnd, string text, string caption, long type); #endregion } diff --git a/Shared/Win32/Win32Interop.cs b/Shared/Win32/Win32Interop.cs index 66fc87383..2c8984a07 100644 --- a/Shared/Win32/Win32Interop.cs +++ b/Shared/Win32/Win32Interop.cs @@ -177,6 +177,13 @@ public static void SetMonitorState(MonitorState state) SendMessage(0xFFFF, 0x112, 0xF170, (int)state); } + public static MessageBoxResult ShowMessageBox(IntPtr owner, + string message, + string caption, + MessageBoxType messageBoxType) + { + return (MessageBoxResult)MessageBox(owner, message, caption, (long)messageBoxType); + } public static bool SwitchToInputDesktop() { var inputDesktop = OpenInputDesktop();