From: Gabriel Ivăncescu Subject: [PATCH 4/6] user32/tests: Add test for a window that doesn't want to be deactivated Message-Id: <7d4fe7b6814431eeb4f60d36a838c816225c0895.1548678703.git.gabrielopcode@gmail.com> Date: Mon, 28 Jan 2019 14:34:17 +0200 In-Reply-To: <9d7e2092f2b9e40d7e85c7e884d4f9b0cfa8952d.1548678703.git.gabrielopcode@gmail.com> References: <9d7e2092f2b9e40d7e85c7e884d4f9b0cfa8952d.1548678703.git.gabrielopcode@gmail.com> On Windows, if WM_NCACTIVATE returns FALSE, the window doesn't get deactivated. Signed-off-by: Gabriel Ivăncescu --- dlls/user32/tests/win.c | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/dlls/user32/tests/win.c b/dlls/user32/tests/win.c index 94eff5e..83ba1de 100644 --- a/dlls/user32/tests/win.c +++ b/dlls/user32/tests/win.c @@ -899,6 +899,17 @@ static LRESULT WINAPI tool_window_procA(HWND hwnd, UINT msg, WPARAM wparam, LPAR return DefWindowProcA(hwnd, msg, wparam, lparam); } +static LRESULT WINAPI no_deactivation_procA(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) +{ + switch (msg) + { + case WM_NCACTIVATE: + DefWindowProcA(hwnd, msg, wparam, lparam); + return FALSE; + } + return DefWindowProcA(hwnd, msg, wparam, lparam); +} + static const WCHAR mainclassW[] = {'M','a','i','n','W','i','n','d','o','w','C','l','a','s','s','W',0}; static BOOL RegisterWindowClasses(void) @@ -3160,6 +3171,18 @@ static void test_SetActiveWindow(HWND hwnd) check_active_state(hwnd, hwnd, hwnd); } DestroyWindow(hwnd2); + + /* a window can disallow being deactivated by returning FALSE from WM_NCACTIVATE */ + hwnd2 = CreateWindowExA(0, "MainWindowClass", "No Deactivation window", WS_OVERLAPPED | WS_VISIBLE, + 10, 10, 50, 50, hwnd, 0, GetModuleHandleA(NULL), NULL); + ok(hwnd2 != NULL, "failed to create No Deactivation window: 0x%08x\n", GetLastError()); + SetWindowLongPtrA(hwnd2, GWLP_WNDPROC, (LONG_PTR)no_deactivation_procA); + + SetActiveWindow(hwnd2); + check_wnd_state(hwnd2, hwnd2, hwnd2, 0); + SetActiveWindow(hwnd); + check_wnd_state(hwnd2, hwnd2, hwnd2, 0); + DestroyWindow(hwnd2); } struct create_window_thread_params -- 2.19.1