Release 950122

Sun Jan 22 18:55:33 1995  Alexandre Julliard  (julliard@lamisun.epfl.ch)

	* [loader/resource.c] [objects/dib.c]
	Fixed icon loading and drawing, now that BitBlt() works correctly.
	
	* [objects/clipping.c] [objects/region.c]
	Implemented elliptic regions with a set of rectangle. This greatly
	simplifies the region code and should boost clipping performance.

	* [objects/color.c]
	Fixed bug that caused seg-fault on 24bpp displays.

	* [objects/bitblt.c]
	Fixed bug when shrinking a bitmap to more than half its size.

	* [windows/graphics.c]
	Fixed bugs in PaintRgn() and Polyline().

	* [windows/nonclient.c] [windows/painting.c] [windows/winpos.c]
	Fixed some problems with window background painting.

Thu Jan 12 12:20:25 PST 1995 Ross Biro (biro@yggdrasil.com)

       * [tools/build.c]
       * [tools/newbuild.c]
       * [Imakefile]
       * [include/wine.h]
       * [loader/call.S]
       * [loader/selector.c]
       * [include/segmem.h]
       * [misc/main.c]
       Changed selector code and 16/32 bit xfer code so that wine
       no longer has to be loaded low in memory.  Changed wine
       to work with ELF binary formats under Linux.
       
Sat Sep 17 11:08:49 1994  Eric Youngdale  (eric@esp22)

	* [debugger/db_disasm.c]
	New instruction disassembler - borrowed from Mach kernel.  Has a
	BSD style of license as opposed to the gdb code we were previously
	using which was under the GPL.

