4 * Copyright 1995 Bernd Schmidt
18 /**************************************************************************
21 * Dialog procedure for message boxes.
23 static LRESULT CALLBACK
MSGBOX_DlgProc( HWND32 hwnd
, UINT32 message
,
24 WPARAM32 wParam
, LPARAM lParam
)
26 LPMSGBOXPARAMS32A lpmb
;
28 RECT32 rect
, textrect
;
32 int i
, buttons
, bwidth
, bheight
, theight
, wwidth
, bpos
;
33 int borheight
, iheight
, tiheight
;
37 lpmb
= (LPMSGBOXPARAMS32A
)lParam
;
38 if (lpmb
->lpszCaption
) SetWindowText32A(hwnd
, lpmb
->lpszCaption
);
39 SetWindowText32A(GetDlgItem32(hwnd
, 100), lpmb
->lpszText
);
40 /* Hide not selected buttons */
41 switch(lpmb
->dwStyle
& MB_TYPEMASK
) {
43 ShowWindow32(GetDlgItem32(hwnd
, 2), SW_HIDE
);
46 ShowWindow32(GetDlgItem32(hwnd
, 3), SW_HIDE
);
47 ShowWindow32(GetDlgItem32(hwnd
, 4), SW_HIDE
);
48 ShowWindow32(GetDlgItem32(hwnd
, 5), SW_HIDE
);
49 ShowWindow32(GetDlgItem32(hwnd
, 6), SW_HIDE
);
50 ShowWindow32(GetDlgItem32(hwnd
, 7), SW_HIDE
);
52 case MB_ABORTRETRYIGNORE
:
53 ShowWindow32(GetDlgItem32(hwnd
, 1), SW_HIDE
);
54 ShowWindow32(GetDlgItem32(hwnd
, 2), SW_HIDE
);
55 ShowWindow32(GetDlgItem32(hwnd
, 6), SW_HIDE
);
56 ShowWindow32(GetDlgItem32(hwnd
, 7), SW_HIDE
);
59 ShowWindow32(GetDlgItem32(hwnd
, 2), SW_HIDE
);
62 ShowWindow32(GetDlgItem32(hwnd
, 1), SW_HIDE
);
63 ShowWindow32(GetDlgItem32(hwnd
, 3), SW_HIDE
);
64 ShowWindow32(GetDlgItem32(hwnd
, 4), SW_HIDE
);
65 ShowWindow32(GetDlgItem32(hwnd
, 5), SW_HIDE
);
69 switch(lpmb
->dwStyle
& MB_ICONMASK
) {
70 case MB_ICONEXCLAMATION
:
71 SendDlgItemMessage16(hwnd
, stc1
, STM_SETICON16
,
72 (WPARAM16
)LoadIcon16(0, IDI_EXCLAMATION16
), 0);
75 SendDlgItemMessage16(hwnd
, stc1
, STM_SETICON16
,
76 (WPARAM16
)LoadIcon16(0, IDI_QUESTION16
), 0);
79 SendDlgItemMessage16(hwnd
, stc1
, STM_SETICON16
,
80 (WPARAM16
)LoadIcon16(0, IDI_ASTERISK16
), 0);
84 SendDlgItemMessage16(hwnd
, stc1
, STM_SETICON16
,
85 (WPARAM16
)LoadIcon16(0, IDI_HAND16
), 0);
89 /* Position everything */
90 GetWindowRect32(hwnd
, &rect
);
91 borheight
= rect
.bottom
- rect
.top
;
92 wwidth
= rect
.right
- rect
.left
;
93 GetClientRect32(hwnd
, &rect
);
94 borheight
-= rect
.bottom
- rect
.top
;
96 /* Get the icon height */
97 GetWindowRect32(GetDlgItem32(hwnd
, 1088), &rect
);
98 iheight
= rect
.bottom
- rect
.top
;
100 /* Get the number of visible buttons and their width */
101 GetWindowRect32(GetDlgItem32(hwnd
, 2), &rect
);
102 bheight
= rect
.bottom
- rect
.top
;
104 GetWindowRect32(GetDlgItem32(hwnd
, 1), &rect
);
106 for (buttons
= 0, i
= 1; i
< 8; i
++)
108 hItem
= GetDlgItem32(hwnd
, i
);
109 if (GetWindowLong32A(hItem
, GWL_STYLE
) & WS_VISIBLE
) buttons
++;
112 /* Get the text size */
113 hItem
= GetDlgItem32(hwnd
, 100);
114 GetWindowRect32(hItem
, &textrect
);
115 MapWindowPoints32(0, hwnd
, (LPPOINT32
)&textrect
, 2);
117 GetClientRect32(hItem
, &rect
);
118 hdc
= GetDC32(hItem
);
119 lRet
= DrawText32A( hdc
, lpmb
->lpszText
, -1, &rect
,
120 DT_LEFT
| DT_EXPANDTABS
| DT_WORDBREAK
| DT_CALCRECT
);
121 theight
= rect
.bottom
- rect
.top
;
122 tiheight
= 16 + MAX(iheight
, theight
);
123 ReleaseDC32(hItem
, hdc
);
125 /* Position the text */
126 SetWindowPos32(hItem
, 0, textrect
.left
, (tiheight
- theight
) / 2,
127 rect
.right
- rect
.left
, theight
,
128 SWP_NOZORDER
| SWP_NOACTIVATE
| SWP_NOREDRAW
);
130 /* Position the icon */
131 hItem
= GetDlgItem32(hwnd
, 1088);
132 GetWindowRect32(hItem
, &rect
);
133 MapWindowPoints32(0, hwnd
, (LPPOINT32
)&rect
, 2);
134 SetWindowPos32(hItem
, 0, rect
.left
, (tiheight
- iheight
) / 2, 0, 0,
135 SWP_NOSIZE
| SWP_NOZORDER
| SWP_NOACTIVATE
| SWP_NOREDRAW
);
137 /* Resize the window */
138 SetWindowPos32(hwnd
, 0, 0, 0, wwidth
, 8 + tiheight
+ bheight
+ borheight
,
139 SWP_NOMOVE
| SWP_NOZORDER
| SWP_NOACTIVATE
| SWP_NOREDRAW
);
141 /* Position the buttons */
142 bpos
= (wwidth
- bwidth
* buttons
) / 2;
143 GetWindowRect32(GetDlgItem32(hwnd
, 1), &rect
);
144 for (buttons
= i
= 0; i
< 7; i
++) {
145 /* some arithmetic to get the right order for YesNoCancel windows */
146 hItem
= GetDlgItem32(hwnd
, (i
+ 5) % 7 + 1);
147 if (GetWindowLong32A(hItem
, GWL_STYLE
) & WS_VISIBLE
) {
148 if (buttons
++ == ((lpmb
->dwStyle
& MB_DEFMASK
) >> 8)) {
150 SendMessage32A( hItem
, BM_SETSTYLE32
, BS_DEFPUSHBUTTON
, TRUE
);
152 SetWindowPos32(hItem
, 0, bpos
, tiheight
, 0, 0,
153 SWP_NOSIZE
|SWP_NOZORDER
|SWP_NOACTIVATE
|SWP_NOREDRAW
);
170 EndDialog32(hwnd
, wParam
);
174 /* Ok. Ignore all the other messages */
175 TRACE (dialog
, "Message number %i is being ignored.\n", message
);
182 /**************************************************************************
183 * MessageBox16 (USER.1)
185 INT16 WINAPI
MessageBox16( HWND16 hwnd
, LPCSTR text
, LPCSTR title
, UINT16 type
)
187 return MessageBox32A( hwnd
, text
, title
, type
);
191 /**************************************************************************
192 * MessageBox32A (USER32.391)
194 INT32 WINAPI
MessageBox32A(HWND32 hWnd
, LPCSTR text
, LPCSTR title
, UINT32 type
)
196 MSGBOXPARAMS32A mbox
;
198 if (!text
) text
="<WINE-NULL>";
201 mbox
.lpszCaption
= title
;
202 mbox
.lpszText
= text
;
204 return DialogBoxIndirectParam32A( WIN_GetWindowInstance(hWnd
),
205 SYSRES_GetResPtr( SYSRES_DIALOG_MSGBOX
),
206 hWnd
, MSGBOX_DlgProc
, (LPARAM
)&mbox
);
210 /**************************************************************************
211 * MessageBox32W (USER32.396)
213 INT32 WINAPI
MessageBox32W( HWND32 hwnd
, LPCWSTR text
, LPCWSTR title
,
216 LPSTR titleA
= HEAP_strdupWtoA( GetProcessHeap(), 0, title
);
217 LPSTR textA
= HEAP_strdupWtoA( GetProcessHeap(), 0, text
);
218 INT32 ret
= MessageBox32A( hwnd
, textA
, titleA
, type
);
219 HeapFree( GetProcessHeap(), 0, titleA
);
220 HeapFree( GetProcessHeap(), 0, textA
);
225 /**************************************************************************
226 * MessageBoxEx32A (USER32.392)
228 INT32 WINAPI
MessageBoxEx32A( HWND32 hWnd
, LPCSTR text
, LPCSTR title
,
229 UINT32 type
, WORD langid
)
231 /* ignore language id for now */
232 return MessageBox32A(hWnd
,text
,title
,type
);
235 /**************************************************************************
236 * MessageBoxEx32W (USER32.393)
238 INT32 WINAPI
MessageBoxEx32W( HWND32 hWnd
, LPCWSTR text
, LPCWSTR title
,
239 UINT32 type
, WORD langid
)
241 /* ignore language id for now */
242 return MessageBox32W(hWnd
,text
,title
,type
);
245 /**************************************************************************
246 * MessageBoxIndirect16 (USER.827)
248 INT16 WINAPI
MessageBoxIndirect16( LPMSGBOXPARAMS16 msgbox
)
250 MSGBOXPARAMS32A msgbox32
;
252 msgbox32
.cbSize
= msgbox
->cbSize
;
253 msgbox32
.hwndOwner
= msgbox
->hwndOwner
;
254 msgbox32
.hInstance
= msgbox
->hInstance
;
255 msgbox32
.lpszText
= PTR_SEG_TO_LIN(msgbox
->lpszText
);
256 msgbox32
.lpszCaption
= PTR_SEG_TO_LIN(msgbox
->lpszCaption
);
257 msgbox32
.dwStyle
= msgbox
->dwStyle
;
258 msgbox32
.lpszIcon
= PTR_SEG_TO_LIN(msgbox
->lpszIcon
);
259 msgbox32
.dwContextHelpId
= msgbox
->dwContextHelpId
;
260 msgbox32
.lpfnMsgBoxCallback
= msgbox
->lpfnMsgBoxCallback
;
261 msgbox32
.dwLanguageId
= msgbox
->dwLanguageId
;
263 return DialogBoxIndirectParam32A( msgbox32
.hInstance
,
264 SYSRES_GetResPtr( SYSRES_DIALOG_MSGBOX
),
265 msgbox32
.hwndOwner
, MSGBOX_DlgProc
,
269 /**************************************************************************
270 * MessageBoxIndirect32A (USER32.394)
272 INT32 WINAPI
MessageBoxIndirect32A( LPMSGBOXPARAMS32A msgbox
)
274 return DialogBoxIndirectParam32A( msgbox
->hInstance
,
275 SYSRES_GetResPtr( SYSRES_DIALOG_MSGBOX
),
276 msgbox
->hwndOwner
, MSGBOX_DlgProc
,
280 /**************************************************************************
281 * MessageBoxIndirect32W (USER32.395)
283 INT32 WINAPI
MessageBoxIndirect32W( LPMSGBOXPARAMS32W msgbox
)
285 MSGBOXPARAMS32A msgboxa
;
287 memcpy(&msgboxa
,msgbox
,sizeof(msgboxa
));
288 if (msgbox
->lpszCaption
) lstrcpyWtoA(msgboxa
.lpszCaption
,msgbox
->lpszCaption
);
289 if (msgbox
->lpszText
) lstrcpyWtoA(msgboxa
.lpszText
,msgbox
->lpszText
);
291 return MessageBoxIndirect32A(&msgboxa
);
295 /**************************************************************************
296 * FatalAppExit16 (KERNEL.137)
298 void WINAPI
FatalAppExit16( UINT16 action
, LPCSTR str
)
300 FatalAppExit32A( action
, str
);
304 /**************************************************************************
305 * FatalAppExit32A (KERNEL32.108)
307 void WINAPI
FatalAppExit32A( UINT32 action
, LPCSTR str
)
309 MessageBox32A( 0, str
, NULL
, MB_SYSTEMMODAL
| MB_OK
);
310 TASK_KillCurrentTask(0);
314 /**************************************************************************
315 * FatalAppExit32W (KERNEL32.109)
317 void WINAPI
FatalAppExit32W( UINT32 action
, LPCWSTR str
)
319 MessageBox32W( 0, str
, NULL
, MB_SYSTEMMODAL
| MB_OK
);
320 TASK_KillCurrentTask(0);