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 = 0x00000002u,
14 MB_CANCELTRYCONTINUE = 0x00000006u,
15 MB_HELP = 0x00004000u,
16 MB_OK = 0x00000000u,
17 MB_OKCANCEL = 0x00000001u,
18 MB_RETRYCANCEL = 0x00000005u,
19 MB_YESNO = 0x00000004u,
20 MB_YESNOCANCEL = 0x00000003u,
21 MB_ICONEXCLAMATION = 0x00000030u,
22 MB_ICONWARNING = 0x00000030u,
23 MB_ICONINFORMATION = 0x00000040u,
24 MB_ICONASTERISK = 0x00000040u,
25 MB_ICONQUESTION = 0x00000020u,
26 MB_ICONSTOP = 0x00000010u,
27 MB_ICONERROR = 0x00000010u,
28 MB_ICONHAND = 0x00000010u
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 void Show(const string& message)
47 {
48 int result = WinShowMessageBox(message.Chars(), null);
49 if (result == 0)
50 {
51 throw WindowsAPIException(WinGetLastError());
52 }
53 }
54 public static void Show(const string& message, const string& caption)
55 {
56 int result = WinShowMessageBox(message.Chars(), caption.Chars());
57 if (result == 0)
58 {
59 throw WindowsAPIException(WinGetLastError());
60 }
61 }
62 public static MessageBoxResult Show(const string& message, const string& caption, Control* owner, MessageBoxType type)
63 {
64 void* ownerWindowHandle = null;
65 if (owner != null)
66 {
67 ownerWindowHandle = owner->Handle();
68 }
69 int result = WinShowMessageBoxWithType(message.Chars(), caption.Chars(), ownerWindowHandle, type);
70 if (result == 0)
71 {
72 throw WindowsAPIException(WinGetLastError());
73 }
74 else
75 {
76 return cast<MessageBoxResult>(result);
77 }
78 }
79 }
80 }