msgbox.c 17.9 KB
Newer Older
Alexandre Julliard's avatar
Alexandre Julliard committed
1 2 3 4
/*
 * Message boxes
 *
 * Copyright 1995 Bernd Schmidt
5
 * Copyright 2004 Ivan Leo Puoti, Juan Lang
6 7 8 9 10 11 12 13 14 15 16 17 18
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
19
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
Alexandre Julliard's avatar
Alexandre Julliard committed
20 21
 */

22
#include <stdarg.h>
23
#include <string.h>
Patrik Stridvall's avatar
Patrik Stridvall committed
24

25
#include "windef.h"
26
#include "winbase.h"
27
#include "wingdi.h"
28
#include "winternl.h"
Alexandre Julliard's avatar
Alexandre Julliard committed
29
#include "dlgs.h"
30
#include "user_private.h"
31
#include "wine/debug.h"
Alexandre Julliard's avatar
Alexandre Julliard committed
32

33
WINE_DEFAULT_DEBUG_CHANNEL(dialog);
34
WINE_DECLARE_DEBUG_CHANNEL(msgbox);
35

36
#define MSGBOX_IDICON stc1
37
#define MSGBOX_IDTEXT 100
38
#define IDS_ERROR     2
Alexandre Julliard's avatar
Alexandre Julliard committed
39

40 41 42 43 44 45 46
struct ThreadWindows
{
    UINT numHandles;
    UINT numAllocs;
    HWND *handles;
};

47
static BOOL CALLBACK MSGBOX_EnumProc(HWND hwnd, LPARAM lParam)
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63
{
    struct ThreadWindows *threadWindows = (struct ThreadWindows *)lParam;

    if (!EnableWindow(hwnd, FALSE))
    {
        if(threadWindows->numHandles >= threadWindows->numAllocs)
        {
            threadWindows->handles = HeapReAlloc(GetProcessHeap(), 0, threadWindows->handles,
                                                 (threadWindows->numAllocs*2)*sizeof(HWND));
            threadWindows->numAllocs *= 2;
        }
        threadWindows->handles[threadWindows->numHandles++]=hwnd;
    }
   return TRUE;
}

