From ababea0fd7036ab13ec17d31afbd584c39f62696 Mon Sep 17 00:00:00 2001 From: Dmitry Timoshkov Date: Mon, 25 Oct 2021 12:41:59 +0300 Subject: [PATCH] user32: DragDetect() should enter its message loop only if the left mouse button is pressed. There's an application that calls DragDetect() on every WM_MOUSEMOVE message, and this breaks handling of mouse events. A simple test app shows that on Windows DragDetect() starts its message loop when left mouse button is pressed. Signed-off-by: Dmitry Timoshkov Signed-off-by: Alexandre Julliard --- dlls/user32/tests/win.c | 17 +++++++++++++++++ dlls/user32/win.c | 10 ++++++++-- 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/dlls/user32/tests/win.c b/dlls/user32/tests/win.c index 6b13d93be14..88989f4064b 100644 --- a/dlls/user32/tests/win.c +++ b/dlls/user32/tests/win.c @@ -12293,6 +12293,22 @@ static void test_cancel_mode(void) DestroyWindow(hwnd2); } +static void test_DragDetect(void) +{ + POINT pt; + BOOL ret; + + ok(!GetCapture(), "got capture window %p\n", GetCapture()); + ok(!(GetKeyState( VK_LBUTTON ) & 0x8000), "got VK_LBUTTON\n"); + + GetCursorPos(&pt); + ret = DragDetect(hwndMain, pt); + ok(!ret, "got %d\n", ret); + + ok(!GetCapture(), "got capture window %p\n", GetCapture()); + ok(!(GetKeyState( VK_LBUTTON ) & 0x8000), "got VK_LBUTTON\n"); +} + START_TEST(win) { char **argv; @@ -12461,6 +12477,7 @@ START_TEST(win) test_other_process_window(argv[0]); test_SC_SIZE(); test_cancel_mode(); + test_DragDetect(); /* add the tests above this line */ if (hhook) UnhookWindowsHookEx(hhook); diff --git a/dlls/user32/win.c b/dlls/user32/win.c index 4d0240f21a8..3c6810f4200 100644 --- a/dlls/user32/win.c +++ b/dlls/user32/win.c @@ -3893,9 +3893,15 @@ BOOL WINAPI DragDetect( HWND hWnd, POINT pt ) { MSG msg; RECT rect; - WORD wDragWidth = GetSystemMetrics(SM_CXDRAG); - WORD wDragHeight= GetSystemMetrics(SM_CYDRAG); + WORD wDragWidth, wDragHeight; + TRACE( "%p,%s\n", hWnd, wine_dbgstr_point( &pt ) ); + + if (!(GetKeyState( VK_LBUTTON ) & 0x8000)) + return FALSE; + + wDragWidth = GetSystemMetrics(SM_CXDRAG); + wDragHeight= GetSystemMetrics(SM_CYDRAG); SetRect(&rect, pt.x - wDragWidth, pt.y - wDragHeight, pt.x + wDragWidth, pt.y + wDragHeight); SetCapture(hWnd); -- 2.11.4.GIT