3 * Copyright (C) 1998, 1999, 2000, 2001 ReactOS Team
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 * PROJECT: ReactOS user32.dll
22 * FILE: win32ss/user/user32/windows/messagebox.c
24 * PROGRAMMERS: Casper S. Hornstrup (chorns@users.sourceforge.net)
25 * Thomas Weidenmueller (w3seek@users.sourceforge.net)
27 * 2003/07/28 Added some NT features
28 * 2003/07/27 Code ported from wine
29 * 09-05-2001 CSH Created
32 /* INCLUDES ******************************************************************/
36 #include <wine/debug.h>
38 WINE_DEFAULT_DEBUG_CHANNEL(user32
);
40 /* DEFINES *******************************************************************/
42 #define MSGBOX_IDICON (1088)
43 #define MSGBOX_IDTEXT (100)
45 #define IDI_HANDW MAKEINTRESOURCEW(32513)
46 #define IDI_QUESTIONW MAKEINTRESOURCEW(32514)
47 #define IDI_EXCLAMATIONW MAKEINTRESOURCEW(32515)
48 #define IDI_ASTERISKW MAKEINTRESOURCEW(32516)
49 #define IDI_WINLOGOW MAKEINTRESOURCEW(32517)
52 /* MessageBox metrics */
57 #define MSGBOXEX_SPACING (16)
58 #define MSGBOXEX_BUTTONSPACING (6)
59 #define MSGBOXEX_MARGIN (12)
60 #define MSGBOXEX_MAXBTNSTR (32)
61 #define MSGBOXEX_MAXBTNS (4)
63 /* Rescale logical coordinates */
64 #define RESCALE_X(_x, _unit) (((_x) * 4 + LOWORD(_unit) - 1) / LOWORD(_unit))
65 #define RESCALE_Y(_y, _unit) (((_y) * 8 + HIWORD(_unit) - 1) / HIWORD(_unit))
68 /* MessageBox button helpers */
70 #define DECLARE_MB_1(_btn0) \
71 { 1, { ID##_btn0, 0, 0 }, { IDS_##_btn0, 0, 0 } }
73 #define DECLARE_MB_2(_btn0, _btn1) \
74 { 2, { ID##_btn0, ID##_btn1, 0 }, { IDS_##_btn0, IDS_##_btn1, 0 } }
76 #define DECLARE_MB_3(_btn0, _btn1, _btn2) \
77 { 3, { ID##_btn0, ID##_btn1, ID##_btn2 }, { IDS_##_btn0, IDS_##_btn1, IDS_##_btn2 } }
79 typedef struct _MSGBTNINFO
82 LONG btnIdx
[MSGBOXEX_MAXBTNS
];
83 UINT btnIds
[MSGBOXEX_MAXBTNS
];
84 } MSGBTNINFO
, *PMSGBTNINFO
;
86 /* Default MessageBox buttons */
87 static const MSGBTNINFO MsgBtnInfo
[] =
92 DECLARE_MB_2(OK
, CANCEL
),
93 /* MB_ABORTRETRYIGNORE (2) */
94 DECLARE_MB_3(ABORT
, RETRY
, IGNORE
),
95 /* MB_YESNOCANCEL (3) */
96 DECLARE_MB_3(YES
, NO
, CANCEL
),
98 DECLARE_MB_2(YES
, NO
),
99 /* MB_RETRYCANCEL (5) */
100 DECLARE_MB_2(RETRY
, CANCEL
),
101 /* MB_CANCELTRYCONTINUE (6) */
102 DECLARE_MB_3(CANCEL
, TRYAGAIN
, CONTINUE
)
106 typedef struct _MSGBOXINFO
108 MSGBOXPARAMSW
; // Wine passes this too.
116 } MSGBOXINFO
, *PMSGBOXINFO
;
118 /* INTERNAL FUNCTIONS ********************************************************/
120 static VOID
MessageBoxTextToClipboard(HWND DialogWindow
)
124 int cchTotal
, cchTitle
, cchText
, cchButton
, i
, n
, cchBuffer
;
125 LPWSTR pszBuffer
, pszBufferPos
, pMessageBoxText
, pszTitle
, pszText
, pszButton
;
126 WCHAR szButton
[MSGBOXEX_MAXBTNSTR
];
129 static const WCHAR szLine
[] = L
"---------------------------\r\n";
131 mbi
= (PMSGBOXINFO
)GetPropW(DialogWindow
, L
"ROS_MSGBOX");
132 hwndText
= GetDlgItem(DialogWindow
, MSGBOX_IDTEXT
);
133 cchTitle
= GetWindowTextLengthW(DialogWindow
) + 1;
134 cchText
= GetWindowTextLengthW(hwndText
) + 1;
139 pMessageBoxText
= (LPWSTR
)RtlAllocateHeap(GetProcessHeap(), 0, (cchTitle
+ cchText
) * sizeof(WCHAR
));
141 if (pMessageBoxText
== NULL
)
143 RtlFreeHeap(GetProcessHeap(), 0, pMessageBoxText
);
147 pszTitle
= pMessageBoxText
;
148 pszText
= pMessageBoxText
+ cchTitle
;
150 if (GetWindowTextW(DialogWindow
, pszTitle
, cchTitle
) == 0 ||
151 GetWindowTextW(hwndText
, pszText
, cchText
) == 0)
153 RtlFreeHeap(GetProcessHeap(), 0, pMessageBoxText
);
158 * Calculate the total buffer size.
160 cchTotal
= 6 + cchTitle
+ cchText
+ (lstrlenW(szLine
) * 4) + (mbi
->nButtons
* MSGBOXEX_MAXBTNSTR
+ 3);
162 hGlobal
= GlobalAlloc(GHND
, cchTotal
* sizeof(WCHAR
));
164 pszBuffer
= (LPWSTR
)GlobalLock(hGlobal
);
166 if (pszBuffer
== NULL
)
168 RtlFreeHeap(GetProcessHeap(), 0, pMessageBoxText
);
174 * First format title and text.
181 cchBuffer
= wsprintfW(pszBuffer
, L
"%s%s\r\n%s%s\r\n%s", szLine
, pszTitle
, szLine
, pszText
, szLine
);
182 pszBufferPos
= pszBuffer
+ cchBuffer
;
184 for (i
= 0; i
< mbi
->nButtons
; i
++)
186 GetDlgItemTextW(DialogWindow
, mbi
->Btns
[i
], szButton
, MSGBOXEX_MAXBTNSTR
);
188 cchButton
= strlenW(szButton
);
189 pszButton
= szButton
;
191 /* Skip '&' character. */
192 if (szButton
[0] == '&')
194 pszButton
= pszButton
+ 1;
195 cchButton
= cchButton
- 1;
198 for (n
= 0; n
< cchButton
; n
++)
199 *(pszBufferPos
++) = pszButton
[n
];
202 *(pszBufferPos
++) = L
' ';
203 *(pszBufferPos
++) = L
' ';
204 *(pszBufferPos
++) = L
' ';
207 wsprintfW(pszBufferPos
, L
"\r\n%s", szLine
);
209 GlobalUnlock(hGlobal
);
211 if (OpenClipboard(DialogWindow
))
214 SetClipboardData(CF_UNICODETEXT
, hGlobal
);
221 RtlFreeHeap(GetProcessHeap(), 0, pMessageBoxText
);
224 static INT_PTR CALLBACK
MessageBoxProc( HWND hwnd
, UINT message
,
225 WPARAM wParam
, LPARAM lParam
)
234 mbi
= (PMSGBOXINFO
)lParam
;
236 SetWindowLongPtrW(hwnd
, GWLP_USERDATA
, (LONG_PTR
)mbi
);
237 NtUserxSetMessageBox(hwnd
);
239 if(!GetPropW(hwnd
, L
"ROS_MSGBOX"))
241 SetPropW(hwnd
, L
"ROS_MSGBOX", (HANDLE
)lParam
);
243 if (mbi
->dwContextHelpId
)
244 SetWindowContextHelpId(hwnd
, mbi
->dwContextHelpId
);
248 SendDlgItemMessageW(hwnd
, MSGBOX_IDICON
, STM_SETICON
, (WPARAM
)mbi
->Icon
, 0);
249 Alert
= ALERT_SYSTEM_WARNING
;
251 else // Setup the rest of the alerts.
253 switch(mbi
->dwStyle
& MB_ICONMASK
)
256 Alert
= ALERT_SYSTEM_WARNING
;
259 Alert
= ALERT_SYSTEM_ERROR
;
261 case MB_ICONQUESTION
:
262 Alert
= ALERT_SYSTEM_QUERY
;
265 Alert
= ALERT_SYSTEM_INFORMATIONAL
;
269 /* Send out the alert notifications. */
270 NotifyWinEvent(EVENT_SYSTEM_ALERT
, hwnd
, OBJID_ALERT
, Alert
);
272 /* set control fonts */
273 SendDlgItemMessageW(hwnd
, MSGBOX_IDTEXT
, WM_SETFONT
, (WPARAM
)mbi
->Font
, 0);
274 for(i
= 0; i
< mbi
->nButtons
; i
++)
276 SendDlgItemMessageW(hwnd
, mbi
->Btns
[i
], WM_SETFONT
, (WPARAM
)mbi
->Font
, 0);
278 switch(mbi
->dwStyle
& MB_TYPEMASK
)
280 case MB_ABORTRETRYIGNORE
:
282 RemoveMenu(GetSystemMenu(hwnd
, FALSE
), SC_CLOSE
, MF_BYCOMMAND
);
285 SetFocus(GetDlgItem(hwnd
, mbi
->DefBtn
));
286 if(mbi
->Timeout
&& (mbi
->Timeout
!= (UINT
)-1))
287 SetTimer(hwnd
, 0, mbi
->Timeout
, NULL
);
292 switch (LOWORD(wParam
))
303 EndDialog(hwnd
, wParam
);
306 /* send WM_HELP message to messagebox window */
307 hi
.cbSize
= sizeof(HELPINFO
);
308 hi
.iContextType
= HELPINFO_WINDOW
;
309 hi
.iCtrlId
= LOWORD(wParam
);
310 hi
.hItemHandle
= (HANDLE
)lParam
;
312 GetCursorPos(&hi
.MousePos
);
313 SendMessageW(hwnd
, WM_HELP
, 0, (LPARAM
)&hi
);
319 MessageBoxTextToClipboard(hwnd
);
323 mbi
= (PMSGBOXINFO
)GetPropW(hwnd
, L
"ROS_MSGBOX");
326 memcpy(&hi
, (void *)lParam
, sizeof(hi
));
327 hi
.dwContextId
= GetWindowContextHelpId(hwnd
);
329 if (mbi
->lpfnMsgBoxCallback
)
330 mbi
->lpfnMsgBoxCallback(&hi
);
333 owner
= GetWindow(hwnd
, GW_OWNER
);
335 SendMessageW(GetWindow(hwnd
, GW_OWNER
), WM_HELP
, 0, (LPARAM
)&hi
);
340 mbi
= (PMSGBOXINFO
)GetPropW(hwnd
, L
"ROS_MSGBOX");
343 switch(mbi
->dwStyle
& MB_TYPEMASK
)
345 case MB_ABORTRETRYIGNORE
:
349 EndDialog(hwnd
, IDCANCEL
);
355 EndDialog(hwnd
, 32000);
363 MessageBoxTimeoutIndirectW(
364 CONST MSGBOXPARAMSW
*lpMsgBoxParams
, UINT Timeout
)
367 DLGITEMTEMPLATE
*iico
, *itxt
;
368 NONCLIENTMETRICSW nclm
;
371 LPCWSTR caption
, text
;
375 int bufsize
, ret
, caplen
, textlen
, i
, btnleft
, btntop
, lmargin
;
377 LPCWSTR ButtonText
[MSGBOXEX_MAXBTNS
];
378 int ButtonLen
[MSGBOXEX_MAXBTNS
];
379 DLGITEMTEMPLATE
*ibtn
[MSGBOXEX_MAXBTNS
];
380 RECT btnrect
, txtrect
, rc
;
384 DWORD units
= GetDialogBaseUnits();
386 if (!lpMsgBoxParams
->lpszCaption
)
388 /* No caption, use the default one */
389 caplen
= LoadStringW(User32Instance
, IDS_ERROR
, (LPWSTR
)&caption
, 0);
391 else if (IS_INTRESOURCE(lpMsgBoxParams
->lpszCaption
))
393 /* User-defined resource string */
394 caplen
= LoadStringW(lpMsgBoxParams
->hInstance
, (UINT
)lpMsgBoxParams
->lpszCaption
, (LPWSTR
)&caption
, 0);
398 /* UNICODE string pointer */
399 caption
= lpMsgBoxParams
->lpszCaption
;
400 caplen
= strlenW(caption
);
403 if (!lpMsgBoxParams
->lpszText
)
405 /* No text, use blank */
409 else if (IS_INTRESOURCE(lpMsgBoxParams
->lpszText
))
411 /* User-defined resource string */
412 textlen
= LoadStringW(lpMsgBoxParams
->hInstance
, (UINT
)lpMsgBoxParams
->lpszText
, (LPWSTR
)&text
, 0);
416 /* UNICODE string pointer */
417 text
= lpMsgBoxParams
->lpszText
;
418 textlen
= strlenW(text
);
421 /* Create the selected buttons; unknown types will fall back to MB_OK */
422 i
= (lpMsgBoxParams
->dwStyle
& MB_TYPEMASK
);
423 if (i
>= ARRAYSIZE(MsgBtnInfo
))
426 /* Get buttons IDs */
427 Buttons
= MsgBtnInfo
[i
];
429 /* Add the Help button */
430 if (lpMsgBoxParams
->dwStyle
& MB_HELP
)
432 Buttons
.btnIdx
[Buttons
.btnCnt
] = IDHELP
;
433 Buttons
.btnIds
[Buttons
.btnCnt
] = IDS_HELP
;
437 switch(lpMsgBoxParams
->dwStyle
& MB_ICONMASK
)
439 case MB_ICONEXCLAMATION
:
440 Icon
= LoadIconW(0, IDI_EXCLAMATIONW
);
441 MessageBeep(MB_ICONEXCLAMATION
);
443 case MB_ICONQUESTION
:
444 Icon
= LoadIconW(0, IDI_QUESTIONW
);
445 MessageBeep(MB_ICONQUESTION
);
447 case MB_ICONASTERISK
:
448 Icon
= LoadIconW(0, IDI_ASTERISKW
);
449 MessageBeep(MB_ICONASTERISK
);
452 Icon
= LoadIconW(0, IDI_HANDW
);
453 MessageBeep(MB_ICONHAND
);
456 Icon
= LoadIconW(lpMsgBoxParams
->hInstance
, lpMsgBoxParams
->lpszIcon
);
460 /* By default, Windows 95/98/NT does not associate an icon to message boxes.
461 * So ReactOS should do the same.
469 bufsize
= sizeof(DLGTEMPLATE
) +
470 2 * sizeof(WORD
) + /* menu and class */
471 (caplen
+ 1) * sizeof(WCHAR
); /* title */
476 bufsize
= (bufsize
+ 3) & ~3;
477 bufsize
+= sizeof(DLGITEMTEMPLATE
) +
483 bufsize
= (bufsize
+ 3) & ~3;
484 bufsize
+= sizeof(DLGITEMTEMPLATE
) +
486 (textlen
+ 1) * sizeof(WCHAR
);
488 for (i
= 0; i
< Buttons
.btnCnt
; i
++)
490 /* Get the default text of the buttons */
491 if (Buttons
.btnIds
[i
])
493 ButtonLen
[i
] = LoadStringW(User32Instance
, Buttons
.btnIds
[i
], (LPWSTR
)&ButtonText
[i
], 0);
501 /* Space for buttons */
502 bufsize
= (bufsize
+ 3) & ~3;
503 bufsize
+= sizeof(DLGITEMTEMPLATE
) +
505 (ButtonLen
[i
] + 1) * sizeof(WCHAR
);
508 buf
= RtlAllocateHeap(GetProcessHeap(), 0, bufsize
);
515 nclm
.cbSize
= sizeof(nclm
);
516 SystemParametersInfoW (SPI_GETNONCLIENTMETRICS
, sizeof(nclm
), &nclm
, 0);
517 hFont
= CreateFontIndirectW(&nclm
.lfMessageFont
);
519 tpl
= (DLGTEMPLATE
*)buf
;
521 tpl
->style
= WS_CAPTION
| WS_POPUP
| WS_VISIBLE
| WS_CLIPSIBLINGS
| WS_SYSMENU
| DS_CENTER
| DS_MODALFRAME
| DS_NOIDLEMSG
;
522 tpl
->dwExtendedStyle
= WS_EX_DLGMODALFRAME
| WS_EX_WINDOWEDGE
| WS_EX_CONTROLPARENT
;
523 if(lpMsgBoxParams
->dwStyle
& MB_TOPMOST
)
524 tpl
->dwExtendedStyle
|= WS_EX_TOPMOST
;
525 if(lpMsgBoxParams
->dwStyle
& MB_RIGHT
)
526 tpl
->dwExtendedStyle
|= WS_EX_RIGHT
;
529 tpl
->cdit
= Buttons
.btnCnt
+ ((Icon
!= (HICON
)0) ? 1 : 0) + 1;
531 dest
= (BYTE
*)(tpl
+ 1);
533 *(WORD
*)dest
= 0; /* no menu */
534 *(((WORD
*)dest
) + 1) = 0; /* use default window class */
535 dest
+= 2 * sizeof(WORD
);
536 memcpy(dest
, caption
, caplen
* sizeof(WCHAR
));
537 dest
+= caplen
* sizeof(WCHAR
);
538 *(WCHAR
*)dest
= L
'\0';
539 dest
+= sizeof(WCHAR
);
544 dest
= (BYTE
*)(((ULONG_PTR
)dest
+ 3) & ~3);
545 iico
= (DLGITEMTEMPLATE
*)dest
;
546 iico
->style
= WS_CHILD
| WS_VISIBLE
| SS_ICON
;
547 iico
->dwExtendedStyle
= 0;
548 iico
->id
= MSGBOX_IDICON
;
550 dest
+= sizeof(DLGITEMTEMPLATE
);
551 *(WORD
*)dest
= 0xFFFF;
552 dest
+= sizeof(WORD
);
553 *(WORD
*)dest
= 0x0082; /* static control */
554 dest
+= sizeof(WORD
);
555 *(WORD
*)dest
= 0xFFFF;
556 dest
+= sizeof(WORD
);
558 dest
+= sizeof(WCHAR
);
560 dest
+= sizeof(WORD
);
563 /* create static for text */
564 dest
= (BYTE
*)(((UINT_PTR
)dest
+ 3) & ~3);
565 itxt
= (DLGITEMTEMPLATE
*)dest
;
566 itxt
->style
= WS_CHILD
| WS_VISIBLE
| SS_NOPREFIX
;
567 if(lpMsgBoxParams
->dwStyle
& MB_RIGHT
)
568 itxt
->style
|= SS_RIGHT
;
570 itxt
->style
|= SS_LEFT
;
571 itxt
->dwExtendedStyle
= 0;
572 itxt
->id
= MSGBOX_IDTEXT
;
573 dest
+= sizeof(DLGITEMTEMPLATE
);
574 *(WORD
*)dest
= 0xFFFF;
575 dest
+= sizeof(WORD
);
576 *(WORD
*)dest
= 0x0082; /* static control */
577 dest
+= sizeof(WORD
);
578 memcpy(dest
, text
, textlen
* sizeof(WCHAR
));
579 dest
+= textlen
* sizeof(WCHAR
);
581 dest
+= sizeof(WCHAR
);
583 dest
+= sizeof(WORD
);
585 hDC
= CreateCompatibleDC(0);
586 SelectObject(hDC
, hFont
);
591 btnrect
.left
= btnrect
.top
= 0;
593 for(i
= 0; i
< Buttons
.btnCnt
; i
++)
595 dest
= (BYTE
*)(((UINT_PTR
)dest
+ 3) & ~3);
596 ibtn
[i
] = (DLGITEMTEMPLATE
*)dest
;
597 ibtn
[i
]->style
= WS_CHILD
| WS_VISIBLE
| WS_TABSTOP
;
598 if(!defbtn
&& (i
== ((lpMsgBoxParams
->dwStyle
& MB_DEFMASK
) >> 8)))
600 ibtn
[i
]->style
|= BS_DEFPUSHBUTTON
;
601 mbi
.DefBtn
= Buttons
.btnIdx
[i
];
605 ibtn
[i
]->style
|= BS_PUSHBUTTON
;
606 ibtn
[i
]->dwExtendedStyle
= 0;
607 ibtn
[i
]->id
= Buttons
.btnIdx
[i
];
608 dest
+= sizeof(DLGITEMTEMPLATE
);
609 *(WORD
*)dest
= 0xFFFF;
610 dest
+= sizeof(WORD
);
611 *(WORD
*)dest
= 0x0080; /* button control */
612 dest
+= sizeof(WORD
);
613 memcpy(dest
, ButtonText
[i
], ButtonLen
[i
] * sizeof(WCHAR
));
614 dest
+= ButtonLen
[i
] * sizeof(WCHAR
);
616 dest
+= sizeof(WORD
);
618 dest
+= sizeof(WORD
);
620 // btnrect.right = btnrect.bottom = 0; // FIXME: Is it needed??
621 DrawTextW(hDC
, ButtonText
[i
], ButtonLen
[i
], &btnrect
, DT_LEFT
| DT_SINGLELINE
| DT_CALCRECT
);
622 btnsize
.cx
= max(btnsize
.cx
, btnrect
.right
);
623 btnsize
.cy
= max(btnsize
.cy
, btnrect
.bottom
);
626 /* make first button the default button if no other is */
629 ibtn
[0]->style
&= ~BS_PUSHBUTTON
;
630 ibtn
[0]->style
|= BS_DEFPUSHBUTTON
;
631 mbi
.DefBtn
= Buttons
.btnIdx
[0];
634 /* calculate position and size of controls */
635 txtrect
.right
= GetSystemMetrics(SM_CXSCREEN
) / 5 * 4;
637 txtrect
.right
-= GetSystemMetrics(SM_CXICON
) + MSGBOXEX_SPACING
;
638 txtrect
.top
= txtrect
.left
= txtrect
.bottom
= 0;
641 DrawTextW(hDC
, text
, textlen
, &txtrect
, DT_LEFT
| DT_NOPREFIX
| DT_WORDBREAK
| DT_CALCRECT
);
645 txtrect
.right
= txtrect
.left
+ 1;
646 txtrect
.bottom
= txtrect
.top
+ 1;
653 /* calculate position and size of the icon */
654 rc
.left
= rc
.bottom
= rc
.right
= 0;
659 rc
.right
= GetSystemMetrics(SM_CXICON
);
660 rc
.bottom
= GetSystemMetrics(SM_CYICON
);
661 #ifdef MSGBOX_ICONVCENTER
662 rc
.top
= MSGBOXEX_MARGIN
+ (max(txtrect
.bottom
, rc
.bottom
) / 2) - (GetSystemMetrics(SM_CYICON
) / 2);
663 rc
.top
= max(MSGBOXEX_SPACING
, rc
.top
);
665 rc
.top
= MSGBOXEX_MARGIN
;
667 btnleft
= (Buttons
.btnCnt
* (btnsize
.cx
+ MSGBOXEX_BUTTONSPACING
)) - MSGBOXEX_BUTTONSPACING
;
668 if(btnleft
> txtrect
.right
+ rc
.right
+ MSGBOXEX_SPACING
)
670 #ifdef MSGBOX_TEXTHCENTER
671 lmargin
= MSGBOXEX_MARGIN
+ ((btnleft
- txtrect
.right
- rc
.right
- MSGBOXEX_SPACING
) / 2);
673 lmargin
= MSGBOXEX_MARGIN
;
675 btnleft
= MSGBOXEX_MARGIN
;
679 lmargin
= MSGBOXEX_MARGIN
;
680 btnleft
= MSGBOXEX_MARGIN
+ ((txtrect
.right
+ rc
.right
+ MSGBOXEX_SPACING
) / 2) - (btnleft
/ 2);
683 iico
->x
= RESCALE_X(rc
.left
, units
);
684 iico
->y
= RESCALE_Y(rc
.top
, units
);
685 iico
->cx
= RESCALE_X(rc
.right
, units
);
686 iico
->cy
= RESCALE_Y(rc
.bottom
, units
);
687 btntop
= rc
.top
+ rc
.bottom
+ MSGBOXEX_SPACING
;
688 rc
.left
+= rc
.right
+ MSGBOXEX_SPACING
;
692 btnleft
= (Buttons
.btnCnt
* (btnsize
.cx
+ MSGBOXEX_BUTTONSPACING
)) - MSGBOXEX_BUTTONSPACING
;
693 if(btnleft
> txtrect
.right
)
695 #ifdef MSGBOX_TEXTHCENTER
696 lmargin
= MSGBOXEX_MARGIN
+ ((btnleft
- txtrect
.right
) / 2);
698 lmargin
= MSGBOXEX_MARGIN
;
700 btnleft
= MSGBOXEX_MARGIN
;
704 lmargin
= MSGBOXEX_MARGIN
;
705 btnleft
= MSGBOXEX_MARGIN
+ (txtrect
.right
/ 2) - (btnleft
/ 2);
709 /* calculate position of the text */
710 rc
.top
= MSGBOXEX_MARGIN
+ (rc
.bottom
/ 2) - (txtrect
.bottom
/ 2);
711 rc
.top
= max(rc
.top
, MSGBOXEX_MARGIN
);
712 /* calculate position of the buttons */
713 btntop
= max(rc
.top
+ txtrect
.bottom
+ MSGBOXEX_SPACING
, btntop
);
714 for(i
= 0; i
< Buttons
.btnCnt
; i
++)
716 ibtn
[i
]->x
= RESCALE_X(btnleft
, units
);
717 ibtn
[i
]->y
= RESCALE_Y(btntop
, units
);
718 ibtn
[i
]->cx
= RESCALE_X(btnsize
.cx
, units
);
719 ibtn
[i
]->cy
= RESCALE_Y(btnsize
.cy
, units
);
720 btnleft
+= btnsize
.cx
+ MSGBOXEX_BUTTONSPACING
;
722 /* calculate size and position of the messagebox window */
723 btnleft
= max(btnleft
- MSGBOXEX_BUTTONSPACING
, rc
.left
+ txtrect
.right
);
724 btnleft
+= MSGBOXEX_MARGIN
;
725 btntop
+= btnsize
.cy
+ MSGBOXEX_MARGIN
;
726 /* set size and position of the message static */
727 itxt
->x
= RESCALE_X(rc
.left
, units
);
728 itxt
->y
= RESCALE_Y(rc
.top
, units
);
729 itxt
->cx
= RESCALE_X(btnleft
- rc
.left
- MSGBOXEX_MARGIN
, units
);
730 itxt
->cy
= RESCALE_Y(txtrect
.bottom
, units
);
731 /* set size of the window */
732 tpl
->cx
= RESCALE_X(btnleft
, units
);
733 tpl
->cy
= RESCALE_Y(btntop
, units
);
735 /* finally show the messagebox */
738 mbi
.dwContextHelpId
= lpMsgBoxParams
->dwContextHelpId
;
739 mbi
.lpfnMsgBoxCallback
= lpMsgBoxParams
->lpfnMsgBoxCallback
;
740 mbi
.dwStyle
= lpMsgBoxParams
->dwStyle
;
741 mbi
.nButtons
= Buttons
.btnCnt
;
742 mbi
.Btns
= Buttons
.btnIdx
;
743 mbi
.Timeout
= Timeout
;
745 /* Pass on to Justin Case so he can peek the message? */
746 mbi
.cbSize
= lpMsgBoxParams
->cbSize
;
747 mbi
.hwndOwner
= lpMsgBoxParams
->hwndOwner
;
748 mbi
.hInstance
= lpMsgBoxParams
->hInstance
;
749 mbi
.lpszText
= lpMsgBoxParams
->lpszText
;
750 mbi
.lpszCaption
= lpMsgBoxParams
->lpszCaption
;
751 mbi
.lpszIcon
= lpMsgBoxParams
->lpszIcon
;
752 mbi
.dwLanguageId
= lpMsgBoxParams
->dwLanguageId
;
754 ret
= DialogBoxIndirectParamW(lpMsgBoxParams
->hInstance
, tpl
, lpMsgBoxParams
->hwndOwner
,
755 MessageBoxProc
, (LPARAM
)&mbi
);
760 RtlFreeHeap(GetProcessHeap(), 0, buf
);
764 /* FUNCTIONS *****************************************************************/
778 return MessageBoxExA(hWnd
, lpText
, lpCaption
, uType
, LANG_NEUTRAL
);
794 MSGBOXPARAMSA msgbox
;
796 msgbox
.cbSize
= sizeof(msgbox
);
797 msgbox
.hwndOwner
= hWnd
;
798 msgbox
.hInstance
= 0;
799 msgbox
.lpszText
= lpText
;
800 msgbox
.lpszCaption
= lpCaption
;
801 msgbox
.dwStyle
= uType
;
802 msgbox
.lpszIcon
= NULL
;
803 msgbox
.dwContextHelpId
= 0;
804 msgbox
.lpfnMsgBoxCallback
= NULL
;
805 msgbox
.dwLanguageId
= wLanguageId
;
807 return MessageBoxIndirectA(&msgbox
);
823 MSGBOXPARAMSW msgbox
;
825 msgbox
.cbSize
= sizeof(msgbox
);
826 msgbox
.hwndOwner
= hWnd
;
827 msgbox
.hInstance
= 0;
828 msgbox
.lpszText
= lpText
;
829 msgbox
.lpszCaption
= lpCaption
;
830 msgbox
.dwStyle
= uType
;
831 msgbox
.lpszIcon
= NULL
;
832 msgbox
.dwContextHelpId
= 0;
833 msgbox
.lpfnMsgBoxCallback
= NULL
;
834 msgbox
.dwLanguageId
= wLanguageId
;
836 return MessageBoxTimeoutIndirectW(&msgbox
, (UINT
)-1);
846 CONST MSGBOXPARAMSA
*lpMsgBoxParams
)
848 MSGBOXPARAMSW msgboxW
;
849 UNICODE_STRING textW
, captionW
, iconW
;
852 if (!IS_INTRESOURCE(lpMsgBoxParams
->lpszText
))
854 RtlCreateUnicodeStringFromAsciiz(&textW
, (PCSZ
)lpMsgBoxParams
->lpszText
);
856 * UNICODE_STRING objects are always allocated with an extra byte so you
857 * can null-term if you want
859 textW
.Buffer
[textW
.Length
/ sizeof(WCHAR
)] = L
'\0';
862 textW
.Buffer
= (LPWSTR
)lpMsgBoxParams
->lpszText
;
864 if (!IS_INTRESOURCE(lpMsgBoxParams
->lpszCaption
))
866 RtlCreateUnicodeStringFromAsciiz(&captionW
, (PCSZ
)lpMsgBoxParams
->lpszCaption
);
868 * UNICODE_STRING objects are always allocated with an extra byte so you
869 * can null-term if you want
871 captionW
.Buffer
[captionW
.Length
/ sizeof(WCHAR
)] = L
'\0';
874 captionW
.Buffer
= (LPWSTR
)lpMsgBoxParams
->lpszCaption
;
876 if(lpMsgBoxParams
->dwStyle
& MB_USERICON
)
878 if (!IS_INTRESOURCE(lpMsgBoxParams
->lpszIcon
))
880 RtlCreateUnicodeStringFromAsciiz(&iconW
, (PCSZ
)lpMsgBoxParams
->lpszIcon
);
882 * UNICODE_STRING objects are always allocated with an extra byte so you
883 * can null-term if you want
885 iconW
.Buffer
[iconW
.Length
/ sizeof(WCHAR
)] = L
'\0';
888 iconW
.Buffer
= (LPWSTR
)lpMsgBoxParams
->lpszIcon
;
893 msgboxW
.cbSize
= sizeof(msgboxW
);
894 msgboxW
.hwndOwner
= lpMsgBoxParams
->hwndOwner
;
895 msgboxW
.hInstance
= lpMsgBoxParams
->hInstance
;
896 msgboxW
.lpszText
= textW
.Buffer
;
897 msgboxW
.lpszCaption
= captionW
.Buffer
;
898 msgboxW
.dwStyle
= lpMsgBoxParams
->dwStyle
;
899 msgboxW
.lpszIcon
= iconW
.Buffer
;
900 msgboxW
.dwContextHelpId
= lpMsgBoxParams
->dwContextHelpId
;
901 msgboxW
.lpfnMsgBoxCallback
= lpMsgBoxParams
->lpfnMsgBoxCallback
;
902 msgboxW
.dwLanguageId
= lpMsgBoxParams
->dwLanguageId
;
904 ret
= MessageBoxTimeoutIndirectW(&msgboxW
, (UINT
)-1);
906 if (!IS_INTRESOURCE(lpMsgBoxParams
->lpszText
))
907 RtlFreeUnicodeString(&textW
);
909 if (!IS_INTRESOURCE(lpMsgBoxParams
->lpszCaption
))
910 RtlFreeUnicodeString(&captionW
);
912 if ((lpMsgBoxParams
->dwStyle
& MB_USERICON
) && !IS_INTRESOURCE(iconW
.Buffer
))
913 RtlFreeUnicodeString(&iconW
);
925 CONST MSGBOXPARAMSW
*lpMsgBoxParams
)
927 return MessageBoxTimeoutIndirectW(lpMsgBoxParams
, (UINT
)-1);
942 return MessageBoxExW(hWnd
, lpText
, lpCaption
, uType
, LANG_NEUTRAL
);
958 MSGBOXPARAMSW msgboxW
;
959 UNICODE_STRING textW
, captionW
;
962 if (!IS_INTRESOURCE(lpText
))
963 RtlCreateUnicodeStringFromAsciiz(&textW
, (PCSZ
)lpText
);
965 textW
.Buffer
= (LPWSTR
)lpText
;
967 if (!IS_INTRESOURCE(lpCaption
))
968 RtlCreateUnicodeStringFromAsciiz(&captionW
, (PCSZ
)lpCaption
);
970 captionW
.Buffer
= (LPWSTR
)lpCaption
;
972 msgboxW
.cbSize
= sizeof(msgboxW
);
973 msgboxW
.hwndOwner
= hWnd
;
974 msgboxW
.hInstance
= 0;
975 msgboxW
.lpszText
= textW
.Buffer
;
976 msgboxW
.lpszCaption
= captionW
.Buffer
;
977 msgboxW
.dwStyle
= uType
;
978 msgboxW
.lpszIcon
= NULL
;
979 msgboxW
.dwContextHelpId
= 0;
980 msgboxW
.lpfnMsgBoxCallback
= NULL
;
981 msgboxW
.dwLanguageId
= wLanguageId
;
983 ret
= MessageBoxTimeoutIndirectW(&msgboxW
, (UINT
)dwTime
);
985 if (!IS_INTRESOURCE(textW
.Buffer
))
986 RtlFreeUnicodeString(&textW
);
988 if (!IS_INTRESOURCE(captionW
.Buffer
))
989 RtlFreeUnicodeString(&captionW
);
1007 MSGBOXPARAMSW msgbox
;
1009 msgbox
.cbSize
= sizeof(msgbox
);
1010 msgbox
.hwndOwner
= hWnd
;
1011 msgbox
.hInstance
= 0;
1012 msgbox
.lpszText
= lpText
;
1013 msgbox
.lpszCaption
= lpCaption
;
1014 msgbox
.dwStyle
= uType
;
1015 msgbox
.lpszIcon
= NULL
;
1016 msgbox
.dwContextHelpId
= 0;
1017 msgbox
.lpfnMsgBoxCallback
= NULL
;
1018 msgbox
.dwLanguageId
= wLanguageId
;
1020 return MessageBoxTimeoutIndirectW(&msgbox
, (UINT
)dwTime
);
1029 SoftModalMessageBox(DWORD Unknown0
)
1041 MessageBeep(UINT uType
)
1043 return NtUserxMessageBeep(uType
);
1050 * See: https://msdn.microsoft.com/en-us/library/windows/desktop/dn910915(v=vs.85).aspx
1051 * and: http://undoc.airesoft.co.uk/user32.dll/MB_GetString.php
1052 * for more information.
1054 LPCWSTR WINAPI
MB_GetString(UINT wBtn
)
1056 LPCWSTR btnStr
= NULL
;
1058 /* The allowable IDs are between IDOK (0) and IDCONTINUE (11) inclusive */
1059 if (wBtn
>= IDCONTINUE
)
1062 LoadStringW(User32Instance
, wBtn
, (LPWSTR
)&btnStr
, 0);