64
static HFONT MSGBOX_OnInit(HWND hwnd, LPMSGBOXPARAMSW lpmb)
65
{
66
    HFONT hFont = 0, hPrevFont = 0;
67 68 69 70
    RECT rect;
    HWND hItem;
    HDC hdc;
    int i, buttons;
71
    int bspace, bw, bh, theight, tleft, wwidth, wheight, wleft, wtop, bpos;
72
    int borheight, borwidth, iheight, ileft, iwidth, twidth, tiheight;
73
    NONCLIENTMETRICSW nclm;
74 75
    HMONITOR monitor = 0;
    MONITORINFO mon_info;
76
    LPCWSTR lpszText;
77 78 79
    WCHAR *buffer = NULL;
    const WCHAR *ptr;

80
    /* Index the order the buttons need to appear to an ID* constant */
81 82 83
    static const int buttonOrder[10] = { IDYES, IDNO, IDOK, IDABORT, IDRETRY,
                                         IDCANCEL, IDIGNORE, IDTRYAGAIN,
                                         IDCONTINUE, IDHELP };
84

85 86 87 88
    nclm.cbSize = sizeof(nclm);
    SystemParametersInfoW (SPI_GETNONCLIENTMETRICS, 0, &nclm, 0);
    hFont = CreateFontIndirectW (&nclm.lfMessageFont);
    /* set button font */
89 90 91 92 93
    for (i=1; i < 12; i++)
        /* No button 8 (Close) */
        if (i != 8) {
            SendDlgItemMessageW (hwnd, i, WM_SETFONT, (WPARAM)hFont, 0);
        }
94 95 96
    /* set text font */
    SendDlgItemMessageW (hwnd, MSGBOX_IDTEXT, WM_SETFONT, (WPARAM)hFont, 0);

97
    if (!IS_INTRESOURCE(lpmb->lpszCaption)) {
98
       SetWindowTextW(hwnd, lpmb->lpszCaption);
99
    } else {
100 101 102 103 104 105 106 107 108 109 110
        UINT len = LoadStringW( lpmb->hInstance, LOWORD(lpmb->lpszCaption), (LPWSTR)&ptr, 0 );
        if (!len) len = LoadStringW( user32_module, IDS_ERROR, (LPWSTR)&ptr, 0 );
        buffer = HeapAlloc( GetProcessHeap(), 0, (len + 1) * sizeof(WCHAR) );
        if (buffer)
        {
            memcpy( buffer, ptr, len * sizeof(WCHAR) );
            buffer[len] = 0;
            SetWindowTextW( hwnd, buffer );
            HeapFree( GetProcessHeap(), 0, buffer );
            buffer = NULL;
        }
111
    }
112
    if (IS_INTRESOURCE(lpmb->lpszText)) {
113 114 115 116 117 118 119
        UINT len = LoadStringW( lpmb->hInstance, LOWORD(lpmb->lpszText), (LPWSTR)&ptr, 0 );
        lpszText = buffer = HeapAlloc( GetProcessHeap(), 0, (len + 1) * sizeof(WCHAR) );
        if (buffer)
        {
            memcpy( buffer, ptr, len * sizeof(WCHAR) );
            buffer[len] = 0;
        }
120 121
    } else {
       lpszText = lpmb->lpszText;
122
    }
123

124
    TRACE_(msgbox)("%s\n", debugstr_w(lpszText));
125
    SetWindowTextW(GetDlgItem(hwnd, MSGBOX_IDTEXT), lpszText);
126

127
    /* Remove not selected buttons */
Alexandre Julliard's avatar
Alexandre Julliard committed
128
    switch(lpmb->dwStyle & MB_TYPEMASK) {
129
    case MB_OK:
130
	DestroyWindow(GetDlgItem(hwnd, IDCANCEL));
131 132
	/* fall through */
    case MB_OKCANCEL:
133 134 135 136 137 138 139
	DestroyWindow(GetDlgItem(hwnd, IDABORT));
	DestroyWindow(GetDlgItem(hwnd, IDRETRY));
	DestroyWindow(GetDlgItem(hwnd, IDIGNORE));
	DestroyWindow(GetDlgItem(hwnd, IDYES));
	DestroyWindow(GetDlgItem(hwnd, IDNO));
	DestroyWindow(GetDlgItem(hwnd, IDTRYAGAIN));
	DestroyWindow(GetDlgItem(hwnd, IDCONTINUE));
140 141
	break;
    case MB_ABORTRETRYIGNORE:
142 143 144 145 146 147
	DestroyWindow(GetDlgItem(hwnd, IDOK));
	DestroyWindow(GetDlgItem(hwnd, IDCANCEL));
	DestroyWindow(GetDlgItem(hwnd, IDYES));
	DestroyWindow(GetDlgItem(hwnd, IDNO));
	DestroyWindow(GetDlgItem(hwnd, IDCONTINUE));
	DestroyWindow(GetDlgItem(hwnd, IDTRYAGAIN));
148 149
	break;
    case MB_YESNO:
150
	DestroyWindow(GetDlgItem(hwnd, IDCANCEL));
151 152
	/* fall through */
    case MB_YESNOCANCEL:
153 154 155 156 157 158
	DestroyWindow(GetDlgItem(hwnd, IDOK));
	DestroyWindow(GetDlgItem(hwnd, IDABORT));
	DestroyWindow(GetDlgItem(hwnd, IDRETRY));
	DestroyWindow(GetDlgItem(hwnd, IDIGNORE));
	DestroyWindow(GetDlgItem(hwnd, IDCONTINUE));
	DestroyWindow(GetDlgItem(hwnd, IDTRYAGAIN));
159 160
	break;
    case MB_RETRYCANCEL:
161 162 163 164 165 166 167
	DestroyWindow(GetDlgItem(hwnd, IDOK));
	DestroyWindow(GetDlgItem(hwnd, IDABORT));
	DestroyWindow(GetDlgItem(hwnd, IDIGNORE));
	DestroyWindow(GetDlgItem(hwnd, IDYES));
	DestroyWindow(GetDlgItem(hwnd, IDNO));
	DestroyWindow(GetDlgItem(hwnd, IDCONTINUE));
	DestroyWindow(GetDlgItem(hwnd, IDTRYAGAIN));
168
	break;
169
    case MB_CANCELTRYCONTINUE:
170 171 172 173 174 175
	DestroyWindow(GetDlgItem(hwnd, IDOK));
	DestroyWindow(GetDlgItem(hwnd, IDABORT));
	DestroyWindow(GetDlgItem(hwnd, IDIGNORE));
	DestroyWindow(GetDlgItem(hwnd, IDYES));
	DestroyWindow(GetDlgItem(hwnd, IDNO));
	DestroyWindow(GetDlgItem(hwnd, IDRETRY));
Alexandre Julliard's avatar
Alexandre Julliard committed
176 177
    }
    /* Set the icon */
Alexandre Julliard's avatar
Alexandre Julliard committed
178
    switch(lpmb->dwStyle & MB_ICONMASK) {
179
    case MB_ICONEXCLAMATION:
180
	SendDlgItemMessageW(hwnd, MSGBOX_IDICON, STM_SETICON,
181
			    (WPARAM)LoadIconW(0, (LPWSTR)IDI_EXCLAMATION), 0);
182 183
	break;
    case MB_ICONQUESTION:
184
	SendDlgItemMessageW(hwnd, MSGBOX_IDICON, STM_SETICON,
185
			    (WPARAM)LoadIconW(0, (LPWSTR)IDI_QUESTION), 0);
186 187
	break;
    case MB_ICONASTERISK:
188
	SendDlgItemMessageW(hwnd, MSGBOX_IDICON, STM_SETICON,
189
			    (WPARAM)LoadIconW(0, (LPWSTR)IDI_ASTERISK), 0);
190 191
	break;
    case MB_ICONHAND:
192
      SendDlgItemMessageW(hwnd, MSGBOX_IDICON, STM_SETICON,
193
			    (WPARAM)LoadIconW(0, (LPWSTR)IDI_HAND), 0);
194 195
      break;
    case MB_USERICON:
196
      SendDlgItemMessageW(hwnd, MSGBOX_IDICON, STM_SETICON,
197
			  (WPARAM)LoadIconW(lpmb->hInstance, lpmb->lpszIcon), 0);
198 199 200 201 202
      break;
    default:
	/* By default, Windows 95/98/NT do not associate an icon to message boxes.
         * So wine should do the same.
         */
203
	break;
Alexandre Julliard's avatar
Alexandre Julliard committed
204
    }
205

206
    /* Remove Help button unless MB_HELP supplied */
207
    if (!(lpmb->dwStyle & MB_HELP)) {
208
        DestroyWindow(GetDlgItem(hwnd, IDHELP));
209 210
    }

Alexandre Julliard's avatar
Alexandre Julliard committed
211
    /* Position everything */
212
    GetWindowRect(hwnd, &rect);
Alexandre Julliard's avatar
Alexandre Julliard committed
213
    borheight = rect.bottom - rect.top;
214
    borwidth  = rect.right - rect.left;
215
    GetClientRect(hwnd, &rect);
Alexandre Julliard's avatar
Alexandre Julliard committed
216
    borheight -= rect.bottom - rect.top;
217
    borwidth  -= rect.right - rect.left;
218

Alexandre Julliard's avatar
Alexandre Julliard committed
219
    /* Get the icon height */
220 221
    GetWindowRect(GetDlgItem(hwnd, MSGBOX_IDICON), &rect);
    MapWindowPoints(0, hwnd, (LPPOINT)&rect, 2);
222 223 224 225 226
    if (!(lpmb->dwStyle & MB_ICONMASK))
    {
        rect.bottom = rect.top;
        rect.right = rect.left;
    }
Alexandre Julliard's avatar
Alexandre Julliard committed
227
    iheight = rect.bottom - rect.top;
228 229
    ileft = rect.left;
    iwidth = rect.right - ileft;
230

231 232 233
    hdc = GetDC(hwnd);
    if (hFont)
	hPrevFont = SelectObject(hdc, hFont);
234

235 236
    /* Get the number of visible buttons and their size */
    bh = bw = 1; /* Minimum button sizes */
237
    for (buttons = 0, i = 1; i < 12; i++)
Alexandre Julliard's avatar
Alexandre Julliard committed
238
    {
239
        if (i == 8) continue; /* No CLOSE button */
240
	hItem = GetDlgItem(hwnd, i);
241
	if (GetWindowLongW(hItem, GWL_STYLE) & WS_VISIBLE)
242
	{
243
	    WCHAR buttonText[1024];
244 245
	    int w, h;
	    buttons++;
246
	    if (GetWindowTextW(hItem, buttonText, 1024))
247
	    {
248
		DrawTextW( hdc, buttonText, -1, &rect, DT_LEFT | DT_EXPANDTABS | DT_CALCRECT);
249 250 251 252 253 254
		h = rect.bottom - rect.top;
		w = rect.right - rect.left;
		if (h > bh) bh = h;
		if (w > bw)  bw = w ;
	    }
	}
Alexandre Julliard's avatar
Alexandre Julliard committed
255
    }
256
    bw = max(bw, bh * 2);
257 258 259 260
    /* Button white space */
    bh = bh * 2;
    bw = bw * 2;
    bspace = bw/3; /* Space between buttons */
261

Alexandre Julliard's avatar
Alexandre Julliard committed
262
    /* Get the text size */
263 264
    GetClientRect(GetDlgItem(hwnd, MSGBOX_IDTEXT), &rect);
    rect.top = rect.left = rect.bottom = 0;
265
    DrawTextW( hdc, lpszText, -1, &rect,
266 267
	       DT_LEFT | DT_EXPANDTABS | DT_WORDBREAK | DT_CALCRECT);
    /* Min text width corresponds to space for the buttons */
268 269
    tleft = ileft;
    if (iwidth) tleft += ileft + iwidth;
270
    twidth = max((bw + bspace) * buttons + bspace - tleft, rect.right);
271
    theight = rect.bottom;
272

273 274
    if (hFont)
	SelectObject(hdc, hPrevFont);
275
    ReleaseDC(hwnd, hdc);
276

277
    tiheight = 16 + max(iheight, theight);
278 279
    wwidth  = tleft + twidth + ileft + borwidth;
    wheight = 8 + tiheight + bh + borheight;
280

281 282
    /* Message boxes are always desktop centered, so query desktop size and center window */
    monitor = MonitorFromWindow(lpmb->hwndOwner ? lpmb->hwndOwner : GetActiveWindow(), MONITOR_DEFAULTTOPRIMARY);
283
    mon_info.cbSize = sizeof(mon_info);
284 285 286 287 288 289 290
    GetMonitorInfoW(monitor, &mon_info);
    wleft = (mon_info.rcWork.left + mon_info.rcWork.right - wwidth) / 2;
    wtop = (mon_info.rcWork.top + mon_info.rcWork.bottom - wheight) / 2;

    /* Resize and center the window */
    SetWindowPos(hwnd, 0, wleft, wtop, wwidth, wheight,
		 SWP_NOZORDER | SWP_NOACTIVATE | SWP_NOREDRAW);
291

Alexandre Julliard's avatar
Alexandre Julliard committed
292
    /* Position the icon */
293 294
    SetWindowPos(GetDlgItem(hwnd, MSGBOX_IDICON), 0, ileft, (tiheight - iheight) / 2, 0, 0,
		 SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE | SWP_NOREDRAW);
295

296 297 298
    /* Position the text */
    SetWindowPos(GetDlgItem(hwnd, MSGBOX_IDTEXT), 0, tleft, (tiheight - theight) / 2, twidth, theight,
		 SWP_NOZORDER | SWP_NOACTIVATE | SWP_NOREDRAW);
299

Alexandre Julliard's avatar
Alexandre Julliard committed
300
    /* Position the buttons */
301
    bpos = (wwidth - (bw + bspace) * buttons + bspace) / 2;
302 303 304 305
    for (buttons = i = 0; i < (sizeof(buttonOrder) / sizeof(buttonOrder[0])); i++) {

	/* Convert the button order to ID* value to order for the buttons */
	hItem = GetDlgItem(hwnd, buttonOrder[i]);
306
	if (GetWindowLongW(hItem, GWL_STYLE) & WS_VISIBLE) {
307 308
	    if (buttons++ == ((lpmb->dwStyle & MB_DEFMASK) >> 8)) {
		SetFocus(hItem);
309
		SendMessageW( hItem, BM_SETSTYLE, BS_DEFPUSHBUTTON, TRUE );
310 311 312 313
	    }
	    SetWindowPos(hItem, 0, bpos, tiheight, bw, bh,
			 SWP_NOZORDER|SWP_NOACTIVATE|SWP_NOREDRAW);
	    bpos += bw + bspace;
Alexandre Julliard's avatar
Alexandre Julliard committed
314 315
	}
    }
316

317 318 319
    /*handle modal message boxes*/
    if (((lpmb->dwStyle & MB_TASKMODAL) && (lpmb->hwndOwner==NULL)) || (lpmb->dwStyle & MB_SYSTEMMODAL))
        SetWindowPos(hwnd, HWND_TOP, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE);
320

321
    HeapFree( GetProcessHeap(), 0, buffer );
322 323 324 325 326 327 328 329 330
    return hFont;
}


