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
34 WINE_DEFAULT_DEBUG_CHANNEL(user32
);
36 /* DEFINES *******************************************************************/
38 #define MSGBOX_IDICON (1088)
39 #define MSGBOX_IDTEXT (0xffff)
41 #define IDI_HANDW MAKEINTRESOURCEW(32513)
42 #define IDI_QUESTIONW MAKEINTRESOURCEW(32514)
43 #define IDI_EXCLAMATIONW MAKEINTRESOURCEW(32515)
44 #define IDI_ASTERISKW MAKEINTRESOURCEW(32516)
45 #define IDI_WINLOGOW MAKEINTRESOURCEW(32517)
48 /* MessageBox metrics */
53 #define MSGBOXEX_SPACING (16)
54 #define MSGBOXEX_BUTTONSPACING (6)
55 #define MSGBOXEX_MARGIN (12)
56 #define MSGBOXEX_MAXBTNSTR (32)
57 #define MSGBOXEX_MAXBTNS (4)
59 /* Rescale logical coordinates */
60 #define RESCALE_X(_x, _unit) (((_x) * 4 + LOWORD(_unit) - 1) / LOWORD(_unit))
61 #define RESCALE_Y(_y, _unit) (((_y) * 8 + HIWORD(_unit) - 1) / HIWORD(_unit))
64 /* MessageBox button helpers */
66 #define DECLARE_MB_1(_btn0) \
67 { 1, { ID##_btn0, 0, 0 }, { IDS_##_btn0, 0, 0 } }
69 #define DECLARE_MB_2(_btn0, _btn1) \
70 { 2, { ID##_btn0, ID##_btn1, 0 }, { IDS_##_btn0, IDS_##_btn1, 0 } }
72 #define DECLARE_MB_3(_btn0, _btn1, _btn2) \
73 { 3, { ID##_btn0, ID##_btn1, ID##_btn2 }, { IDS_##_btn0, IDS_##_btn1, IDS_##_btn2 } }
75 typedef struct _MSGBTNINFO
78 LONG btnIdx
[MSGBOXEX_MAXBTNS
];
79 UINT btnIds
[MSGBOXEX_MAXBTNS
];
80 } MSGBTNINFO
, *PMSGBTNINFO
;
82 /* Default MessageBox buttons */
83 static const MSGBTNINFO MsgBtnInfo
[] =
88 DECLARE_MB_2(OK
, CANCEL
),
89 /* MB_ABORTRETRYIGNORE (2) */
90 DECLARE_MB_3(ABORT
, RETRY
, IGNORE
),
91 /* MB_YESNOCANCEL (3) */
92 DECLARE_MB_3(YES
, NO
, CANCEL
),
94 DECLARE_MB_2(YES
, NO
),
95 /* MB_RETRYCANCEL (5) */
96 DECLARE_MB_2(RETRY
, CANCEL
),
97 /* MB_CANCELTRYCONTINUE (6) */
98 DECLARE_MB_3(CANCEL
, TRYAGAIN
, CONTINUE
)
101 typedef struct _MSGBOXINFO
103 MSGBOXPARAMSW
; // Wine passes this too.
111 } MSGBOXINFO
, *PMSGBOXINFO
;
113 /* INTERNAL FUNCTIONS ********************************************************/
115 static VOID
MessageBoxTextToClipboard(HWND DialogWindow
)
119 int cchTotal
, cchTitle
, cchText
, cchButton
, i
, n
, cchBuffer
;
120 LPWSTR pszBuffer
, pszBufferPos
, pMessageBoxText
, pszTitle
, pszText
, pszButton
;
121 WCHAR szButton
[MSGBOXEX_MAXBTNSTR
];
124 static const WCHAR szLine
[] = L
"---------------------------\r\n";
126 mbi
= (PMSGBOXINFO
)GetPropW(DialogWindow
, L
"ROS_MSGBOX");
127 hwndText
= GetDlgItem(DialogWindow
, MSGBOX_IDTEXT
);
128 cchTitle
= GetWindowTextLengthW(DialogWindow
) + 1;
129 cchText
= GetWindowTextLengthW(hwndText
) + 1;
134 pMessageBoxText
= (LPWSTR
)RtlAllocateHeap(GetProcessHeap(), 0, (cchTitle
+ cchText
) * sizeof(WCHAR
));
136 if (pMessageBoxText
== NULL
)
138 RtlFreeHeap(GetProcessHeap(), 0, pMessageBoxText
);
142 pszTitle
= pMessageBoxText
;
143 pszText
= pMessageBoxText
+ cchTitle
;
145 if (GetWindowTextW(DialogWindow
, pszTitle
, cchTitle
) == 0 ||
146 GetWindowTextW(hwndText
, pszText
, cchText
) == 0)
148 RtlFreeHeap(GetProcessHeap(), 0, pMessageBoxText
);
153 * Calculate the total buffer size.
155 cchTotal
= 6 + cchTitle
+ cchText
+ (lstrlenW(szLine
) * 4) + (mbi
->nButtons
* MSGBOXEX_MAXBTNSTR
+ 3);
157 hGlobal
= GlobalAlloc(GHND
, cchTotal
* sizeof(WCHAR
));
159 pszBuffer
= (LPWSTR
)GlobalLock(hGlobal
);
161 if (pszBuffer
== NULL
)
163 RtlFreeHeap(GetProcessHeap(), 0, pMessageBoxText
);
169 * First format title and text.
176 cchBuffer
= wsprintfW(pszBuffer
, L
"%s%s\r\n%s%s\r\n%s", szLine
, pszTitle
, szLine
, pszText
, szLine
);
177 pszBufferPos
= pszBuffer
+ cchBuffer
;
179 for (i
= 0; i
< mbi
->nButtons
; i
++)
181 GetDlgItemTextW(DialogWindow
, mbi
->Btns
[i
], szButton
, MSGBOXEX_MAXBTNSTR
);
183 cchButton
= strlenW(szButton
);
184 pszButton
= szButton
;
186 /* Skip '&' character. */
187 if (szButton
[0] == '&')
189 pszButton
= pszButton
+ 1;
190 cchButton
= cchButton
- 1;
193 for (n
= 0; n
< cchButton
; n
++)
194 *(pszBufferPos
++) = pszButton
[n
];
197 *(pszBufferPos
++) = L
' ';
198 *(pszBufferPos
++) = L
' ';
199 *(pszBufferPos
++) = L
' ';
202 wsprintfW(pszBufferPos
, L
"\r\n%s", szLine
);
204 GlobalUnlock(hGlobal
);
206 if (OpenClipboard(DialogWindow
))
209 SetClipboardData(CF_UNICODETEXT
, hGlobal
);
216 RtlFreeHeap(GetProcessHeap(), 0, pMessageBoxText
);
219 static INT_PTR CALLBACK
MessageBoxProc(
220 HWND hwnd
, UINT message
,
221 WPARAM wParam
, LPARAM lParam
)
232 mbi
= (PMSGBOXINFO
)lParam
;
234 SetWindowLongPtrW(hwnd
, GWLP_USERDATA
, (LONG_PTR
)mbi
);
235 NtUserxSetMessageBox(hwnd
);
237 if (!GetPropW(hwnd
, L
"ROS_MSGBOX"))
239 SetPropW(hwnd
, L
"ROS_MSGBOX", (HANDLE
)lParam
);
241 if (mbi
->dwContextHelpId
)
242 SetWindowContextHelpId(hwnd
, mbi
->dwContextHelpId
);
246 SendDlgItemMessageW(hwnd
, MSGBOX_IDICON
, STM_SETICON
, (WPARAM
)mbi
->Icon
, 0);
247 Alert
= ALERT_SYSTEM_WARNING
;
249 else // Setup the rest of the alerts.
251 switch (mbi
->dwStyle
& MB_ICONMASK
)
254 Alert
= ALERT_SYSTEM_WARNING
;
257 Alert
= ALERT_SYSTEM_ERROR
;
259 case MB_ICONQUESTION
:
260 Alert
= ALERT_SYSTEM_QUERY
;
263 Alert
= ALERT_SYSTEM_INFORMATIONAL
;
267 /* Send out the alert notifications. */
268 NotifyWinEvent(EVENT_SYSTEM_ALERT
, hwnd
, OBJID_ALERT
, Alert
);
270 /* set control fonts */
271 SendDlgItemMessageW(hwnd
, MSGBOX_IDTEXT
, WM_SETFONT
, (WPARAM
)mbi
->Font
, 0);
272 for (i
= 0; i
< mbi
->nButtons
; i
++)
274 SendDlgItemMessageW(hwnd
, mbi
->Btns
[i
], WM_SETFONT
, (WPARAM
)mbi
->Font
, 0);
276 switch (mbi
->dwStyle
& MB_TYPEMASK
)
278 case MB_ABORTRETRYIGNORE
:
280 RemoveMenu(GetSystemMenu(hwnd
, FALSE
), SC_CLOSE
, MF_BYCOMMAND
);
283 SetFocus(GetDlgItem(hwnd
, mbi
->DefBtn
));
284 if (mbi
->Timeout
&& (mbi
->Timeout
!= (UINT
)-1))
285 SetTimer(hwnd
, 0, mbi
->Timeout
, NULL
);
291 switch (LOWORD(wParam
))
302 EndDialog(hwnd
, wParam
);
305 /* send WM_HELP message to messagebox window */
306 hi
.cbSize
= sizeof(HELPINFO
);
307 hi
.iContextType
= HELPINFO_WINDOW
;
308 hi
.iCtrlId
= LOWORD(wParam
);
309 hi
.hItemHandle
= (HANDLE
)lParam
;
311 GetCursorPos(&hi
.MousePos
);
312 SendMessageW(hwnd
, WM_HELP
, 0, (LPARAM
)&hi
);
318 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
);
342 mbi
= (PMSGBOXINFO
)GetPropW(hwnd
, L
"ROS_MSGBOX");
345 switch (mbi
->dwStyle
& MB_TYPEMASK
)
347 case MB_ABORTRETRYIGNORE
:
351 EndDialog(hwnd
, IDCANCEL
);
358 EndDialog(hwnd
, 32000);
366 MessageBoxTimeoutIndirectW(
367 CONST MSGBOXPARAMSW
*lpMsgBoxParams
, UINT Timeout
)
370 DLGITEMTEMPLATE
*iico
, *itxt
;
371 NONCLIENTMETRICSW nclm
;
374 LPCWSTR caption
, text
;
378 int bufsize
, ret
, caplen
, textlen
, i
, btnleft
, btntop
, lmargin
;
380 LPCWSTR ButtonText
[MSGBOXEX_MAXBTNS
];
381 int ButtonLen
[MSGBOXEX_MAXBTNS
];
382 DLGITEMTEMPLATE
*ibtn
[MSGBOXEX_MAXBTNS
];
383 RECT btnrect
, txtrect
, rc
;
387 DWORD units
= GetDialogBaseUnits();
389 if (!lpMsgBoxParams
->lpszCaption
)
391 /* No caption, use the default one */
392 caplen
= LoadStringW(User32Instance
, IDS_ERROR
, (LPWSTR
)&caption
, 0);
394 else if (IS_INTRESOURCE(lpMsgBoxParams
->lpszCaption
))
396 /* User-defined resource string */
397 caplen
= LoadStringW(lpMsgBoxParams
->hInstance
, PtrToUlong(lpMsgBoxParams
->lpszCaption
), (LPWSTR
)&caption
, 0);
401 /* UNICODE string pointer */
402 caption
= lpMsgBoxParams
->lpszCaption
;
403 caplen
= strlenW(caption
);
406 if (!lpMsgBoxParams
->lpszText
)
408 /* No text, use blank */
412 else if (IS_INTRESOURCE(lpMsgBoxParams
->lpszText
))
414 /* User-defined resource string */
415 textlen
= LoadStringW(lpMsgBoxParams
->hInstance
, PtrToUlong(lpMsgBoxParams
->lpszText
), (LPWSTR
)&text
, 0);
419 /* UNICODE string pointer */
420 text
= lpMsgBoxParams
->lpszText
;
421 textlen
= strlenW(text
);
424 /* Create the selected buttons; unknown types will fall back to MB_OK */
425 i
= (lpMsgBoxParams
->dwStyle
& MB_TYPEMASK
);
426 if (i
>= ARRAYSIZE(MsgBtnInfo
))
429 /* Get buttons IDs */
430 Buttons
= MsgBtnInfo
[i
];
432 /* Add the Help button */
433 if (lpMsgBoxParams
->dwStyle
& MB_HELP
)
435 Buttons
.btnIdx
[Buttons
.btnCnt
] = IDHELP
;
436 Buttons
.btnIds
[Buttons
.btnCnt
] = IDS_HELP
;
440 switch (lpMsgBoxParams
->dwStyle
& MB_ICONMASK
)
442 case MB_ICONEXCLAMATION
:
443 Icon
= LoadIconW(0, IDI_EXCLAMATIONW
);
444 MessageBeep(MB_ICONEXCLAMATION
);
446 case MB_ICONQUESTION
:
447 Icon
= LoadIconW(0, IDI_QUESTIONW
);
448 MessageBeep(MB_ICONQUESTION
);
450 case MB_ICONASTERISK
:
451 Icon
= LoadIconW(0, IDI_ASTERISKW
);
452 MessageBeep(MB_ICONASTERISK
);
455 Icon
= LoadIconW(0, IDI_HANDW
);
456 MessageBeep(MB_ICONHAND
);
459 Icon
= LoadIconW(lpMsgBoxParams
->hInstance
, lpMsgBoxParams
->lpszIcon
);
463 /* By default, Windows 95/98/NT does not associate an icon to message boxes.
464 * So ReactOS should do the same.
472 bufsize
= sizeof(DLGTEMPLATE
) +
473 2 * sizeof(WORD
) + /* menu and class */
474 (caplen
+ 1) * sizeof(WCHAR
); /* title */
479 bufsize
= (bufsize
+ 3) & ~3;
480 bufsize
+= sizeof(DLGITEMTEMPLATE
) +
486 bufsize
= (bufsize
+ 3) & ~3;
487 bufsize
+= sizeof(DLGITEMTEMPLATE
) +
489 (textlen
+ 1) * sizeof(WCHAR
);
491 for (i
= 0; i
< Buttons
.btnCnt
; i
++)
493 /* Get the default text of the buttons */
494 if (Buttons
.btnIds
[i
])
496 ButtonLen
[i
] = LoadStringW(User32Instance
, Buttons
.btnIds
[i
], (LPWSTR
)&ButtonText
[i
], 0);
504 /* Space for buttons */
505 bufsize
= (bufsize
+ 3) & ~3;
506 bufsize
+= sizeof(DLGITEMTEMPLATE
) +
508 (ButtonLen
[i
] + 1) * sizeof(WCHAR
);
511 buf
= RtlAllocateHeap(GetProcessHeap(), 0, bufsize
);
518 nclm
.cbSize
= sizeof(nclm
);
519 SystemParametersInfoW (SPI_GETNONCLIENTMETRICS
, sizeof(nclm
), &nclm
, 0);
520 hFont
= CreateFontIndirectW(&nclm
.lfMessageFont
);
522 tpl
= (DLGTEMPLATE
*)buf
;
524 tpl
->style
= WS_CAPTION
| WS_POPUP
| WS_VISIBLE
| WS_CLIPSIBLINGS
| WS_SYSMENU
| DS_CENTER
| DS_MODALFRAME
| DS_NOIDLEMSG
;
525 tpl
->dwExtendedStyle
= WS_EX_DLGMODALFRAME
| WS_EX_WINDOWEDGE
| WS_EX_CONTROLPARENT
;
526 if (lpMsgBoxParams
->dwStyle
& MB_TOPMOST
)
527 tpl
->dwExtendedStyle
|= WS_EX_TOPMOST
;
528 if (lpMsgBoxParams
->dwStyle
& MB_RIGHT
)
529 tpl
->dwExtendedStyle
|= WS_EX_RIGHT
;
532 tpl
->cdit
= Buttons
.btnCnt
+ ((Icon
!= (HICON
)0) ? 1 : 0) + 1;
534 dest
= (BYTE
*)(tpl
+ 1);
536 *(WORD
*)dest
= 0; /* no menu */
537 *(((WORD
*)dest
) + 1) = 0; /* use default window class */
538 dest
+= 2 * sizeof(WORD
);
539 memcpy(dest
, caption
, caplen
* sizeof(WCHAR
));
540 dest
+= caplen
* sizeof(WCHAR
);
541 *(WCHAR
*)dest
= L
'\0';
542 dest
+= sizeof(WCHAR
);
547 dest
= (BYTE
*)(((ULONG_PTR
)dest
+ 3) & ~3);
548 iico
= (DLGITEMTEMPLATE
*)dest
;
549 iico
->style
= WS_CHILD
| WS_VISIBLE
| SS_ICON
;
550 iico
->dwExtendedStyle
= 0;
551 iico
->id
= MSGBOX_IDICON
;
553 dest
+= sizeof(DLGITEMTEMPLATE
);
554 *(WORD
*)dest
= 0xFFFF;
555 dest
+= sizeof(WORD
);
556 *(WORD
*)dest
= 0x0082; /* static control */
557 dest
+= sizeof(WORD
);
558 *(WORD
*)dest
= 0xFFFF;
559 dest
+= sizeof(WORD
);
561 dest
+= sizeof(WCHAR
);
563 dest
+= sizeof(WORD
);
566 /* create static for text */
567 dest
= (BYTE
*)(((UINT_PTR
)dest
+ 3) & ~3);
568 itxt
= (DLGITEMTEMPLATE
*)dest
;
569 itxt
->style
= WS_CHILD
| WS_VISIBLE
| SS_NOPREFIX
;
570 if (lpMsgBoxParams
->dwStyle
& MB_RIGHT
)
571 itxt
->style
|= SS_RIGHT
;
573 itxt
->style
|= SS_LEFT
;
574 itxt
->dwExtendedStyle
= 0;
575 itxt
->id
= MSGBOX_IDTEXT
;
576 dest
+= sizeof(DLGITEMTEMPLATE
);
577 *(WORD
*)dest
= 0xFFFF;
578 dest
+= sizeof(WORD
);
579 *(WORD
*)dest
= 0x0082; /* static control */
580 dest
+= sizeof(WORD
);
581 memcpy(dest
, text
, textlen
* sizeof(WCHAR
));
582 dest
+= textlen
* sizeof(WCHAR
);
584 dest
+= sizeof(WCHAR
);
586 dest
+= sizeof(WORD
);
588 hDC
= CreateCompatibleDC(0);
589 SelectObject(hDC
, hFont
);
594 btnrect
.left
= btnrect
.top
= 0;
596 for (i
= 0; i
< Buttons
.btnCnt
; i
++)
598 dest
= (BYTE
*)(((UINT_PTR
)dest
+ 3) & ~3);
599 ibtn
[i
] = (DLGITEMTEMPLATE
*)dest
;
600 ibtn
[i
]->style
= WS_CHILD
| WS_VISIBLE
| WS_TABSTOP
;
601 if (!defbtn
&& (i
== ((lpMsgBoxParams
->dwStyle
& MB_DEFMASK
) >> 8)))
603 ibtn
[i
]->style
|= BS_DEFPUSHBUTTON
;
604 mbi
.DefBtn
= Buttons
.btnIdx
[i
];
609 ibtn
[i
]->style
|= BS_PUSHBUTTON
;
611 ibtn
[i
]->dwExtendedStyle
= 0;
612 ibtn
[i
]->id
= Buttons
.btnIdx
[i
];
613 dest
+= sizeof(DLGITEMTEMPLATE
);
614 *(WORD
*)dest
= 0xFFFF;
615 dest
+= sizeof(WORD
);
616 *(WORD
*)dest
= 0x0080; /* button control */
617 dest
+= sizeof(WORD
);
618 memcpy(dest
, ButtonText
[i
], ButtonLen
[i
] * sizeof(WCHAR
));
619 dest
+= ButtonLen
[i
] * sizeof(WCHAR
);
621 dest
+= sizeof(WORD
);
623 dest
+= sizeof(WORD
);
625 // btnrect.right = btnrect.bottom = 0; // FIXME: Is it needed??
626 DrawTextW(hDC
, ButtonText
[i
], ButtonLen
[i
], &btnrect
, DT_LEFT
| DT_SINGLELINE
| DT_CALCRECT
);
627 btnsize
.cx
= max(btnsize
.cx
, btnrect
.right
);
628 btnsize
.cy
= max(btnsize
.cy
, btnrect
.bottom
);
631 /* make first button the default button if no other is */
634 ibtn
[0]->style
&= ~BS_PUSHBUTTON
;
635 ibtn
[0]->style
|= BS_DEFPUSHBUTTON
;
636 mbi
.DefBtn
= Buttons
.btnIdx
[0];
639 /* calculate position and size of controls */
640 txtrect
.right
= GetSystemMetrics(SM_CXSCREEN
) / 5 * 4;
642 txtrect
.right
-= GetSystemMetrics(SM_CXICON
) + MSGBOXEX_SPACING
;
643 txtrect
.top
= txtrect
.left
= txtrect
.bottom
= 0;
646 DrawTextW(hDC
, text
, textlen
, &txtrect
, DT_LEFT
| DT_NOPREFIX
| DT_WORDBREAK
| DT_CALCRECT
);
650 txtrect
.right
= txtrect
.left
+ 1;
651 txtrect
.bottom
= txtrect
.top
+ 1;
658 /* calculate position and size of the icon */
659 rc
.left
= rc
.bottom
= rc
.right
= 0;
664 rc
.right
= GetSystemMetrics(SM_CXICON
);
665 rc
.bottom
= GetSystemMetrics(SM_CYICON
);
666 #ifdef MSGBOX_ICONVCENTER
667 rc
.top
= MSGBOXEX_MARGIN
+ (max(txtrect
.bottom
, rc
.bottom
) / 2) - (GetSystemMetrics(SM_CYICON
) / 2);
668 rc
.top
= max(MSGBOXEX_SPACING
, rc
.top
);
670 rc
.top
= MSGBOXEX_MARGIN
;
672 btnleft
= (Buttons
.btnCnt
* (btnsize
.cx
+ MSGBOXEX_BUTTONSPACING
)) - MSGBOXEX_BUTTONSPACING
;
673 if (btnleft
> txtrect
.right
+ rc
.right
+ MSGBOXEX_SPACING
)
675 #ifdef MSGBOX_TEXTHCENTER
676 lmargin
= MSGBOXEX_MARGIN
+ ((btnleft
- txtrect
.right
- rc
.right
- MSGBOXEX_SPACING
) / 2);
678 lmargin
= MSGBOXEX_MARGIN
;
680 btnleft
= MSGBOXEX_MARGIN
;
684 lmargin
= MSGBOXEX_MARGIN
;
685 btnleft
= MSGBOXEX_MARGIN
+ ((txtrect
.right
+ rc
.right
+ MSGBOXEX_SPACING
) / 2) - (btnleft
/ 2);
688 iico
->x
= RESCALE_X(rc
.left
, units
);
689 iico
->y
= RESCALE_Y(rc
.top
, units
);
690 iico
->cx
= RESCALE_X(rc
.right
, units
);
691 iico
->cy
= RESCALE_Y(rc
.bottom
, units
);
692 btntop
= rc
.top
+ rc
.bottom
+ MSGBOXEX_SPACING
;
693 rc
.left
+= rc
.right
+ MSGBOXEX_SPACING
;
697 btnleft
= (Buttons
.btnCnt
* (btnsize
.cx
+ MSGBOXEX_BUTTONSPACING
)) - MSGBOXEX_BUTTONSPACING
;
698 if (btnleft
> txtrect
.right
)
700 #ifdef MSGBOX_TEXTHCENTER
701 lmargin
= MSGBOXEX_MARGIN
+ ((btnleft
- txtrect
.right
) / 2);
703 lmargin
= MSGBOXEX_MARGIN
;
705 btnleft
= MSGBOXEX_MARGIN
;
709 lmargin
= MSGBOXEX_MARGIN
;
710 btnleft
= MSGBOXEX_MARGIN
+ (txtrect
.right
/ 2) - (btnleft
/ 2);
714 /* calculate position of the text */
715 rc
.top
= MSGBOXEX_MARGIN
+ (rc
.bottom
/ 2) - (txtrect
.bottom
/ 2);
716 rc
.top
= max(rc
.top
, MSGBOXEX_MARGIN
);
717 /* calculate position of the buttons */
718 btntop
= max(rc
.top
+ txtrect
.bottom
+ MSGBOXEX_SPACING
, btntop
);
719 for (i
= 0; i
< Buttons
.btnCnt
; i
++)
721 ibtn
[i
]->x
= RESCALE_X(btnleft
, units
);
722 ibtn
[i
]->y
= RESCALE_Y(btntop
, units
);
723 ibtn
[i
]->cx
= RESCALE_X(btnsize
.cx
, units
);
724 ibtn
[i
]->cy
= RESCALE_Y(btnsize
.cy
, units
);
725 btnleft
+= btnsize
.cx
+ MSGBOXEX_BUTTONSPACING
;
727 /* calculate size and position of the messagebox window */
728 btnleft
= max(btnleft
- MSGBOXEX_BUTTONSPACING
, rc
.left
+ txtrect
.right
);
729 btnleft
+= MSGBOXEX_MARGIN
;
730 btntop
+= btnsize
.cy
+ MSGBOXEX_MARGIN
;
731 /* set size and position of the message static */
732 itxt
->x
= RESCALE_X(rc
.left
, units
);
733 itxt
->y
= RESCALE_Y(rc
.top
, units
);
734 itxt
->cx
= RESCALE_X(btnleft
- rc
.left
- MSGBOXEX_MARGIN
, units
);
735 itxt
->cy
= RESCALE_Y(txtrect
.bottom
, units
);
736 /* set size of the window */
737 tpl
->cx
= RESCALE_X(btnleft
, units
);
738 tpl
->cy
= RESCALE_Y(btntop
, units
);
740 /* finally show the messagebox */
743 mbi
.dwContextHelpId
= lpMsgBoxParams
->dwContextHelpId
;
744 mbi
.lpfnMsgBoxCallback
= lpMsgBoxParams
->lpfnMsgBoxCallback
;
745 mbi
.dwStyle
= lpMsgBoxParams
->dwStyle
;
746 mbi
.nButtons
= Buttons
.btnCnt
;
747 mbi
.Btns
= Buttons
.btnIdx
;
748 mbi
.Timeout
= Timeout
;
750 /* Pass on to Justin Case so he can peek the message? */
751 mbi
.cbSize
= lpMsgBoxParams
->cbSize
;
752 mbi
.hwndOwner
= lpMsgBoxParams
->hwndOwner
;
753 mbi
.hInstance
= lpMsgBoxParams
->hInstance
;
754 mbi
.lpszText
= lpMsgBoxParams
->lpszText
;
755 mbi
.lpszCaption
= lpMsgBoxParams
->lpszCaption
;
756 mbi
.lpszIcon
= lpMsgBoxParams
->lpszIcon
;
757 mbi
.dwLanguageId
= lpMsgBoxParams
->dwLanguageId
;
759 ret
= DialogBoxIndirectParamW(lpMsgBoxParams
->hInstance
, tpl
, lpMsgBoxParams
->hwndOwner
,
760 MessageBoxProc
, (LPARAM
)&mbi
);
765 RtlFreeHeap(GetProcessHeap(), 0, buf
);
769 /* FUNCTIONS *****************************************************************/
783 return MessageBoxExA(hWnd
, lpText
, lpCaption
, uType
, LANG_NEUTRAL
);
794 IN LPCWSTR lpCaption
,
797 return MessageBoxExW(hWnd
, lpText
, lpCaption
, uType
, LANG_NEUTRAL
);
813 MSGBOXPARAMSA msgbox
;
815 msgbox
.cbSize
= sizeof(msgbox
);
816 msgbox
.hwndOwner
= hWnd
;
817 msgbox
.hInstance
= 0;
818 msgbox
.lpszText
= lpText
;
819 msgbox
.lpszCaption
= lpCaption
;
820 msgbox
.dwStyle
= uType
;
821 msgbox
.lpszIcon
= NULL
;
822 msgbox
.dwContextHelpId
= 0;
823 msgbox
.lpfnMsgBoxCallback
= NULL
;
824 msgbox
.dwLanguageId
= wLanguageId
;
826 return MessageBoxIndirectA(&msgbox
);
837 IN LPCWSTR lpCaption
,
841 MSGBOXPARAMSW msgbox
;
843 msgbox
.cbSize
= sizeof(msgbox
);
844 msgbox
.hwndOwner
= hWnd
;
845 msgbox
.hInstance
= 0;
846 msgbox
.lpszText
= lpText
;
847 msgbox
.lpszCaption
= lpCaption
;
848 msgbox
.dwStyle
= uType
;
849 msgbox
.lpszIcon
= NULL
;
850 msgbox
.dwContextHelpId
= 0;
851 msgbox
.lpfnMsgBoxCallback
= NULL
;
852 msgbox
.dwLanguageId
= wLanguageId
;
854 return MessageBoxTimeoutIndirectW(&msgbox
, (UINT
)-1);
864 IN CONST MSGBOXPARAMSA
* lpMsgBoxParams
)
866 MSGBOXPARAMSW msgboxW
;
867 UNICODE_STRING textW
, captionW
, iconW
;
870 if (!IS_INTRESOURCE(lpMsgBoxParams
->lpszText
))
872 RtlCreateUnicodeStringFromAsciiz(&textW
, (PCSZ
)lpMsgBoxParams
->lpszText
);
874 * UNICODE_STRING objects are always allocated with an extra byte so you
875 * can null-term if you want
877 textW
.Buffer
[textW
.Length
/ sizeof(WCHAR
)] = L
'\0';
880 textW
.Buffer
= (LPWSTR
)lpMsgBoxParams
->lpszText
;
882 if (!IS_INTRESOURCE(lpMsgBoxParams
->lpszCaption
))
884 RtlCreateUnicodeStringFromAsciiz(&captionW
, (PCSZ
)lpMsgBoxParams
->lpszCaption
);
886 * UNICODE_STRING objects are always allocated with an extra byte so you
887 * can null-term if you want
889 captionW
.Buffer
[captionW
.Length
/ sizeof(WCHAR
)] = L
'\0';
892 captionW
.Buffer
= (LPWSTR
)lpMsgBoxParams
->lpszCaption
;
894 if (lpMsgBoxParams
->dwStyle
& MB_USERICON
)
896 if (!IS_INTRESOURCE(lpMsgBoxParams
->lpszIcon
))
898 RtlCreateUnicodeStringFromAsciiz(&iconW
, (PCSZ
)lpMsgBoxParams
->lpszIcon
);
900 * UNICODE_STRING objects are always allocated with an extra byte so you
901 * can null-term if you want
903 iconW
.Buffer
[iconW
.Length
/ sizeof(WCHAR
)] = L
'\0';
906 iconW
.Buffer
= (LPWSTR
)lpMsgBoxParams
->lpszIcon
;
911 msgboxW
.cbSize
= sizeof(msgboxW
);
912 msgboxW
.hwndOwner
= lpMsgBoxParams
->hwndOwner
;
913 msgboxW
.hInstance
= lpMsgBoxParams
->hInstance
;
914 msgboxW
.lpszText
= textW
.Buffer
;
915 msgboxW
.lpszCaption
= captionW
.Buffer
;
916 msgboxW
.dwStyle
= lpMsgBoxParams
->dwStyle
;
917 msgboxW
.lpszIcon
= iconW
.Buffer
;
918 msgboxW
.dwContextHelpId
= lpMsgBoxParams
->dwContextHelpId
;
919 msgboxW
.lpfnMsgBoxCallback
= lpMsgBoxParams
->lpfnMsgBoxCallback
;
920 msgboxW
.dwLanguageId
= lpMsgBoxParams
->dwLanguageId
;
922 ret
= MessageBoxTimeoutIndirectW(&msgboxW
, (UINT
)-1);
924 if (!IS_INTRESOURCE(lpMsgBoxParams
->lpszText
))
925 RtlFreeUnicodeString(&textW
);
927 if (!IS_INTRESOURCE(lpMsgBoxParams
->lpszCaption
))
928 RtlFreeUnicodeString(&captionW
);
930 if ((lpMsgBoxParams
->dwStyle
& MB_USERICON
) && !IS_INTRESOURCE(iconW
.Buffer
))
931 RtlFreeUnicodeString(&iconW
);
942 IN CONST MSGBOXPARAMSW
* lpMsgBoxParams
)
944 return MessageBoxTimeoutIndirectW(lpMsgBoxParams
, (UINT
)-1);
961 MSGBOXPARAMSW msgboxW
;
962 UNICODE_STRING textW
, captionW
;
965 if (!IS_INTRESOURCE(lpText
))
966 RtlCreateUnicodeStringFromAsciiz(&textW
, (PCSZ
)lpText
);
968 textW
.Buffer
= (LPWSTR
)lpText
;
970 if (!IS_INTRESOURCE(lpCaption
))
971 RtlCreateUnicodeStringFromAsciiz(&captionW
, (PCSZ
)lpCaption
);
973 captionW
.Buffer
= (LPWSTR
)lpCaption
;
975 msgboxW
.cbSize
= sizeof(msgboxW
);
976 msgboxW
.hwndOwner
= hWnd
;
977 msgboxW
.hInstance
= 0;
978 msgboxW
.lpszText
= textW
.Buffer
;
979 msgboxW
.lpszCaption
= captionW
.Buffer
;
980 msgboxW
.dwStyle
= uType
;
981 msgboxW
.lpszIcon
= NULL
;
982 msgboxW
.dwContextHelpId
= 0;
983 msgboxW
.lpfnMsgBoxCallback
= NULL
;
984 msgboxW
.dwLanguageId
= wLanguageId
;
986 ret
= MessageBoxTimeoutIndirectW(&msgboxW
, (UINT
)dwTimeout
);
988 if (!IS_INTRESOURCE(textW
.Buffer
))
989 RtlFreeUnicodeString(&textW
);
991 if (!IS_INTRESOURCE(captionW
.Buffer
))
992 RtlFreeUnicodeString(&captionW
);
1005 IN LPCWSTR lpCaption
,
1007 IN WORD wLanguageId
,
1010 MSGBOXPARAMSW msgbox
;
1012 msgbox
.cbSize
= sizeof(msgbox
);
1013 msgbox
.hwndOwner
= hWnd
;
1014 msgbox
.hInstance
= 0;
1015 msgbox
.lpszText
= lpText
;
1016 msgbox
.lpszCaption
= lpCaption
;
1017 msgbox
.dwStyle
= uType
;
1018 msgbox
.lpszIcon
= NULL
;
1019 msgbox
.dwContextHelpId
= 0;
1020 msgbox
.lpfnMsgBoxCallback
= NULL
;
1021 msgbox
.dwLanguageId
= wLanguageId
;
1023 return MessageBoxTimeoutIndirectW(&msgbox
, (UINT
)dwTimeout
);
1032 SoftModalMessageBox(DWORD Unknown0
)
1044 MessageBeep(IN UINT uType
)
1046 return NtUserxMessageBeep(uType
);
1053 * See: https://msdn.microsoft.com/en-us/library/windows/desktop/dn910915(v=vs.85).aspx
1054 * and: http://undoc.airesoft.co.uk/user32.dll/MB_GetString.php
1055 * for more information.
1059 MB_GetString(IN UINT wBtn
)
1061 LPCWSTR btnStr
= NULL
;
1064 * The allowable IDs are between "IDOK - 1" (0) and "IDCONTINUE - 1" (10) inclusive.
1065 * See psdk/winuser.h and user32/include/resource.h .
1067 if (wBtn
> IDCONTINUE
- 1)
1070 wBtn
+= 800; // See user32/include/resource.h
1071 LoadStringW(User32Instance
, wBtn
, (LPWSTR
)&btnStr
, 0);