1
2
3
4
5
6 using System;
7 using System.Windows.API;
8
9 namespace System.Windows
10 {
11 public enum MessageBoxType : uint
12 {
13 MB_ABORTRETRYIGNORE = 2u,
14 MB_CANCELTRYCONTINUE = 6u,
15 MB_HELP = 16384u,
16 MB_OK = 0u,
17 MB_OKCANCEL = 1u,
18 MB_RETRYCANCEL = 5u,
19 MB_YESNO = 4u,
20 MB_YESNOCANCEL = 3u,
21 MB_ICONEXCLAMATION = 48u,
22 MB_ICONWARNING = 48u,
23 MB_ICONINFORMATION = 64u,
24 MB_ICONASTERISK = 64u,
25 MB_ICONQUESTION = 32u,
26 MB_ICONSTOP = 16u,
27 MB_ICONERROR = 16u,
28 MB_ICONHAND = 16u
29 }
30
31 public enum MessageBoxResult : int
32 {
33 ok = 1,
34 cancel = 2,
35 abort = 3,
36 retry = 4,
37 ignore = 5,
38 yes = 6,
39 no = 7,
40 tryAgain = 10,
41 continue_ = 11
42 }
43
44 public static class MessageBox
45 {
46 public static Result<bool> Show(const string& message)
47 {
48 int result = WinShowMessageBox(message.Chars(), null);
49 if (result == 0)
50 {
51 int errorId = WinAllocateWindowsError("MessageBox.Show failed", WinGetLastError());
52 return Result<bool>(ErrorId(errorId));
53 }
54 return Result<bool>(true);
55 }
56 public static Result<bool> Show(const string& message, const string& caption)
57 {
58 int result = WinShowMessageBox(message.Chars(), caption.Chars());
59 if (result == 0)
60 {
61 int errorId = WinAllocateWindowsError("MessageBox.Show failed", WinGetLastError());
62 return Result<bool>(ErrorId(errorId));
63 }
64 return Result<bool>(true);
65 }
66 public static Result<MessageBoxResult> Show(const string& message, const string& caption, Control* owner, MessageBoxType type)
67 {
68 void* ownerWindowHandle = null;
69 if (owner != null)
70 {
71 ownerWindowHandle = owner->Handle();
72 }
73 int result = WinShowMessageBoxWithType(message.Chars(), caption.Chars(), ownerWindowHandle, type);
74 if (result == 0)
75 {
76 int errorId = WinAllocateWindowsError("MessageBox.Show failed", WinGetLastError());
77 return Result<MessageBoxResult>(ErrorId(errorId));
78 }
79 else
80 {
81 return Result<MessageBoxResult>(cast<MessageBoxResult>(result));
82 }
83 }
84 }