/**************************************************************************
 *           MSGBOX_DlgProc
 *
 * Dialog procedure for message boxes.
 */
331
static INT_PTR CALLBACK MSGBOX_DlgProc( HWND hwnd, UINT message,
332
                                        WPARAM wParam, LPARAM lParam )
333
{
334 335
  HFONT hFont;

336 337
  switch(message) {
   case WM_INITDIALOG:
338 339 340 341
   {
       LPMSGBOXPARAMSW mbp = (LPMSGBOXPARAMSW)lParam;
       SetWindowContextHelpId(hwnd, mbp->dwContextHelpId);
       hFont = MSGBOX_OnInit(hwnd, mbp);
342 343
       SetPropA(hwnd, "WINE_MSGBOX_HFONT", hFont);
       SetPropA(hwnd, "WINE_MSGBOX_HELPCALLBACK", mbp->lpfnMsgBoxCallback);
344 345
       break;
   }
346

Alexandre Julliard's avatar
Alexandre Julliard committed
347
   case WM_COMMAND:
348
    switch (LOWORD(wParam))
Alexandre Julliard's avatar
Alexandre Julliard committed
349
    {
Alexandre Julliard's avatar
Alexandre Julliard committed
350 351 352 353 354 355 356
     case IDOK:
     case IDCANCEL:
     case IDABORT:
     case IDRETRY:
     case IDIGNORE:
     case IDYES:
     case IDNO:
357 358
     case IDTRYAGAIN:
     case IDCONTINUE:
359
      hFont = GetPropA(hwnd, "WINE_MSGBOX_HFONT");
360
      EndDialog(hwnd, wParam);
361 362
      if (hFont)
	  DeleteObject(hFont);
Alexandre Julliard's avatar
Alexandre Julliard committed
363
      break;
364 365 366
     case IDHELP:
      FIXME("Help button not supported yet\n");
      break;
Alexandre Julliard's avatar
Alexandre Julliard committed
367
    }
368
    break;
Alexandre Julliard's avatar
Alexandre Julliard committed
369

370 371 372 373 374 375 376 377 378 379 380 381 382 383 384
    case WM_HELP:
    {
        MSGBOXCALLBACK callback = (MSGBOXCALLBACK)GetPropA(hwnd, "WINE_MSGBOX_HELPCALLBACK");
        HELPINFO hi;

        memcpy(&hi, (void *)lParam, sizeof(hi));
        hi.dwContextId = GetWindowContextHelpId(hwnd);

        if (callback)
            callback(&hi);
        else
            SendMessageW(GetWindow(hwnd, GW_OWNER), WM_HELP, 0, (LPARAM)&hi);
	break;
   }

Alexandre Julliard's avatar
Alexandre Julliard committed
385 386
   default:
     /* Ok. Ignore all the other messages */
387
     TRACE("Message number 0x%04x is being ignored.\n", message);
Alexandre Julliard's avatar
Alexandre Julliard committed
388 389 390 391 392
    break;
  }
  return 0;
}