Mon Jan  9 18:27:11 1995  Alexandre Julliard  (julliard@lamisun.epfl.ch)

	* [Imakefile]
	Compiling with -Wall flag.

	* [*/*]
	Fixes to minimize the number of compilation warnings.

	* [objects/bitblt.c]
	Fixed BitBlt() and used the same code to rewrite PatBlt() and
	StretchBlt(). The three *Blt() functions should now be correct in
	every case (famous last words).

	* [objects/brush.c] [objects/dither.c]
	Merged the two files into brush.c

	* [objects/dc.c]
	Fixed bug when the Windows programs forget to re-select the
	original bitmap in a memory DC.

	* [objects/font.c]
	Tty to use 'fixed' font when the system font can't be found.

	* [windows/dialog.c]
	Tentative fix to make dialogs look better when using fixed-width
	fonts.

	* [windows/graphics.c]
	Partially implemented the PS_INSIDEFRAME pen style.

	* [windows/nonclient.c]
	Fix for windows that have the WS_EX_DLGMODALFRAME style bit
	without the WS_DLGFRAME style.
diff --git a/windows/cursor.c b/windows/cursor.c
index 5ba75a7..7c98f92 100644
--- a/windows/cursor.c
+++ b/windows/cursor.c
@@ -416,7 +416,8 @@
  */
 void ClipCursor(LPRECT lpNewClipRect)
 {
-    CopyRect(&ClipCursorRect, lpNewClipRect);
+    if (!lpNewClipRect) SetRectEmpty( &ClipCursorRect );
+    else CopyRect( &ClipCursorRect, lpNewClipRect );
 }
 
 
diff --git a/windows/defwnd.c b/windows/defwnd.c
index a8c5319..37ed5aa 100644
--- a/windows/defwnd.c
+++ b/windows/defwnd.c
@@ -69,7 +69,7 @@
 
     case WM_PAINTICON: 
     case WM_NCPAINT:
-	return NC_HandleNCPaint( hwnd, (HRGN)wParam );
+	return NC_HandleNCPaint( hwnd );
 
     case WM_NCHITTEST:
 	return NC_HandleNCHitTest( hwnd, MAKEPOINT(lParam) );
@@ -145,8 +145,8 @@
     case WM_ERASEBKGND:
     case WM_ICONERASEBKGND:
 	{
-	    if (!(classPtr = CLASS_FindClassPtr( wndPtr->hClass ))) return 1;
-	    if (!classPtr->wc.hbrBackground) return 1;
+	    if (!(classPtr = CLASS_FindClassPtr( wndPtr->hClass ))) return 0;
+	    if (!classPtr->wc.hbrBackground) return 0;
             if (classPtr->wc.hbrBackground <= COLOR_MAX+1)
             {
                  HBRUSH hbrush;
@@ -158,7 +158,7 @@
             else
 	         FillWindow( GetParent(hwnd), hwnd, (HDC)wParam,
 		        classPtr->wc.hbrBackground );
-	    return 0;
+	    return 1;
 	}
 
     case WM_GETDLGCODE:
@@ -211,7 +211,7 @@
 
     case WM_SETTEXT:
 	DEFWND_SetText( hwnd, (LPSTR)lParam );
-	NC_HandleNCPaint( hwnd, (HRGN)1 );  /* Repaint caption */
+	NC_HandleNCPaint( hwnd );  /* Repaint caption */
 	return 0;
 
     case WM_SETCURSOR:
diff --git a/windows/event.c b/windows/event.c
index 71469b7..4f4a2cf 100644
--- a/windows/event.c
+++ b/windows/event.c
@@ -256,7 +256,6 @@
 static void EVENT_Expose( HWND hwnd, XExposeEvent *event )
 {
     RECT rect;
-    UINT flags;
     WND * wndPtr = WIN_FindWndPtr( hwnd );
     if (!wndPtr) return;
 
@@ -266,10 +265,9 @@
     rect.right  = rect.left + event->width;
     rect.bottom = rect.top + event->height;
 
-    flags = RDW_INVALIDATE | RDW_ERASE | RDW_FRAME | RDW_ALLCHILDREN;
-      /* Erase desktop background synchronously */
-/*     if (event->window == rootWindow) flags |= RDW_ERASENOW | RDW_NOCHILDREN; */
-    RedrawWindow( hwnd, &rect, 0, flags );
+    RedrawWindow( hwnd, &rect, 0,
+                  RDW_INVALIDATE | RDW_FRAME | RDW_ALLCHILDREN | RDW_ERASE |
+                  (event->count ? 0 : RDW_ERASENOW) );
 }
 
 
diff --git a/windows/graphics.c b/windows/graphics.c
index cd8013b..8ed3f8c 100644
--- a/windows/graphics.c
+++ b/windows/graphics.c
@@ -542,8 +542,6 @@
     DC * dc = (DC *) GDI_GetObjPtr( hdc, DC_MAGIC );
     if (!dc) return FALSE;
 
-      /* FIXME: the region is supposed to be in logical coordinates */
-
       /* Modify visible region */
 
     if (!(prevVisRgn = SaveVisRgn( hdc ))) return FALSE;
@@ -558,7 +556,7 @@
 
       /* Fill the region */
 
-    GetClipBox( hdc, &box );
+    GetRgnBox( dc->w.hGCClipRgn, &box );
     if (DC_SetupGCForBrush( dc ))
 	XFillRectangle( display, dc->u.x.drawable, dc->u.x.gc,
 		        dc->w.DCOrgX + box.left, dc->w.DCOrgY + box.top,
@@ -717,21 +715,13 @@
     }
 
     if (DC_SetupGCForPen( dc ))
-    {
 	for (i = 0; i < count-1; i ++)
 	    XDrawLine (display, dc->u.x.drawable, dc->u.x.gc,  
 		       dc->w.DCOrgX + XLPTODP(dc, pt [i].x),
 		       dc->w.DCOrgY + YLPTODP(dc, pt [i].y),
 		       dc->w.DCOrgX + XLPTODP(dc, pt [i+1].x),
 		       dc->w.DCOrgY + YLPTODP(dc, pt [i+1].y));
-	XDrawLine (display, dc->u.x.drawable, dc->u.x.gc,  
-		   dc->w.DCOrgX + XLPTODP(dc, pt [count-1].x),
-		   dc->w.DCOrgY + YLPTODP(dc, pt [count-1].y),
-		   dc->w.DCOrgX + XLPTODP(dc, pt [0].x),
-		   dc->w.DCOrgY + YLPTODP(dc, pt [0].y));
-    } 
-	
-    return (TRUE);
+    return TRUE;
 }
 
 
@@ -915,7 +905,7 @@
     }
 
     if (!PtVisible( hdc, x, y )) return FALSE;
