Release 960717
[wine/multimedia.git] / windows / msgbox.c
blobbc739850cb318da8658e32bf9ff5c52a607779a5
1 /*
2 * Message boxes
4 * Copyright 1995 Bernd Schmidt
6 */
8 #include "windows.h"
9 #include "dlgs.h"
10 #include "module.h"
11 #include "win.h"
12 #include "resource.h"
13 #include "task.h"
15 typedef struct {
16 LPCSTR title;
17 LPCSTR text;
18 WORD type;
19 } MSGBOX, *LPMSGBOX;
21 LRESULT SystemMessageBoxProc(HWND hwnd,UINT message,WPARAM wParam,LPARAM lParam)
23 LPMSGBOX lpmb;
24 RECT16 rect, textrect;
25 HWND hItem;
26 HDC hdc;
27 LONG lRet;
28 int i, buttons, bwidth, bheight, theight, wwidth, bpos;
29 int borheight, iheight, tiheight;
31 switch(message) {
32 case WM_INITDIALOG:
33 lpmb = (LPMSGBOX)lParam;
34 if (lpmb->title) SetWindowText32A(hwnd, lpmb->title);
35 SetWindowText32A(GetDlgItem(hwnd, 100), lpmb->text);
36 /* Hide not selected buttons */
37 switch(lpmb->type & MB_TYPEMASK) {
38 case MB_OK:
39 ShowWindow(GetDlgItem(hwnd, 2), SW_HIDE);
40 /* fall through */
41 case MB_OKCANCEL:
42 ShowWindow(GetDlgItem(hwnd, 3), SW_HIDE);
43 ShowWindow(GetDlgItem(hwnd, 4), SW_HIDE);
44 ShowWindow(GetDlgItem(hwnd, 5), SW_HIDE);
45 ShowWindow(GetDlgItem(hwnd, 6), SW_HIDE);
46 ShowWindow(GetDlgItem(hwnd, 7), SW_HIDE);
47 break;
48 case MB_ABORTRETRYIGNORE:
49 ShowWindow(GetDlgItem(hwnd, 1), SW_HIDE);
50 ShowWindow(GetDlgItem(hwnd, 2), SW_HIDE);
51 ShowWindow(GetDlgItem(hwnd, 6), SW_HIDE);
52 ShowWindow(GetDlgItem(hwnd, 7), SW_HIDE);
53 break;
54 case MB_YESNO:
55 ShowWindow(GetDlgItem(hwnd, 2), SW_HIDE);
56 /* fall through */
57 case MB_YESNOCANCEL:
58 ShowWindow(GetDlgItem(hwnd, 1), SW_HIDE);
59 ShowWindow(GetDlgItem(hwnd, 3), SW_HIDE);
60 ShowWindow(GetDlgItem(hwnd, 4), SW_HIDE);
61 ShowWindow(GetDlgItem(hwnd, 5), SW_HIDE);
62 break;
64 /* Set the icon */
65 switch(lpmb->type & MB_ICONMASK) {
66 case MB_ICONEXCLAMATION:
67 SendDlgItemMessage16(hwnd, stc1, STM_SETICON,
68 (WPARAM)LoadIcon16(0, IDI_EXCLAMATION), 0);
69 break;
70 case MB_ICONQUESTION:
71 SendDlgItemMessage16(hwnd, stc1, STM_SETICON,
72 (WPARAM)LoadIcon16(0, IDI_QUESTION), 0);
73 break;
74 case MB_ICONASTERISK:
75 SendDlgItemMessage16(hwnd, stc1, STM_SETICON,
76 (WPARAM)LoadIcon16(0, IDI_ASTERISK), 0);
77 break;
78 case MB_ICONHAND:
79 default:
80 SendDlgItemMessage16(hwnd, stc1, STM_SETICON,
81 (WPARAM)LoadIcon16(0, IDI_HAND), 0);
82 break;
85 /* Position everything */
86 GetWindowRect16(hwnd, &rect);
87 borheight = rect.bottom - rect.top;
88 wwidth = rect.right - rect.left;
89 GetClientRect16(hwnd, &rect);
90 borheight -= rect.bottom - rect.top;
92 /* Get the icon height */
93 GetWindowRect16(GetDlgItem(hwnd, 1088), &rect);
94 iheight = rect.bottom - rect.top;
96 /* Get the number of visible buttons and their width */
97 GetWindowRect16(GetDlgItem(hwnd, 2), &rect);
98 bheight = rect.bottom - rect.top;
99 bwidth = rect.left;
100 GetWindowRect16(GetDlgItem(hwnd, 1), &rect);
101 bwidth -= rect.left;
102 for (buttons = 0, i = 1; i < 8; i++)
104 hItem = GetDlgItem(hwnd, i);
105 if (GetWindowLong32A(hItem, GWL_STYLE) & WS_VISIBLE) buttons++;
108 /* Get the text size */
109 hItem = GetDlgItem(hwnd, 100);
110 GetWindowRect16(hItem, &textrect);
111 MapWindowPoints16(0, hwnd, (LPPOINT16)&textrect, 2);
113 GetClientRect16(hItem, &rect);
114 hdc = GetDC(hItem);
115 lRet = DrawText16( hdc, lpmb->text, -1, &rect,
116 DT_LEFT | DT_EXPANDTABS | DT_WORDBREAK | DT_CALCRECT);
117 theight = rect.bottom - rect.top;
118 tiheight = 16 + MAX(iheight, theight);
119 ReleaseDC(hItem, hdc);
121 /* Position the text */
122 SetWindowPos(hItem, 0, textrect.left, (tiheight - theight) / 2,
123 rect.right - rect.left, theight,
124 SWP_NOZORDER | SWP_NOACTIVATE | SWP_NOREDRAW);
126 /* Position the icon */
127 hItem = GetDlgItem(hwnd, 1088);
128 GetWindowRect16(hItem, &rect);
129 MapWindowPoints16(0, hwnd, (LPPOINT16)&rect, 2);
130 SetWindowPos(hItem, 0, rect.left, (tiheight - iheight) / 2, 0, 0,
131 SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE | SWP_NOREDRAW);
133 /* Resize the window */
134 SetWindowPos(hwnd, 0, 0, 0, wwidth, 8 + tiheight + bheight + borheight,
135 SWP_NOMOVE | SWP_NOZORDER | SWP_NOACTIVATE | SWP_NOREDRAW);
137 /* Position the buttons */
138 bpos = (wwidth - bwidth * buttons) / 2;
139 GetWindowRect16(GetDlgItem(hwnd, 1), &rect);
140 for (buttons = i = 0; i < 7; i++) {
141 /* some arithmetic to get the right order for YesNoCancel windows */
142 hItem = GetDlgItem(hwnd, (i + 5) % 7 + 1);
143 if (GetWindowLong32A(hItem, GWL_STYLE) & WS_VISIBLE) {
144 if (buttons++ == ((lpmb->type & MB_DEFMASK) >> 8)) {
145 SetFocus(hItem);
146 SendMessage32A( hItem, BM_SETSTYLE32, BS_DEFPUSHBUTTON, TRUE );
148 SetWindowPos(hItem, 0, bpos, tiheight, 0, 0,
149 SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE | SWP_NOREDRAW);
150 bpos += bwidth;
153 return 0;
154 break;
156 case WM_COMMAND:
157 switch (wParam) {
158 case IDOK:
159 case IDCANCEL:
160 case IDABORT:
161 case IDRETRY:
162 case IDIGNORE:
163 case IDYES:
164 case IDNO:
165 EndDialog(hwnd, wParam);
166 break;
168 break;
170 return 0;
173 /**************************************************************************
174 * MessageBox [USER.1]
177 int MessageBox(HWND hWnd, LPCSTR text, LPCSTR title, WORD type)
179 HANDLE handle;
180 MSGBOX mbox;
181 int ret;
183 mbox.title = title;
184 mbox.text = text;
185 mbox.type = type;
187 handle = SYSRES_LoadResource( SYSRES_DIALOG_MSGBOX );
188 if (!handle) return 0;
189 ret = DialogBoxIndirectParam16( WIN_GetWindowInstance(hWnd),
190 handle, hWnd,
191 MODULE_GetWndProcEntry16("SystemMessageBoxProc"),
192 (LONG)&mbox );
193 SYSRES_FreeResource( handle );
194 return ret;
197 /**************************************************************************
198 * FatalAppExit [USER.137]
201 void FatalAppExit(UINT fuAction, LPCSTR str)
203 MessageBox(0, str, NULL, MB_SYSTEMMODAL | MB_OK);
204 TASK_KillCurrentTask(0);