Alexandre Julliard's avatar
Alexandre Julliard committed
393

Alexandre Julliard's avatar
Alexandre Julliard committed
394
/**************************************************************************
395
 *		MessageBoxA (USER32.@)
Alexandre Julliard's avatar
Alexandre Julliard committed
396
 */
397
INT WINAPI MessageBoxA(HWND hWnd, LPCSTR text, LPCSTR title, UINT type)
Alexandre Julliard's avatar
Alexandre Julliard committed
398
{
399
    return MessageBoxExA(hWnd, text, title, type, LANG_NEUTRAL);
Alexandre Julliard's avatar
Alexandre Julliard committed
400 401
}

Alexandre Julliard's avatar
Alexandre Julliard committed
402

Alexandre Julliard's avatar
Alexandre Julliard committed
403
/**************************************************************************
404
 *		MessageBoxW (USER32.@)
Alexandre Julliard's avatar
Alexandre Julliard committed
405
 */
406
INT WINAPI MessageBoxW( HWND hwnd, LPCWSTR text, LPCWSTR title, UINT type )
Alexandre Julliard's avatar
Alexandre Julliard committed
407
{
408
    return MessageBoxExW(hwnd, text, title, type, LANG_NEUTRAL);
Alexandre Julliard's avatar
Alexandre Julliard committed
409
}
Alexandre Julliard's avatar
Alexandre Julliard committed
410 411