-    if (GetClipBox( hdc, &rect ) == ERROR) return FALSE;
+    if (GetRgnBox( dc->w.hGCClipRgn, &rect ) == ERROR) return FALSE;
     pixel = COLOR_ToPhysical( dc, color );
 
     if (!(image = XGetImage( display, dc->u.x.drawable,
diff --git a/windows/keyboard.c b/windows/keyboard.c
index ab15b9d..e02ebd7 100644
--- a/windows/keyboard.c
+++ b/windows/keyboard.c
@@ -3,9 +3,6 @@
  *
  * Copyright 1993 Bob Amstadt
  */
-
-static char Copyright[] = "Copyright  Bob Amstadt, 1993";
-
 #include <string.h>
 #include "win.h"
 #include "windows.h"
diff --git a/windows/mdi.c b/windows/mdi.c
index 43abdf4..ee6f575 100644
--- a/windows/mdi.c
+++ b/windows/mdi.c
@@ -9,6 +9,7 @@
 #include <math.h>
 #include "windows.h"
 #include "win.h"
+#include "nonclient.h"
 #include "mdi.h"
 #include "user.h"
 #include "menu.h"
@@ -271,7 +272,7 @@
     SendMessage(child, WM_SIZE, SIZE_MAXIMIZED,
 		MAKELONG(w->rectClient.right-w->rectClient.left,
 			 w->rectClient.bottom-w->rectClient.top));
-    SendMessage(GetParent(parent), WM_NCPAINT, 1, 0);
+    SendMessage(GetParent(parent), WM_NCPAINT, 0, 0);
 
     return 0;
 }
@@ -298,7 +299,7 @@
     ci->flagChildMaximized = FALSE;
 
     ShowWindow(child, SW_RESTORE);		/* display the window */
-    SendMessage(GetParent(parent), WM_NCPAINT, 1, 0);
+    SendMessage(GetParent(parent), WM_NCPAINT, 0, 0);
     MDIBringChildToTop(parent, child, FALSE, FALSE);
 
     return 0;
@@ -496,7 +497,6 @@
     
     MDICLIENTINFO *ci;
     WND           *w;
-    LONG           rv;
     HDC            hdc, hdcMem;
     RECT           rect;
     WND           *wndPtr = WIN_FindWndPtr(hwndFrame);
@@ -512,11 +512,10 @@
 
     if (ci->flagChildMaximized && wndPtr && wndPtr->wIDmenu != 0)
     {
-	rv = NC_DoNCPaint( hwndFrame, (HRGN) 1, wParam, TRUE);
-    
+	NC_DoNCPaint( hwndFrame, wParam, TRUE);
+
 	hdc = GetDCEx(hwndFrame, 0, DCX_CACHE | DCX_WINDOW);
-	if (!hdc)
-	    return rv;
+	if (!hdc) return 0;
 
 	hdcMem = CreateCompatibleDC(hdc);
 
@@ -563,7 +562,7 @@
     else
 	DefWindowProc(hwndFrame, message, wParam, lParam);
 
-    return rv;
+    return 0;
 }
 
 /**********************************************************************
@@ -725,8 +724,8 @@
 	break;
 	
       case WM_NCPAINT:
-	return NC_DoNCPaint(hwnd, (HRGN)1, 
-			    hwnd == ci->hwndActiveChild);
+	NC_DoNCPaint( hwnd, hwnd == ci->hwndActiveChild, FALSE );
+        return 0;
 
       case WM_SYSCOMMAND:
 	switch (wParam)
diff --git a/windows/message.c b/windows/message.c
index 072635e..2fd510e 100644
--- a/windows/message.c
+++ b/windows/message.c
@@ -209,7 +209,7 @@
 static BOOL MSG_TranslateMouseMsg( MSG *msg, BOOL remove )
 {
     BOOL eatMsg = FALSE;
-    LONG hittest_result;
+    INT hittest_result;
     static DWORD lastClickTime = 0;
     static WORD  lastClickMsg = 0;
     static POINT lastClickPos = { 0, 0 };
@@ -231,14 +231,14 @@
 
       /* Send the WM_NCHITTEST message */
 
-    hittest_result = SendMessage( msg->hwnd, WM_NCHITTEST, 0,
-				  MAKELONG( msg->pt.x, msg->pt.y ) );
+    hittest_result = (INT)SendMessage( msg->hwnd, WM_NCHITTEST, 0,
+                                       MAKELONG( msg->pt.x, msg->pt.y ) );
     while ((hittest_result == HTTRANSPARENT) && (msg->hwnd))
     {
 	msg->hwnd = WINPOS_NextWindowFromPoint( msg->hwnd, msg->pt );
 	if (msg->hwnd)
-	    hittest_result = SendMessage( msg->hwnd, WM_NCHITTEST, 0,
-					  MAKELONG( msg->pt.x, msg->pt.y ) );
+	    hittest_result = (INT)SendMessage( msg->hwnd, WM_NCHITTEST, 0,
+                                             MAKELONG( msg->pt.x, msg->pt.y ));
     }
     if (!msg->hwnd) msg->hwnd = GetDesktopWindow();
 
diff --git a/windows/nonclient.c b/windows/nonclient.c
index bab7953..6d0903f 100644
--- a/windows/nonclient.c
+++ b/windows/nonclient.c
@@ -537,33 +537,18 @@
  *           NC_DoNCPaint
  *
  * Paint the non-client area.
- * 'hrgn' is the update rgn to use (in client coords) or 1 if no update rgn.
  */
-void NC_DoNCPaint( HWND hwnd, HRGN hrgn, BOOL active, BOOL suppress_menupaint )
+void NC_DoNCPaint( HWND hwnd, BOOL active, BOOL suppress_menupaint )
 {
     HDC hdc;
     RECT rect;
 
     WND *wndPtr = WIN_FindWndPtr( hwnd );
 
-    dprintf_nonclient(stddeb, "NC_DoNCPaint: %d %d\n", hwnd, hrgn );
-    if (!wndPtr || !hrgn) return;
-    if (!(wndPtr->dwStyle & WS_VISIBLE)) return; /* Nothing to do */
-    if (!(wndPtr->dwStyle & (WS_BORDER | WS_DLGFRAME | WS_THICKFRAME)) &&
-        !(wndPtr->dwExStyle & WS_EX_DLGMODALFRAME)) return; /* Nothing to do */
+    dprintf_nonclient(stddeb, "NC_DoNCPaint: %x %d\n", hwnd, active );
+    if (!wndPtr || !(wndPtr->dwStyle & WS_VISIBLE)) return; /* Nothing to do */
 
-    if (hrgn == 1) hdc = GetDCEx( hwnd, 0, DCX_USESTYLE | DCX_WINDOW );
-    else
-    {
-	  /* Make region relative to window area */
-	int xoffset = wndPtr->rectWindow.left - wndPtr->rectClient.left;
-	int yoffset = wndPtr->rectWindow.top - wndPtr->rectClient.top;
-	OffsetRgn( hrgn, -xoffset, -yoffset );
-	hdc = GetDCEx( hwnd, hrgn, DCX_USESTYLE|DCX_WINDOW|DCX_INTERSECTRGN );
-	OffsetRgn( hrgn, xoffset, yoffset );  /* Restore region */
-    }
-    if (!hdc) return;
-
+    if (!(hdc = GetDCEx( hwnd, 0, DCX_USESTYLE | DCX_WINDOW ))) return;
 
     /*
      * If this is an icon, we don't want to do any more nonclient painting
@@ -654,9 +639,9 @@
  *
  * Handle a WM_NCPAINT message. Called from DefWindowProc().
  */
-LONG NC_HandleNCPaint( HWND hwnd, HRGN hrgn )
+LONG NC_HandleNCPaint( HWND hwnd )
 {
-    NC_DoNCPaint( hwnd, hrgn, hwnd == GetActiveWindow(), FALSE );
+    NC_DoNCPaint( hwnd, hwnd == GetActiveWindow(), FALSE );
     return 0;
 }
 
@@ -668,7 +653,7 @@
  */
 LONG NC_HandleNCActivate( HWND hwnd, WORD wParam )
 {
-    NC_DoNCPaint( hwnd, (HRGN)1, wParam, FALSE );
+    NC_DoNCPaint( hwnd, wParam, FALSE );
     return TRUE;
 }
 
diff --git a/windows/painting.c b/windows/painting.c
index fe45db7..e44110b 100644
--- a/windows/painting.c
+++ b/windows/painting.c
@@ -10,6 +10,9 @@
 #include "win.h"
 #include "message.h"
 #include "gdi.h"
+#include "stddebug.h"
+/* #define DEBUG_WIN */
+#include "debug.h"
 
   /* Last CTLCOLOR id */
 #define CTLCOLOR_MAX   CTLCOLOR_STATIC
@@ -34,21 +37,29 @@
     wndPtr->hrgnUpdate = 0;
     wndPtr->flags &= ~(WIN_NEEDS_BEGINPAINT | WIN_INTERNAL_PAINT);
 
-    if (!(lps->hdc = GetDCEx( hwnd, hrgnUpdate,
-			      DCX_INTERSECTRGN | DCX_USESTYLE )))
+    if (wndPtr->flags & WIN_NEEDS_NCPAINT)
     {
-        fprintf( stderr, "GetDCEx() failed in BeginPaint(), hwnd=%d\n", hwnd );
-        DeleteObject( hrgnUpdate );
+        SendMessage( hwnd, WM_NCPAINT, 0, 0 );
+        wndPtr->flags &= ~WIN_NEEDS_NCPAINT;
+    }
+
+    lps->hdc = GetDCEx( hwnd, hrgnUpdate, DCX_INTERSECTRGN | DCX_USESTYLE );
+    DeleteObject( hrgnUpdate );
+    if (!lps->hdc)
+    {
+        fprintf( stderr, "GetDCEx() failed in BeginPaint(), hwnd=%x\n", hwnd );
         return 0;
     }
+
     GetRgnBox( InquireVisRgn(lps->hdc), &lps->rcPaint );
     DPtoLP( lps->hdc, (LPPOINT)&lps->rcPaint, 2 );
 
-    SendMessage( hwnd, WM_NCPAINT, hrgnUpdate, 0 );
-    DeleteObject( hrgnUpdate );
-
-    if (!(wndPtr->flags & WIN_ERASE_UPDATERGN)) lps->fErase = TRUE;
-    else lps->fErase = !SendMessage( hwnd, WM_ERASEBKGND, lps->hdc, 0 );
+    if (wndPtr->flags & WIN_NEEDS_ERASEBKGND)
+    {
+        lps->fErase = !SendMessage( hwnd, WM_ERASEBKGND, lps->hdc, 0 );
+        wndPtr->flags &= ~WIN_NEEDS_ERASEBKGND;
+    }
+    else lps->fErase = TRUE;
 
     return lps->hdc;
 }
@@ -86,7 +97,7 @@
     {
 	if (!hwndParent) return;
 	hbrush = (HBRUSH)SendMessage( hwndParent, WM_CTLCOLOR,
-				      hdc, hwnd | (hbrush << 16) );
+				      hdc, MAKELONG( hwnd, hbrush ) );
     }
     if (hbrush) FillRect( hdc, rect, hbrush );
 }
