- Cleanup DefWndDoButton function.
- Fix some loops where GetMessage was inadvertently used.
Modified: trunk/reactos/lib/user32/windows/defwnd.c
Modified: trunk/reactos/lib/user32/windows/nonclient.c
_____
Modified: trunk/reactos/lib/user32/windows/defwnd.c
--- trunk/reactos/lib/user32/windows/defwnd.c 2005-03-21 00:55:16 UTC
(rev 14246)
+++ trunk/reactos/lib/user32/windows/defwnd.c 2005-03-21 01:34:02 UTC
(rev 14247)
@@ -317,7 +317,8 @@
{
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 @@
{
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) ||
_____
Modified: trunk/reactos/lib/user32/windows/nonclient.c
--- trunk/reactos/lib/user32/windows/nonclient.c 2005-03-21
00:55:16 UTC (rev 14246)
+++ trunk/reactos/lib/user32/windows/nonclient.c 2005-03-21
01:34:02 UTC (rev 14247)
@@ -882,79 +882,75 @@
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);
}