Alexandre Julliard's avatar
Alexandre Julliard committed
412
/**************************************************************************
413
 *		MessageBoxExA (USER32.@)
Alexandre Julliard's avatar
Alexandre Julliard committed
414
 */
415 416
INT WINAPI MessageBoxExA( HWND hWnd, LPCSTR text, LPCSTR title,
                              UINT type, WORD langid )
Alexandre Julliard's avatar
Alexandre Julliard committed
417
{
418 419 420 421 422 423 424 425 426 427 428 429 430 431
    MSGBOXPARAMSA msgbox;

    msgbox.cbSize = sizeof(msgbox);
    msgbox.hwndOwner = hWnd;
    msgbox.hInstance = 0;
    msgbox.lpszText = text;
    msgbox.lpszCaption = title;
    msgbox.dwStyle = type;
    msgbox.lpszIcon = NULL;
    msgbox.dwContextHelpId = 0;
    msgbox.lpfnMsgBoxCallback = NULL;
    msgbox.dwLanguageId = langid;

    return MessageBoxIndirectA(&msgbox);
Alexandre Julliard's avatar
Alexandre Julliard committed
432 433 434
}

/**************************************************************************
435
 *		MessageBoxExW (USER32.@)
Alexandre Julliard's avatar
Alexandre Julliard committed
436
 */
