From 5d1a1471636c793e75cdd1ac8a52a6d98d8c9a1c Mon Sep 17 00:00:00 2001 From: Alexandre Julliard Date: Wed, 15 Feb 2012 14:26:00 +0100 Subject: [PATCH] user32: Add mouse tracking on caption right-clicks to avoid messing with the capture. --- dlls/user32/controls.h | 1 + dlls/user32/defwnd.c | 12 +----------- dlls/user32/nonclient.c | 38 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 40 insertions(+), 11 deletions(-) diff --git a/dlls/user32/controls.h b/dlls/user32/controls.h index 66d66596a1e..6bd946b6673 100644 --- a/dlls/user32/controls.h +++ b/dlls/user32/controls.h @@ -170,6 +170,7 @@ extern LRESULT NC_HandleNCActivate( HWND hwnd, WPARAM wParam, LPARAM lParam ) DE extern LRESULT NC_HandleNCCalcSize( HWND hwnd, WPARAM wParam, RECT *winRect ) DECLSPEC_HIDDEN; extern LRESULT NC_HandleNCHitTest( HWND hwnd, POINT pt ) DECLSPEC_HIDDEN; extern LRESULT NC_HandleNCLButtonDown( HWND hwnd, WPARAM wParam, LPARAM lParam ) DECLSPEC_HIDDEN; +extern LRESULT NC_HandleNCRButtonDown( HWND hwnd, WPARAM wParam, LPARAM lParam ) DECLSPEC_HIDDEN; extern LRESULT NC_HandleNCLButtonDblClk( HWND hwnd, WPARAM wParam, LPARAM lParam) DECLSPEC_HIDDEN; extern LRESULT NC_HandleSysCommand( HWND hwnd, WPARAM wParam, LPARAM lParam ) DECLSPEC_HIDDEN; extern LRESULT NC_HandleSetCursor( HWND hwnd, WPARAM wParam, LPARAM lParam ) DECLSPEC_HIDDEN; diff --git a/dlls/user32/defwnd.c b/dlls/user32/defwnd.c index 226b604c22c..0ac308c8ddb 100644 --- a/dlls/user32/defwnd.c +++ b/dlls/user32/defwnd.c @@ -334,21 +334,11 @@ static LRESULT DEFWND_DefWinProc( HWND hwnd, UINT msg, WPARAM wParam, LPARAM lPa return NC_HandleNCLButtonDblClk( hwnd, wParam, lParam ); case WM_NCRBUTTONDOWN: - /* in Windows, capture is taken when right-clicking on the caption bar */ - if (wParam==HTCAPTION) - { - SetCapture(hwnd); - } - break; + return NC_HandleNCRButtonDown( hwnd, wParam, lParam ); case WM_RBUTTONUP: { POINT pt; - - if (hwnd == GetCapture()) - /* release capture if we took it on WM_NCRBUTTONDOWN */ - ReleaseCapture(); - pt.x = (short)LOWORD(lParam); pt.y = (short)HIWORD(lParam); ClientToScreen(hwnd, &pt); diff --git a/dlls/user32/nonclient.c b/dlls/user32/nonclient.c index 6bef9ff278a..5ca0a8df97e 100644 --- a/dlls/user32/nonclient.c +++ b/dlls/user32/nonclient.c @@ -1461,6 +1461,44 @@ LRESULT NC_HandleNCLButtonDown( HWND hwnd, WPARAM wParam, LPARAM lParam ) } +/*********************************************************************** + * NC_HandleNCRButtonDown + * + * Handle a WM_NCRBUTTONDOWN message. Called from DefWindowProc(). + */ +LRESULT NC_HandleNCRButtonDown( HWND hwnd, WPARAM wParam, LPARAM lParam ) +{ + MSG msg; + INT hittest = wParam; + HMENU hSysMenu = GetSystemMenu(hwnd, FALSE); + + switch (hittest) + { + case HTCAPTION: + case HTSYSMENU: + hSysMenu = GetSystemMenu(hwnd, FALSE); + if (!hSysMenu) break; + + SetCapture( hwnd ); + for (;;) + { + if (!GetMessageW( &msg, 0, WM_MOUSEFIRST, WM_MOUSELAST )) break; + if (CallMsgFilterW( &msg, MSGF_MAX )) continue; + if (msg.message == WM_RBUTTONUP) + { + hittest = NC_HandleNCHitTest( hwnd, msg.pt ); + break; + } + } + ReleaseCapture(); + if (hittest == HTCAPTION || hittest == HTSYSMENU) + SendMessageW( hwnd, WM_SYSCOMMAND, SC_MOUSEMENU + HTSYSMENU, msg.lParam ); + break; + } + return 0; +} + + /*********************************************************************** * NC_HandleNCLButtonDblClk *