Name | Executed | Routines | % | Executed | Lines | % | Unexecuted |
/home/matt/eu/rds/include/std/win32/msgbox.e | 0 | 1 | 0.00% | 0 | 53 | 0.00% | 53 |
Routine | Executed | Lines | Unexecuted | |
message_box() | 0 | 18 | 0.00% | 18 |
# | Executed | |
1 | -- (c) Copyright - See License.txt | |
2 | -- | |
3 | --**** | |
4 | -- == Windows Message Box | |
5 | -- | |
6 | -- < | |
7 | -- | |
8 | namespace msgbox | |
9 | ||
10 | include std/dll.e | |
11 | include std/machine.e | |
12 | ||
13 | without warning | |
14 | ||
15 | --**** | |
16 | -- === Style Constants | |
17 | -- | |
18 | -- Possible style values for message_box() style sequence | |
19 | -- | |
20 | ||
21 | public constant | |
22 | --** Abort, Retry, Ignore | |
23 | 0 | MB_ABORTRETRYIGNORE = #02, |
24 | --** User must respond before doing something else | |
25 | 0 | MB_APPLMODAL = #00, |
26 | 0 | MB_DEFAULT_DESKTOP_ONLY = #20000, |
27 | --** First button is default button | |
28 | 0 | MB_DEFBUTTON1 = #00, |
29 | --** Second button is default button | |
30 | 0 | MB_DEFBUTTON2 = #100, |
31 | --** Third button is default button | |
32 | 0 | MB_DEFBUTTON3 = #200, |
33 | --** Fourth button is default button | |
34 | 0 | MB_DEFBUTTON4 = #300, |
35 | --** Windows 95: Help button generates help event | |
36 | 0 | MB_HELP = #4000, |
37 | 0 | MB_ICONASTERISK = #40, |
38 | 0 | MB_ICONERROR = #10, |
39 | --** Exclamation-point appears in the box | |
40 | 0 | MB_ICONEXCLAMATION = #30, |
41 | --** A hand appears | |
42 | 0 | MB_ICONHAND = MB_ICONERROR, |
43 | --** Lowercase letter i in a circle appears | |
44 | 0 | MB_ICONINFORMATION = MB_ICONASTERISK, |
45 | --** A question-mark icon appears | |
46 | 0 | MB_ICONQUESTION = #20, |
47 | 0 | MB_ICONSTOP = MB_ICONHAND, |
48 | 0 | MB_ICONWARNING = MB_ICONEXCLAMATION, |
49 | --** Message box contains one push button: OK | |
50 | 0 | MB_OK = #00, |
51 | --** Message box contains OK and Cancel | |
52 | 0 | MB_OKCANCEL = #01, |
53 | --** Message box contains Retry and Cancel | |
54 | 0 | MB_RETRYCANCEL = #05, |
55 | --** Windows 95: The text is right-justified | |
56 | 0 | MB_RIGHT = #80000, |
57 | --** Windows 95: For Hebrew and Arabic systems | |
58 | 0 | MB_RTLREADING = #100000, |
59 | --** Windows NT: The caller is a service | |
60 | 0 | MB_SERVICE_NOTIFICATION = #40000, |
61 | --** Message box becomes the foreground window | |
62 | 0 | MB_SETFOREGROUND = #10000, |
63 | --** All applications suspended until user responds | |
64 | 0 | MB_SYSTEMMODAL = #1000, |
65 | --** Similar to MB_APPLMODAL | |
66 | 0 | MB_TASKMODAL = #2000, |
67 | --** Message box contains Yes and No | |
68 | 0 | MB_YESNO = #04, |
69 | --** Message box contains Yes, No, and Cancel | |
70 | 0 | MB_YESNOCANCEL = #03 |
71 | ||
72 | --**** | |
73 | -- === Return Value Constants | |
74 | -- | |
75 | -- possible values returned by MessageBox(). 0 means failure | |
76 | ||
77 | public constant | |
78 | --** Abort button was selected. | |
79 | 0 | IDABORT = 3, |
80 | --** Cancel button was selected. | |
81 | 0 | IDCANCEL = 2, |
82 | --** Ignore button was selected. | |
83 | 0 | IDIGNORE = 5, |
84 | --** No button was selected. | |
85 | 0 | IDNO = 7, |
86 | --** OK button was selected. | |
87 | 0 | IDOK = 1, |
88 | --** Retry button was selected. | |
89 | 0 | IDRETRY = 4, |
90 | --** Yes button was selected. | |
91 | 0 | IDYES = 6 |
92 | ||
93 | atom lib | |
94 | integer msgbox_id, get_active_id | |
95 | ||
96 | 0 | ifdef WIN32 then |
97 | lib = open_dll("user32.dll") | |
98 | msgbox_id = define_c_func(lib, "MessageBoxA", {C_UINT, C_POINTER, | |
99 | C_POINTER, C_UINT}, C_INT) | |
100 | if msgbox_id = -1 then | |
101 | puts(2, "couldn't find MessageBoxA\n") | |
102 | abort(1) | |
103 | end if | |
104 | ||
105 | get_active_id = define_c_func(lib, "GetActiveWindow", {}, C_UINT) | |
106 | if get_active_id = -1 then | |
107 | puts(2, "couldn't find GetActiveWindow\n") | |
108 | abort(1) | |
109 | end if | |
110 | end ifdef | |
111 | ||
112 | --**** | |
113 | -- === Routines | |
114 | -- | |
115 | ||
116 | --** | |
117 | -- Displays a window with a title, message, buttons and an icon, usually known as a message box. | |
118 | -- | |
119 | -- Parameters: | |
120 | -- # ##text##: a sequence, the message to be displayed | |
121 | -- # ##title##: a sequence, the title the box should have | |
122 | -- # ##style##: an object which defines which,icon should be displayed, if any, and which buttons will be presented. | |
123 | -- | |
124 | -- Returns: | |
125 | -- An **integer**, the button which was clicked to close the message box, or 0 on failure. | |
126 | -- | |
127 | -- Comments: | |
128 | -- See [[:Style Constants]] above for a complete list of possible values for ##style## and | |
129 | -- [[:Return Value Constants]] for the returned value. If ##style## is a sequence, its elements will be | |
130 | -- or'ed together. | |
131 | ||
132 | 0 | |
133 | integer or_style | |
134 | atom text_ptr, title_ptr, ret | |
135 | ||
136 | 0 | text_ptr = allocate_string(text) |
137 | 0 | if not text_ptr then |
138 | 0 | return 0 |
139 | end if | |
140 | 0 | title_ptr = allocate_string(title) |
141 | 0 | if not title_ptr then |
142 | 0 | free(text_ptr) |
143 | 0 | return 0 |
144 | end if | |
145 | 0 | if atom(style) then |
146 | 0 | or_style = style |
147 | else | |
148 | 0 | or_style = 0 |
149 | 0 | for i = 1 to length(style) do |
150 | 0 | or_style = or_bits(or_style, style[i]) |
151 | 0 | end for |
152 | end if | |
153 | 0 | ret = c_func(msgbox_id, {c_func(get_active_id, {}), |
154 | text_ptr, title_ptr, or_style}) | |
155 | 0 | free(text_ptr) |
156 | 0 | free(title_ptr) |
157 | ||
158 | 0 | return ret |
159 | end function | |
160 |