-- v2: user32/msgbox: Implement MB_TOPMOST. user32/tests: Test more flags for MessageBox.
From: Paul Gofman pgofman@codeweavers.com
--- dlls/user32/tests/dialog.c | 72 +++++++++++++++++++++++--------------- 1 file changed, 44 insertions(+), 28 deletions(-)
diff --git a/dlls/user32/tests/dialog.c b/dlls/user32/tests/dialog.c index 21958ddb193..99f52769e73 100644 --- a/dlls/user32/tests/dialog.c +++ b/dlls/user32/tests/dialog.c @@ -2123,15 +2123,36 @@ static void test_timer_message(void) DialogBoxA(g_hinst, "RADIO_TEST_DIALOG", NULL, timer_message_dlg_proc); }
+static unsigned int msgbox_hook_proc_called; +static UINT msgbox_type; + static LRESULT CALLBACK msgbox_hook_proc(INT code, WPARAM wParam, LPARAM lParam) { + static const LONG considered_ex_styles = WS_EX_CONTROLPARENT | WS_EX_WINDOWEDGE | WS_EX_DLGMODALFRAME | WS_EX_TOPMOST; + if (code == HCBT_ACTIVATE) { HWND msgbox = (HWND)wParam, msghwnd; + LONG exstyles, expected_exstyles; + BOOL system_modal; char text[64];
if (msgbox) { + exstyles = GetWindowLongA(msgbox, GWL_EXSTYLE) & considered_ex_styles; + + ++msgbox_hook_proc_called; + system_modal = msgbox_type & MB_SYSTEMMODAL && !(msgbox_type & MB_TASKMODAL); + expected_exstyles = WS_EX_CONTROLPARENT | WS_EX_WINDOWEDGE; + if ((msgbox_type & MB_TOPMOST) || system_modal) + expected_exstyles |= WS_EX_TOPMOST; + if (!system_modal) + expected_exstyles |= WS_EX_DLGMODALFRAME; + + todo_wine_if((system_modal && exstyles == (expected_exstyles | WS_EX_DLGMODALFRAME)) + || (!system_modal && msgbox_type & MB_TOPMOST)) + ok(exstyles == expected_exstyles, "got %#lx, expected %#lx\n", exstyles, expected_exstyles); + text[0] = 0; GetWindowTextA(msgbox, text, sizeof(text)); ok(!strcmp(text, "MSGBOX caption"), "Unexpected window text "%s"\n", text); @@ -2141,26 +2162,9 @@ static LRESULT CALLBACK msgbox_hook_proc(INT code, WPARAM wParam, LPARAM lParam)
text[0] = 0; GetWindowTextA(msghwnd, text, sizeof(text)); - ok(!strcmp(text, "Text"), "Unexpected window text "%s"\n", text); - - SendDlgItemMessageA(msgbox, IDCANCEL, WM_LBUTTONDOWN, 0, 0); - SendDlgItemMessageA(msgbox, IDCANCEL, WM_LBUTTONUP, 0, 0); - } - } - - return CallNextHookEx(NULL, code, wParam, lParam); -} - -static LRESULT CALLBACK msgbox_sysmodal_hook_proc(INT code, WPARAM wParam, LPARAM lParam) -{ - if (code == HCBT_ACTIVATE) - { - HWND msgbox = (HWND)wParam; - LONG exstyles = GetWindowLongA(msgbox, GWL_EXSTYLE);
- if (msgbox) - { - ok(exstyles & WS_EX_TOPMOST, "expected message box to have topmost exstyle set\n"); + todo_wine_if(msgbox_type != MB_OKCANCEL && !*text) + ok(!strcmp(text, "Text"), "Unexpected window text "%s"\n", text);
SendDlgItemMessageA(msgbox, IDCANCEL, WM_LBUTTONDOWN, 0, 0); SendDlgItemMessageA(msgbox, IDCANCEL, WM_LBUTTONUP, 0, 0); @@ -2172,20 +2176,32 @@ static LRESULT CALLBACK msgbox_sysmodal_hook_proc(INT code, WPARAM wParam, LPARA
static void test_MessageBox(void) { + static const UINT tests[] = + { + MB_OKCANCEL, + MB_OKCANCEL | MB_SYSTEMMODAL, + MB_OKCANCEL | MB_TASKMODAL | MB_SYSTEMMODAL, + MB_OKCANCEL | MB_TOPMOST, + MB_OKCANCEL | MB_TOPMOST | MB_SYSTEMMODAL, + MB_OKCANCEL | MB_TASKMODAL | MB_TOPMOST, + MB_OKCANCEL | MB_TASKMODAL | MB_SYSTEMMODAL | MB_TOPMOST, + }; + unsigned int i; HHOOK hook; int ret;
hook = SetWindowsHookExA(WH_CBT, msgbox_hook_proc, NULL, GetCurrentThreadId());
- ret = MessageBoxA(NULL, "Text", "MSGBOX caption", MB_OKCANCEL); - ok(ret == IDCANCEL, "got %d\n", ret); - - UnhookWindowsHookEx(hook); - - /* Test for MB_SYSTEMMODAL */ - hook = SetWindowsHookExA(WH_CBT, msgbox_sysmodal_hook_proc, NULL, GetCurrentThreadId()); - - MessageBoxA(NULL, NULL, "system modal", MB_OKCANCEL | MB_SYSTEMMODAL); + for (i = 0; i < ARRAY_SIZE(tests); ++i) + { + msgbox_type = tests[i]; + winetest_push_context("type %#x", msgbox_type); + msgbox_hook_proc_called = 0; + ret = MessageBoxA(NULL, "Text", "MSGBOX caption", msgbox_type); + ok(ret == IDCANCEL, "got %d\n", ret); + ok(msgbox_hook_proc_called, "got %u.\n", msgbox_hook_proc_called); + winetest_pop_context(); + }
UnhookWindowsHookEx(hook); }
From: Paul Gofman pgofman@codeweavers.com
--- dlls/user32/msgbox.c | 6 ++++-- dlls/user32/tests/dialog.c | 3 +-- 2 files changed, 5 insertions(+), 4 deletions(-)
diff --git a/dlls/user32/msgbox.c b/dlls/user32/msgbox.c index 4a14a868c73..4d345777a10 100644 --- a/dlls/user32/msgbox.c +++ b/dlls/user32/msgbox.c @@ -110,10 +110,12 @@ static void MSGBOX_OnInit(HWND hwnd, LPMSGBOXPARAMSW lpmb) }
/* handle modal message boxes */ - if (((lpmb->dwStyle & MB_TASKMODAL) && (lpmb->hwndOwner==NULL))) - NtUserSetWindowPos( hwnd, HWND_TOP, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE ); + if (lpmb->dwStyle & MB_TASKMODAL && lpmb->hwndOwner == NULL) + NtUserSetWindowPos( hwnd, lpmb->dwStyle & MB_TOPMOST ? HWND_TOPMOST : HWND_TOP, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE ); else if (lpmb->dwStyle & MB_SYSTEMMODAL) NtUserSetWindowPos( hwnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_FRAMECHANGED ); + else if (lpmb->dwStyle & MB_TOPMOST) + NtUserSetWindowPos( hwnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE );
TRACE_(msgbox)("%s\n", debugstr_w(lpszText)); SetWindowTextW(GetDlgItem(hwnd, MSGBOX_IDTEXT), lpszText); diff --git a/dlls/user32/tests/dialog.c b/dlls/user32/tests/dialog.c index 99f52769e73..a24bfafd0b9 100644 --- a/dlls/user32/tests/dialog.c +++ b/dlls/user32/tests/dialog.c @@ -2149,8 +2149,7 @@ static LRESULT CALLBACK msgbox_hook_proc(INT code, WPARAM wParam, LPARAM lParam) if (!system_modal) expected_exstyles |= WS_EX_DLGMODALFRAME;
- todo_wine_if((system_modal && exstyles == (expected_exstyles | WS_EX_DLGMODALFRAME)) - || (!system_modal && msgbox_type & MB_TOPMOST)) + todo_wine_if(system_modal && exstyles == (expected_exstyles | WS_EX_DLGMODALFRAME)) ok(exstyles == expected_exstyles, "got %#lx, expected %#lx\n", exstyles, expected_exstyles);
text[0] = 0;