Release 950620
[wine/multimedia.git] / windows / msgbox.c
blobc064f6d84e08324ccbcc5fc195f8d253c620cff2
1 /*
2 * Message boxes
4 * Copyright 1995 Bernd Schmidt
6 */
8 #include "windows.h"
9 #include "dlgs.h"
10 #include "dialog.h"
11 #include "selectors.h"
12 #include "../rc/sysres.h"
13 #include "task.h"
15 typedef struct {
16 LPSTR title;
17 LPSTR text;
18 WORD type;
19 } MSGBOX, *LPMSGBOX;
21 LONG SystemMessageBoxProc(HWND hwnd, WORD message, WORD wParam, LONG lParam)
23 LPMSGBOX lpmb;
24 RECT 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 != NULL) {
35 SetWindowText(hwnd, lpmb->title);
37 SetWindowText(GetDlgItem(hwnd, 100), lpmb->text);
38 /* Hide not selected buttons */
39 switch(lpmb->type & MB_TYPEMASK) {
40 case MB_OK:
41 ShowWindow(GetDlgItem(hwnd, 2), SW_HIDE);
42 /* fall through */
43 case MB_OKCANCEL:
44 ShowWindow(GetDlgItem(hwnd, 3), SW_HIDE);
45 ShowWindow(GetDlgItem(hwnd, 4), SW_HIDE);
46 ShowWindow(GetDlgItem(hwnd, 5), SW_HIDE);
47 ShowWindow(GetDlgItem(hwnd, 6), SW_HIDE);
48 ShowWindow(GetDlgItem(hwnd, 7), SW_HIDE);
49 break;
50 case MB_ABORTRETRYIGNORE:
51 ShowWindow(GetDlgItem(hwnd, 1), SW_HIDE);
52 ShowWindow(GetDlgItem(hwnd, 2), SW_HIDE);
53 ShowWindow(GetDlgItem(hwnd, 6), SW_HIDE);
54 ShowWindow(GetDlgItem(hwnd, 7), SW_HIDE);
55 break;
56 case MB_YESNO:
57 ShowWindow(GetDlgItem(hwnd, 2), SW_HIDE);
58 /* fall through */
59 case MB_YESNOCANCEL:
60 ShowWindow(GetDlgItem(hwnd, 1), SW_HIDE);
61 ShowWindow(GetDlgItem(hwnd, 3), SW_HIDE);
62 ShowWindow(GetDlgItem(hwnd, 4), SW_HIDE);
63 ShowWindow(GetDlgItem(hwnd, 5), SW_HIDE);
64 break;
66 /* Set the icon */
67 switch(lpmb->type & MB_ICONMASK) {
68 case MB_ICONEXCLAMATION:
69 SendDlgItemMessage(hwnd, stc1, STM_SETICON, LoadIcon(0, IDI_EXCLAMATION), 0);
70 break;
71 case MB_ICONQUESTION:
72 SendDlgItemMessage(hwnd, stc1, STM_SETICON, LoadIcon(0, IDI_QUESTION), 0);
73 break;
74 case MB_ICONASTERISK:
75 SendDlgItemMessage(hwnd, stc1, STM_SETICON, LoadIcon(0, IDI_ASTERISK), 0);
76 break;
77 case MB_ICONHAND:
78 default:
79 SendDlgItemMessage(hwnd, stc1, STM_SETICON, LoadIcon(0, IDI_HAND), 0);
80 break;
83 /* Position everything */
84 GetWindowRect(hwnd, &rect);
85 borheight = rect.bottom - rect.top;
86 wwidth = rect.right - rect.left;
87 GetClientRect(hwnd, &rect);
88 borheight -= rect.bottom - rect.top;
90 /* Get the icon height */
91 GetWindowRect(GetDlgItem(hwnd, 1088), &rect);
92 iheight = rect.bottom - rect.top;
94 /* Get the number of visible buttons and their width */
95 GetWindowRect(GetDlgItem(hwnd, 2), &rect);
96 bheight = rect.bottom - rect.top;
97 bwidth = rect.left;
98 GetWindowRect(GetDlgItem(hwnd, 1), &rect);
99 bwidth -= rect.left;
100 for (buttons = 0, i = 1; i < 8; i++) {
101 hItem = GetDlgItem(hwnd, i);
102 if (GetWindowLong(hItem, GWL_STYLE) & WS_VISIBLE) {
103 buttons++;
107 /* Get the text size */
108 hItem = GetDlgItem(hwnd, 100);
109 GetWindowRect(hItem, &textrect);
110 MapWindowPoints(0, hwnd, (LPPOINT)&textrect, 2);
112 GetClientRect(hItem, &rect);
113 hdc = GetDC(hItem);
114 lRet = DrawText(hdc, lpmb->text, -1, &rect,
115 DT_LEFT | DT_EXPANDTABS | DT_WORDBREAK | DT_CALCRECT);
116 theight = rect.bottom - rect.top;
117 tiheight = 16 + max(iheight, theight);
118 ReleaseDC(hItem, hdc);
120 /* Position the text */
121 SetWindowPos(hItem, 0, textrect.left, (tiheight - theight) / 2,
122 rect.right - rect.left, theight,
123 SWP_NOZORDER | SWP_NOACTIVATE | SWP_NOREDRAW);
125 /* Position the icon */
126 hItem = GetDlgItem(hwnd, 1088);
127 GetWindowRect(hItem, &rect);
128 MapWindowPoints(0, hwnd, (LPPOINT)&rect, 2);
129 SetWindowPos(hItem, 0, rect.left, (tiheight - iheight) / 2, 0, 0,
130 SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE | SWP_NOREDRAW);
132 /* Resize the window */
133 SetWindowPos(hwnd, 0, 0, 0, wwidth, 8 + tiheight + bheight + borheight,
134 SWP_NOMOVE | SWP_NOZORDER | SWP_NOACTIVATE | SWP_NOREDRAW);
136 /* Position the buttons */
137 bpos = (wwidth - bwidth * buttons) / 2;
138 GetWindowRect(GetDlgItem(hwnd, 1), &rect);
139 for (buttons = i = 0; i < 7; i++) {
140 /* some arithmetic to get the right order for YesNoCancel windows */
141 hItem = GetDlgItem(hwnd, (i + 5) % 7 + 1);
142 if (GetWindowLong(hItem, GWL_STYLE) & WS_VISIBLE) {
143 if (buttons++ == ((lpmb->type & MB_DEFMASK) >> 8)) {
144 SetFocus(hItem);
145 SendMessage(hItem, BM_SETSTYLE, BS_DEFPUSHBUTTON, TRUE);
147 SetWindowPos(hItem, 0, bpos, tiheight, 0, 0,
148 SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE | SWP_NOREDRAW);
149 bpos += bwidth;
152 return 0;
153 break;
155 case WM_COMMAND:
156 switch (wParam) {
157 case IDOK:
158 case IDCANCEL:
159 case IDABORT:
160 case IDRETRY:
161 case IDIGNORE:
162 case IDYES:
163 case IDNO:
164 EndDialog(hwnd, wParam);
165 break;
167 break;
169 return 0;
172 /**************************************************************************
173 * MessageBox [USER.1]
176 int MessageBox(HWND hWnd, LPSTR text, LPSTR title, WORD type)
178 MSGBOX mbox;
180 mbox.title = title;
181 mbox.text = text;
182 mbox.type = type;
183 return DialogBoxIndirectParamPtr(GetWindowWord(hWnd, GWW_HINSTANCE),
184 sysres_DIALOG_MSGBOX, hWnd,
185 GetWndProcEntry16("SystemMessageBoxProc"),
186 (LONG)&mbox);
189 /**************************************************************************
190 * FatalAppExit [USER.137]
193 void FatalAppExit(WORD wAction, LPSTR str)
195 MessageBox(0, str, NULL, MB_SYSTEMMODAL | MB_OK);
196 TASK_KillCurrentTask(0);