From 23151003143c38b7aa0ef8f1f0feefad619e39ae Mon Sep 17 00:00:00 2001 From: Filip Navara Date: Mon, 21 Mar 2005 01:34:02 +0000 Subject: [PATCH] - Cleanup DefWndDoButton function. - Fix some loops where GetMessage was inadvertently used. svn path=/trunk/; revision=14247 --- reactos/lib/user32/windows/defwnd.c | 6 +- reactos/lib/user32/windows/nonclient.c | 134 ++++++++++++------------- 2 files changed, 69 insertions(+), 71 deletions(-) diff --git a/reactos/lib/user32/windows/defwnd.c b/reactos/lib/user32/windows/defwnd.c index 6d7ed4b39dd..c04e43d8669 100644 --- a/reactos/lib/user32/windows/defwnd.c +++ b/reactos/lib/user32/windows/defwnd.c @@ -317,7 +317,8 @@ DefWndStartSizeMove(HWND hWnd, WPARAM wParam, POINT *capturePoint) { while(!hittest) { - GetMessageW(&msg, NULL, 0, 0); + if (GetMessageW(&msg, NULL, 0, 0) <= 0) + break; switch(msg.message) { case WM_MOUSEMOVE: @@ -572,7 +573,8 @@ DefWndDoSizeMove(HWND hwnd, WORD wParam) { int dx = 0, dy = 0; - GetMessageW(&msg, 0, 0, 0); + if (GetMessageW(&msg, 0, 0, 0) <= 0) + break; /* Exit on button-up, Return, or Esc */ if ((msg.message == WM_LBUTTONUP) || diff --git a/reactos/lib/user32/windows/nonclient.c b/reactos/lib/user32/windows/nonclient.c index 822629beefb..02a328011e1 100644 --- a/reactos/lib/user32/windows/nonclient.c +++ b/reactos/lib/user32/windows/nonclient.c @@ -882,79 +882,75 @@ DefWndNCHitTest(HWND hWnd, POINT Point) VOID DefWndDoButton(HWND hWnd, WPARAM wParam) { - MSG Msg; - BOOL InBtn, HasBtn = FALSE; - ULONG Btn, Style; - WPARAM SCMsg, CurBtn = wParam, OrigBtn = wParam; - HDC WindowDC = NULL; + MSG Msg; + HDC WindowDC; + BOOL Pressed = TRUE, OldState; + WPARAM SCMsg; + ULONG ButtonType, Style; - Style = GetWindowLongW(hWnd, GWL_STYLE); - switch(wParam) - { - case HTCLOSE: - Btn = DFCS_CAPTIONCLOSE; - SCMsg = SC_CLOSE; - HasBtn = (Style & WS_SYSMENU); - break; - case HTMINBUTTON: - Btn = DFCS_CAPTIONMIN; - SCMsg = ((Style & WS_MINIMIZE) ? SC_RESTORE : SC_MINIMIZE); - HasBtn = (Style & WS_MINIMIZEBOX); - break; - case HTMAXBUTTON: - Btn = DFCS_CAPTIONMAX; - SCMsg = ((Style & WS_MAXIMIZE) ? SC_RESTORE : SC_MAXIMIZE); - HasBtn = (Style & WS_MAXIMIZEBOX); - break; - default: - return; - } + Style = GetWindowLongW(hWnd, GWL_STYLE); + switch (wParam) + { + case HTCLOSE: + if (!(Style & WS_SYSMENU)) + return; + ButtonType = DFCS_CAPTIONCLOSE; + SCMsg = SC_CLOSE; + break; + case HTMINBUTTON: + if (!(Style & WS_MINIMIZEBOX)) + return; + ButtonType = DFCS_CAPTIONMIN; + SCMsg = ((Style & WS_MINIMIZE) ? SC_RESTORE : SC_MINIMIZE); + break; + case HTMAXBUTTON: + if (!(Style & WS_MAXIMIZEBOX)) + return; + ButtonType = DFCS_CAPTIONMAX; + SCMsg = ((Style & WS_MAXIMIZE) ? SC_RESTORE : SC_MAXIMIZE); + break; + + default: + ASSERT(FALSE); + return; + } - InBtn = HasBtn; + /* + * FIXME: Not sure where to do this, but we must flush the pending + * window updates when someone clicks on the close button and at + * the same time the window is overlapped with another one. This + * looks like a good place for now... + */ + UpdateWindow(hWnd); + + WindowDC = GetWindowDC(hWnd); + UserDrawCaptionButtonWnd(hWnd, WindowDC, TRUE, ButtonType); + + SetCapture(hWnd); - SetCapture(hWnd); + for (;;) + { + if (GetMessageW(&Msg, 0, WM_MOUSEFIRST, WM_MOUSELAST) <= 0) + break; + + if (Msg.message == WM_LBUTTONUP) + break; + + if (Msg.message != WM_MOUSEMOVE) + continue; + + OldState = Pressed; + Pressed = (DefWndNCHitTest(hWnd, Msg.pt) == wParam); + if (Pressed != OldState) + UserDrawCaptionButtonWnd(hWnd, WindowDC, Pressed, ButtonType); + } - if(HasBtn) - { - WindowDC = GetWindowDC(hWnd); - UserDrawCaptionButtonWnd(hWnd, WindowDC, HasBtn , Btn); - } - - for(;;) - { - GetMessageW(&Msg, 0, 0, 0); - switch(Msg.message) - { - case WM_LBUTTONUP: - if(InBtn) - goto done; - else - { - ReleaseCapture(); - if (HasBtn) - ReleaseDC(hWnd, WindowDC); - return; - } - case WM_MOUSEMOVE: - if(HasBtn) - { - CurBtn = DefWndNCHitTest(hWnd, Msg.pt); - if(InBtn != (CurBtn == OrigBtn)) - { - UserDrawCaptionButtonWnd( hWnd, WindowDC, (CurBtn == OrigBtn) , Btn); - } - InBtn = CurBtn == OrigBtn; - } - break; - } - } - -done: - UserDrawCaptionButtonWnd( hWnd, WindowDC, FALSE , Btn); - ReleaseDC(hWnd, WindowDC); - ReleaseCapture(); - SendMessageW(hWnd, WM_SYSCOMMAND, SCMsg, 0); - return; + if (Pressed) + UserDrawCaptionButtonWnd(hWnd, WindowDC, FALSE, ButtonType); + ReleaseCapture(); + ReleaseDC(hWnd, WindowDC); + if (Pressed) + SendMessageW(hWnd, WM_SYSCOMMAND, SCMsg, 0); }