437 438
INT WINAPI MessageBoxExW( HWND hWnd, LPCWSTR text, LPCWSTR title,
                              UINT type, WORD langid )
Alexandre Julliard's avatar
Alexandre Julliard committed
439
{
440 441 442 443 444 445 446 447 448 449 450 451 452 453
    MSGBOXPARAMSW msgbox;

    msgbox.cbSize = sizeof(msgbox);
    msgbox.hwndOwner = hWnd;
    msgbox.hInstance = 0;
    msgbox.lpszText = text;
    msgbox.lpszCaption = title;
    msgbox.dwStyle = type;
    msgbox.lpszIcon = NULL;
    msgbox.dwContextHelpId = 0;
    msgbox.lpfnMsgBoxCallback = NULL;
    msgbox.dwLanguageId = langid;

    return MessageBoxIndirectW(&msgbox);
Alexandre Julliard's avatar
Alexandre Julliard committed
454 455
}

456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475
/**************************************************************************
 *      MessageBoxTimeoutA (USER32.@)
 */
INT WINAPI MessageBoxTimeoutA( HWND hWnd, LPCSTR text, LPCSTR title,
                               UINT type, WORD langid, DWORD timeout )
{
    FIXME("timeout not supported (%u)\n", timeout);
    return MessageBoxExA( hWnd, text, title, type, langid );
}

/**************************************************************************
 *      MessageBoxTimeoutW (USER32.@)
 */
INT WINAPI MessageBoxTimeoutW( HWND hWnd, LPCWSTR text, LPCWSTR title,
                               UINT type, WORD langid, DWORD timeout )
{
    FIXME("timeout not supported (%u)\n", timeout);
    return MessageBoxExW( hWnd, text, title, type, langid );
}

Alexandre Julliard's avatar
Alexandre Julliard committed
476
/**************************************************************************
477
 *		MessageBoxIndirectA (USER32.@)
Alexandre Julliard's avatar
Alexandre Julliard committed
478
 */
