1 /** 2 * Implements message box facilities. 3 */ 4 module dguihub.messagebox; 5 6 import std.utf : toUTFz; 7 8 private import dguihub.core.winapi; 9 public import dguihub.core.dialogs.dialogresult; 10 11 /// 12 enum MsgBoxButtons : uint { 13 ok = MB_OK, 14 yesNo = MB_YESNO, 15 okCancel = MB_OKCANCEL, 16 retryCancel = MB_RETRYCANCEL, 17 yesNoCancel = MB_YESNOCANCEL, 18 abortRetryIgnore = MB_ABORTRETRYIGNORE, 19 } 20 21 /// 22 enum MsgBoxIcons : uint { 23 /// 24 none = 0, 25 /** 26 * Icon with an exclamation point 27 */ 28 warning = MB_ICONWARNING, 29 /** 30 * Icon with a lowercase letter i in a circle. 31 */ 32 information = MB_ICONINFORMATION, 33 /** 34 * Icon with a question mark. 35 */ 36 question = MB_ICONQUESTION, 37 error = MB_ICONERROR, ///Icon with a X letter. 38 39 } 40 41 /** 42 * Displays a message window which presents a message to the user. 43 */ 44 final class MsgBox { 45 private this() {} 46 47 /** 48 * Shows a message box. 49 * 50 * Params: 51 * title = The message title 52 * text = The text to display in the message box 53 * button = Specifies which buttons to display in the message box. 54 * icon = Specifies which icon to display in the message box. 55 */ 56 public static DialogResult show(string title, string text, MsgBoxButtons button, MsgBoxIcons icon) { 57 return cast(DialogResult)MessageBoxW(GetActiveWindow(), 58 toUTFz!(wchar*)(text), toUTFz!(wchar*)(title), button | icon); 59 } 60 61 /** 62 * Shows a message box. 63 * 64 * Params: 65 * title = The message title 66 * text = The text to display in the message box 67 * button = Specifies which buttons to display in the message box. 68 */ 69 public static DialogResult show(string title, string text, MsgBoxButtons button) { 70 return MsgBox.show(title, text, button, MsgBoxIcons.none); 71 } 72 73 /** 74 * Shows a message box with OK button. 75 * 76 * Params: 77 * title = The message title 78 * text = The text to display in the message box 79 * icon = Specifies which icon to display in the message box. 80 */ 81 public static DialogResult show(string title, string text, MsgBoxIcons icon) { 82 return MsgBox.show(title, text, MsgBoxButtons.ok, icon); 83 } 84 85 /** 86 * Shows a message box with OK button. 87 * 88 * Params: 89 * title = The message title 90 * text = The text to display in the message box 91 */ 92 public static DialogResult show(string title, string text) { 93 return MsgBox.show(title, text, MsgBoxButtons.ok, MsgBoxIcons.none); 94 } 95 }