@@ -106,14 +117,23 @@
     if (!(wndPtr->dwStyle & WS_VISIBLE) || (wndPtr->flags & WIN_NO_REDRAW))
         return TRUE;  /* No redraw needed */
 
+    if (rectUpdate)
+    {
+        dprintf_win( stddeb, "RedrawWindow: %x %d,%d-%d,%d %x flags=%04x\n",
+                     hwnd, rectUpdate->left, rectUpdate->top,
+                     rectUpdate->right, rectUpdate->bottom, hrgnUpdate, flags);
+    }
+    else
+    {
+        dprintf_win( stddeb, "RedrawWindow: %x NULL %x flags=%04x\n",
+                     hwnd, hrgnUpdate, flags);
+    }
     GetClientRect( hwnd, &rectClient );
     rectWindow = wndPtr->rectWindow;
     OffsetRect(&rectWindow, -wndPtr->rectClient.left, -wndPtr->rectClient.top);
 
     if (flags & RDW_INVALIDATE)  /* Invalidate */
     {
-	if (flags & RDW_ERASE) wndPtr->flags |= WIN_ERASE_UPDATERGN;
-
 	if (hrgnUpdate)  /* Invalidate a region */
 	{
 	    if (flags & RDW_FRAME) tmpRgn = CreateRectRgnIndirect(&rectWindow);
@@ -162,11 +182,13 @@
 		wndPtr->hrgnUpdate = tmpRgn;
 	    }
 	}