479
INT WINAPI MessageBoxIndirectA( LPMSGBOXPARAMSA msgbox )
Alexandre Julliard's avatar
Alexandre Julliard committed
480
{
481 482 483 484
    MSGBOXPARAMSW msgboxW;
    UNICODE_STRING textW, captionW, iconW;
    int ret;

485
    if (IS_INTRESOURCE(msgbox->lpszText))
486 487
        textW.Buffer = (LPWSTR)msgbox->lpszText;
    else
488 489
        RtlCreateUnicodeStringFromAsciiz(&textW, msgbox->lpszText);
    if (IS_INTRESOURCE(msgbox->lpszCaption))
490
        captionW.Buffer = (LPWSTR)msgbox->lpszCaption;
491 492
    else
        RtlCreateUnicodeStringFromAsciiz(&captionW, msgbox->lpszCaption);
493 494 495

    if (msgbox->dwStyle & MB_USERICON)
    {
496
        if (IS_INTRESOURCE(msgbox->lpszIcon))
497
            iconW.Buffer = (LPWSTR)msgbox->lpszIcon;
498 499
        else
            RtlCreateUnicodeStringFromAsciiz(&iconW, msgbox->lpszIcon);
500
    }
501
    else
502
        iconW.Buffer = NULL;
503 504 505 506 507 508 509 510 511 512 513 514 515 516

    msgboxW.cbSize = sizeof(msgboxW);
    msgboxW.hwndOwner = msgbox->hwndOwner;
    msgboxW.hInstance = msgbox->hInstance;
    msgboxW.lpszText = textW.Buffer;
    msgboxW.lpszCaption = captionW.Buffer;
    msgboxW.dwStyle = msgbox->dwStyle;
    msgboxW.lpszIcon = iconW.Buffer;
    msgboxW.dwContextHelpId = msgbox->dwContextHelpId;
    msgboxW.lpfnMsgBoxCallback = msgbox->lpfnMsgBoxCallback;
    msgboxW.dwLanguageId = msgbox->dwLanguageId;

    ret = MessageBoxIndirectW(&msgboxW);

517 518 519
    if (!IS_INTRESOURCE(textW.Buffer)) RtlFreeUnicodeString(&textW);
    if (!IS_INTRESOURCE(captionW.Buffer)) RtlFreeUnicodeString(&captionW);
    if (!IS_INTRESOURCE(iconW.Buffer)) RtlFreeUnicodeString(&iconW);
520
    return ret;
Alexandre Julliard's avatar
Alexandre Julliard committed
521 522 523
}

/**************************************************************************
524
 *		MessageBoxIndirectW (USER32.@)
Alexandre Julliard's avatar
Alexandre Julliard committed
525
 */
526
INT WINAPI MessageBoxIndirectW( LPMSGBOXPARAMSW msgbox )
Alexandre Julliard's avatar
Alexandre Julliard committed
527
{
528 529
    LPVOID tmplate;
    HRSRC hRes;
530 531 532
    int ret;
    UINT i;
    struct ThreadWindows threadWindows;
533
    static const WCHAR msg_box_res_nameW[] = { 'M','S','G','B','O','X',0 };
534

535 536
    if (!(hRes = FindResourceExW(user32_module, (LPWSTR)RT_DIALOG,
                                 msg_box_res_nameW, msgbox->dwLanguageId)))
537 538 539 540 541
    {
        if (!msgbox->dwLanguageId ||
            !(hRes = FindResourceExW(user32_module, (LPWSTR)RT_DIALOG, msg_box_res_nameW, LANG_NEUTRAL)))
            return 0;
    }
542
    if (!(tmplate = LoadResource(user32_module, hRes)))
543 544
        return 0;

545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562
    if ((msgbox->dwStyle & MB_TASKMODAL) && (msgbox->hwndOwner==NULL))
    {
        threadWindows.numHandles = 0;
        threadWindows.numAllocs = 10;
        threadWindows.handles = HeapAlloc(GetProcessHeap(), 0, 10*sizeof(HWND));
        EnumThreadWindows(GetCurrentThreadId(), MSGBOX_EnumProc, (LPARAM)&threadWindows);
    }

    ret=DialogBoxIndirectParamW(msgbox->hInstance, tmplate,
                                msgbox->hwndOwner, MSGBOX_DlgProc, (LPARAM)msgbox);

    if ((msgbox->dwStyle & MB_TASKMODAL) && (msgbox->hwndOwner==NULL))
    {
        for (i = 0; i < threadWindows.numHandles; i++)
            EnableWindow(threadWindows.handles[i], TRUE);
        HeapFree(GetProcessHeap(), 0, threadWindows.handles);
    }
    return ret;
Alexandre Julliard's avatar
Alexandre Julliard committed
563
}