Skip to content

Commit

Permalink
Add Windows native message box.
Browse files Browse the repository at this point in the history
  • Loading branch information
bitbound committed Apr 22, 2020
1 parent 3ae0b78 commit b01ac18
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 0 deletions.
47 changes: 47 additions & 0 deletions Shared/Win32/User32.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
}
Expand Down
7 changes: 7 additions & 0 deletions Shared/Win32/Win32Interop.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit b01ac18

Please sign in to comment.