+        if (flags & RDW_FRAME) wndPtr->flags |= WIN_NEEDS_NCPAINT;
+        if (flags & RDW_ERASE) wndPtr->flags |= WIN_NEEDS_ERASEBKGND;
 	flags |= RDW_FRAME;  /* Force invalidating the frame of children */
     }
     else if (flags & RDW_VALIDATE)  /* Validate */
     {
-	if (flags & RDW_NOERASE) wndPtr->flags &= ~WIN_ERASE_UPDATERGN;
+	if (flags & RDW_NOERASE) wndPtr->flags &= ~WIN_NEEDS_ERASEBKGND;
 	if (!(hrgn = CreateRectRgn( 0, 0, 0, 0 ))) return FALSE;
 
 	  /* Remove frame from update region */
@@ -231,22 +253,31 @@
 
       /* Erase/update window */
 
-    if (flags & RDW_UPDATENOW) UpdateWindow( hwnd );
+    if (flags & RDW_UPDATENOW) SendMessage( hwnd, WM_PAINT, 0, 0 );
     else if (flags & RDW_ERASENOW)
     {
-	HDC hdc = GetDCEx( hwnd, wndPtr->hrgnUpdate,
-			   DCX_INTERSECTRGN | DCX_USESTYLE );
-	if (hdc)
-	{
-            SendMessage( hwnd, WM_NCPAINT, wndPtr->hrgnUpdate, 0 );
-
+        if (wndPtr->flags & WIN_NEEDS_NCPAINT)
+        {
+            SendMessage( hwnd, WM_NCPAINT, 0, 0 );
+            wndPtr->flags &= ~WIN_NEEDS_NCPAINT;
+        }
+        if (wndPtr->flags & WIN_NEEDS_ERASEBKGND)
+        {
+            HDC hdc = GetDCEx( hwnd, wndPtr->hrgnUpdate,
+                               DCX_INTERSECTRGN | DCX_USESTYLE );
+            if (hdc)
+            {
               /* Don't send WM_ERASEBKGND to icons */
               /* (WM_ICONERASEBKGND is sent during processing of WM_NCPAINT) */
-            if (!(wndPtr->dwStyle & WS_MINIMIZE)
-                || !WIN_CLASS_INFO(wndPtr).hIcon)
-                SendMessage( hwnd, WM_ERASEBKGND, hdc, 0 );
-	    ReleaseDC( hwnd, hdc );
-	}
+                if (!(wndPtr->dwStyle & WS_MINIMIZE)
+                    || !WIN_CLASS_INFO(wndPtr).hIcon)
+                {
+                    if (SendMessage( hwnd, WM_ERASEBKGND, hdc, 0 ))
+                        wndPtr->flags &= ~WIN_NEEDS_ERASEBKGND;
+                }
+                ReleaseDC( hwnd, hdc );
+            }
+        }
     }
 
       /* Recursively process children */
@@ -294,10 +325,7 @@
  */
 void UpdateWindow( HWND hwnd )
 {
-    if (GetUpdateRect( hwnd, NULL, FALSE )) 
-    {
-	if (IsWindowVisible( hwnd )) SendMessage( hwnd, WM_PAINT, 0, 0 );
-    }
+    RedrawWindow( hwnd, NULL, 0, RDW_UPDATENOW | RDW_NOCHILDREN );
 }
 
 
@@ -372,27 +400,15 @@
 
     if (!wndPtr->hrgnUpdate)
     {
-	if (!(hrgnClip = CreateRectRgn( 0, 0, 0, 0 ))) return ERROR;
-	retval = CombineRgn( hrgn, hrgnClip, 0, RGN_COPY );
+        SetRectRgn( hrgn, 0, 0, 0, 0 );
+        return NULLREGION;
     }
-    else
-    {
-	hrgnClip = CreateRectRgn( 0, 0,
-			   wndPtr->rectClient.right-wndPtr->rectClient.left,
-			   wndPtr->rectClient.bottom-wndPtr->rectClient.top );
-	if (!hrgnClip) return ERROR;
-	retval = CombineRgn( hrgn, wndPtr->hrgnUpdate, hrgnClip, RGN_AND );
-	if (erase)
-	{
-	    HDC hdc = GetDCEx( hwnd, wndPtr->hrgnUpdate,
-			      DCX_INTERSECTRGN | DCX_USESTYLE );
-	    if (hdc)
-	    {
-		SendMessage( hwnd, WM_ERASEBKGND, hdc, 0 );
-		ReleaseDC( hwnd, hdc );
-	    }
-	}	
-    }
+    hrgnClip = CreateRectRgn( 0, 0,
+                             wndPtr->rectClient.right-wndPtr->rectClient.left,
+                             wndPtr->rectClient.bottom-wndPtr->rectClient.top);
+    if (!hrgnClip) return ERROR;
+    retval = CombineRgn( hrgn, wndPtr->hrgnUpdate, hrgnClip, RGN_AND );
+    if (erase) RedrawWindow( hwnd, NULL, 0, RDW_ERASENOW | RDW_NOCHILDREN );
     DeleteObject( hrgnClip );
     return retval;
 }
