Dmitry Timoshkov : user32: DragDetect() should enter its message loop only if the left mouse button is pressed.

Alexandre Julliard julliard at winehq.org
Mon Oct 25 16:30:08 CDT 2021


Module: wine
Branch: master
Commit: ababea0fd7036ab13ec17d31afbd584c39f62696
URL:    https://source.winehq.org/git/wine.git/?a=commit;h=ababea0fd7036ab13ec17d31afbd584c39f62696

Author: Dmitry Timoshkov <dmitry at baikal.ru>
Date:   Mon Oct 25 12:41:59 2021 +0300

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 <dmitry at baikal.ru>
Signed-off-by: Alexandre Julliard <julliard at winehq.org>

---

 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);




More information about the wine-cvs mailing list