Moved hrgnUpdate from client to window coordinates, made nonclient
painting depend on the update region, reworked SetWindowPos() and
RedrawWindow() to speed up update region calculation, made -desktop
work properly, added WM_CANCELMODE here and there, fixed several
window activation bugs that crept in since the last time.

diff --git a/windows/nonclient.c b/windows/nonclient.c
index 0a71f83..5b7ba08 100644
--- a/windows/nonclient.c
+++ b/windows/nonclient.c
@@ -11,6 +11,7 @@
 #include "sysmetrics.h"
 #include "user.h"
 #include "heap.h"
+#include "dce.h"
 #include "cursoricon.h"
 #include "dialog.h"
 #include "menu.h"
@@ -1563,7 +1564,8 @@
 
     TRACE(nonclient, "%04x %d\n", hwnd, active );
 
-    if (!(hdc = GetDCEx( hwnd, 0, DCX_USESTYLE | DCX_WINDOW ))) return;
+    if (!(hdc = GetDCEx( hwnd, (clip > 1) ? clip : 0, DCX_USESTYLE | DCX_WINDOW |
+			      ((clip > 1) ? (DCX_INTERSECTRGN | DCX_KEEPCLIPRGN): 0) ))) return;
 
     if (ExcludeVisRect16( hdc, wndPtr->rectClient.left-wndPtr->rectWindow.left,
 		        wndPtr->rectClient.top-wndPtr->rectWindow.top,
@@ -1665,7 +1667,7 @@
     BOOL  suppress_menupaint )
 {
     HDC hdc;
-    RECT rect;
+    RECT rfuzz, rect, rectClip;
     BOOL active;
     HWND hwnd = wndPtr->hwndSelf;
 
@@ -1676,7 +1678,15 @@
 
     TRACE(nonclient, "%04x %d\n", hwnd, active );
 
-    if (!(hdc = GetDCEx( hwnd, 0, DCX_USESTYLE | DCX_WINDOW ))) return;
+    /* MSDN docs are pretty idiotic here, they say app CAN use clipRgn in the call to
+     * GetDCEx implying that it is allowed not to use it either. However, the suggested
+     * GetDCEx(    , DCX_WINDOW | DCX_INTERSECTRGN) will cause clipRgn to be deleted
+     * after ReleaseDC(). Now, how is the "system" supposed to tell what happened?
+     */
+
+    if (!(hdc = GetDCEx( hwnd, (clip > 1) ? clip : 0, DCX_USESTYLE | DCX_WINDOW |
+			      ((clip > 1) ?(DCX_INTERSECTRGN | DCX_KEEPCLIPRGN) : 0) ))) return;
+
 
     if (ExcludeVisRect16( hdc, wndPtr->rectClient.left-wndPtr->rectWindow.left,
 		        wndPtr->rectClient.top-wndPtr->rectWindow.top,
@@ -1692,6 +1702,14 @@
     rect.right  = wndPtr->rectWindow.right - wndPtr->rectWindow.left;
     rect.bottom = wndPtr->rectWindow.bottom - wndPtr->rectWindow.top;
 
+    if( clip > 1 )
+	GetRgnBox( clip, &rectClip );
+    else
+    {
+	clip = 0;
+	rectClip = rect;
+    }
+
     SelectObject( hdc, GetSysColorPen(COLOR_WINDOWFRAME) );
 
     if(!(wndPtr->flags & WIN_MANAGED)) {
@@ -1716,8 +1734,9 @@
 		r.bottom = rect.top + sysMetrics[SM_CYCAPTION];
 		rect.top += sysMetrics[SM_CYCAPTION];
 	    }
-            NC_DrawCaption95 (hdc, &r, hwnd, wndPtr->dwStyle,
-                              wndPtr->dwExStyle, active);
+	    if( !clip || IntersectRect( &rfuzz, &r, &rectClip ) )
+                NC_DrawCaption95 (hdc, &r, hwnd, wndPtr->dwStyle,
+                                  wndPtr->dwExStyle, active);
         }
     }