diff --git a/windows/scroll.c b/windows/scroll.c
index 4a1a51f..d662983 100644
--- a/windows/scroll.c
+++ b/windows/scroll.c
@@ -154,8 +154,8 @@
 
     if (flags | SW_INVALIDATE)
     {
-	RedrawWindow(hwnd, NULL, hrgnUpdate,
-		     RDW_INVALIDATE | ((flags & SW_ERASE) ? RDW_ERASENOW : 0));
+	RedrawWindow( hwnd, NULL, hrgnUpdate, RDW_INVALIDATE | RDW_ERASE |
+                      ((flags & SW_ERASE) ? RDW_ERASENOW : 0));
     }
 
     ReleaseDC(hwnd, hdc);
diff --git a/windows/win.c b/windows/win.c
index 779fbf7..809c333 100644
--- a/windows/win.c
+++ b/windows/win.c
@@ -3,9 +3,6 @@
  *
  * Copyright 1993, 1994 Alexandre Julliard
  */
-
-static char Copyright[] = "Copyright  Alexandre Julliard, 1993, 1994";
-
 #include <stdlib.h>
 #include <stdio.h>
 #include <string.h>
diff --git a/windows/winpos.c b/windows/winpos.c
index 659211e..6de8899 100644
--- a/windows/winpos.c
+++ b/windows/winpos.c
@@ -11,7 +11,6 @@
 #include "winpos.h"
 #include "stddebug.h"
 /* #define DEBUG_WIN */
-/* #undef  DEBUG_WIN */
 #include "debug.h"
 
 static HWND hwndActive = 0;  /* Currently active window */
@@ -274,7 +273,7 @@
 	     */
             MoveWindow(hwnd, wndPtr->ptIconPos.x, wndPtr->ptIconPos.y,
                        SYSMETRICS_CXICON, SYSMETRICS_CYICON, FALSE);
-            RedrawWindow( hwnd, NULL, 0, RDW_FRAME | RDW_ERASENOW );
+            RedrawWindow( hwnd, NULL, 0, RDW_FRAME | RDW_ERASE | RDW_ERASENOW);
 	    break;
 
 	case SW_SHOWNA:
@@ -604,7 +603,7 @@
             OffsetRect( &rect, -wndPtr->rectClient.left,
                         -wndPtr->rectClient.top );
             RedrawWindow( hwnd, &rect, 0, RDW_INVALIDATE | RDW_ALLCHILDREN |
-                          RDW_FRAME | (erase ? RDW_ERASENOW : RDW_ERASE) );
+                          RDW_FRAME | RDW_ERASE | (erase ? RDW_ERASENOW : 0) );
             hwndCur = curPtr->hwndNext;
         }
     }
@@ -620,7 +619,7 @@
             OffsetRect( &rect, -curPtr->rectClient.left,
                         -curPtr->rectClient.top );
             RedrawWindow( hwndCur, &rect, 0, RDW_INVALIDATE | RDW_ALLCHILDREN |
-                          RDW_FRAME | (erase ? RDW_ERASENOW : RDW_ERASE) );
+                          RDW_FRAME | RDW_ERASE | (erase ? RDW_ERASENOW : 0) );
             hwndCur = curPtr->hwndNext;
         }
     }
@@ -775,12 +774,13 @@
             HRGN hrgn3 = CreateRectRgn( 0, 0, 0, 0 );
             CombineRgn( hrgn3, hrgn1, hrgn2, RGN_DIFF );
             RedrawWindow( wndPtr->hwndParent, NULL, hrgn3,
-                          RDW_INVALIDATE | RDW_ALLCHILDREN | RDW_ERASENOW );
+                          RDW_INVALIDATE | RDW_ALLCHILDREN |
+                          RDW_ERASE | RDW_ERASENOW );
             if ((oldWindowRect.left != wndPtr->rectWindow.left) ||
                 (oldWindowRect.top != wndPtr->rectWindow.top))
             {
                 RedrawWindow( winpos->hwnd, NULL, 0, RDW_INVALIDATE |
-                              RDW_FRAME | RDW_ALLCHILDREN | RDW_ERASENOW );
+                      RDW_FRAME | RDW_ALLCHILDREN | RDW_ERASE | RDW_ERASENOW );
             }
             DeleteObject( hrgn1 );
             DeleteObject( hrgn2 );
@@ -794,9 +794,11 @@
         if (wndPtr->window)
         {
             XMapWindow( display, wndPtr->window );
-            MSG_Synchronize();
-            if (flags & SWP_NOREDRAW)  /* Validate the whole window */
-                RedrawWindow( winpos->hwnd, NULL, 0, RDW_VALIDATE );
+        }
+        else
+        {
+            RedrawWindow( winpos->hwnd, NULL, 0,
+                          RDW_INVALIDATE | RDW_FRAME | RDW_ERASE );
         }
     }
     else if (flags & SWP_HIDEWINDOW)
@@ -810,7 +812,7 @@
         {
             RedrawWindow( wndPtr->hwndParent, &wndPtr->rectWindow, 0,
                           RDW_INVALIDATE | RDW_FRAME |
-                          RDW_ALLCHILDREN | RDW_ERASENOW );
+                          RDW_ALLCHILDREN | RDW_ERASE | RDW_ERASENOW );
         }
         if ((winpos->hwnd == GetFocus()) || IsChild(winpos->hwnd, GetFocus()))
             SetFocus( GetParent(winpos->hwnd) );  /* Revert focus to parent */
@@ -835,23 +837,14 @@
 	    WINPOS_ChangeActiveWindow( winpos->hwnd, FALSE );
     }
     
-      /* Send WM_NCPAINT message if needed */
+      /* Repaint the window */
 
-    if (flags & SWP_SHOWWINDOW)
-    {
-	  /* Repaint the window frame and background */
-	RedrawWindow( winpos->hwnd, NULL, 0,
-		      RDW_INVALIDATE | RDW_FRAME | RDW_ERASENOW );
-    }
-    else
-    {
-	if ((flags & SWP_FRAMECHANGED) ||
-	    (!(flags & SWP_NOSIZE)) ||
-	    (!(flags & SWP_NOMOVE)) ||
-	    (!(flags & SWP_NOACTIVATE)) ||
-	    (!(flags & SWP_NOZORDER)))
-	        SendMessage( winpos->hwnd, WM_NCPAINT, 1, 0L );
-    }
+    if (wndPtr->window) MSG_Synchronize();  /* Wait for all expose events */
+    if (flags & SWP_FRAMECHANGED)
+        RedrawWindow( winpos->hwnd, NULL, 0,
+                      RDW_INVALIDATE | RDW_FRAME | RDW_ERASE );
+    RedrawWindow( winpos->hwnd, NULL, 0,
+                  (flags & SWP_NOREDRAW) ? RDW_VALIDATE : RDW_ERASENOW );
 
       /* And last, send the WM_WINDOWPOSCHANGED message */