Index: trunk/src/user32/Makefile
===================================================================
--- trunk/src/user32/Makefile	(revision 2382)
+++ trunk/src/user32/Makefile	(revision 2383)
@@ -1,3 +1,3 @@
-# $Id: Makefile,v 1.55 2000-01-08 14:15:05 sandervl Exp $
+# $Id: Makefile,v 1.56 2000-01-09 14:37:08 sandervl Exp $
 
 #
@@ -43,5 +43,5 @@
         win32wbasepos.obj oslibres.obj dummy.obj oslibmenu.obj dc.obj timer.obj \
         caret.obj resource.obj winproc.obj text.obj oslibmsgtranslate.obj \
-        windlgmsg.obj windlg.obj win32wdesktop.obj pmtitlebar.obj
+        windlgmsg.obj windlg.obj win32wdesktop.obj pmtitlebar.obj win32wbasepaint.obj
 
 
@@ -136,4 +136,5 @@
 win32wbase.obj:   win32wbase.cpp win32class.h win32wbase.h win32dlg.h gen_object.h $(PDWIN32_INCLUDE)\heapshared.h oslibwin.h win32wndchild.h  $(PDWIN32_INCLUDE)\winres.h oslibres.h win32wndhandle.h oslibdos.h dc.h pmframe.h win32wdesktop.h controls.h winmouse.h $(PDWIN32_INCLUDE)\win\winproc.h $(PDWIN32_INCLUDE)\win\hook.h oslibmsg.h pmtitlebar.h
 win32wbasepos.obj: win32wbasepos.cpp win32class.h win32wbase.h win32dlg.h gen_object.h $(PDWIN32_INCLUDE)\heapshared.h oslibwin.h win32wndchild.h  $(PDWIN32_INCLUDE)\winres.h oslibres.h win32wndhandle.h oslibdos.h dc.h pmframe.h win32wdesktop.h
+win32wbasepaint.obj: win32wbasepaint.cpp win32class.h win32wbase.h win32dlg.h gen_object.h $(PDWIN32_INCLUDE)\heapshared.h oslibwin.h win32wndchild.h  $(PDWIN32_INCLUDE)\winres.h oslibres.h win32wndhandle.h oslibdos.h dc.h pmframe.h win32wdesktop.h controls.h winmouse.h $(PDWIN32_INCLUDE)\win\winproc.h $(PDWIN32_INCLUDE)\win\hook.h oslibmsg.h pmtitlebar.h
 win32wnd.obj:   win32wnd.cpp win32class.h win32wbase.h win32wnd.h win32dlg.h gen_object.h $(PDWIN32_INCLUDE)\heapshared.h oslibwin.h win32wndchild.h  $(PDWIN32_INCLUDE)\winres.h oslibres.h win32wndhandle.h oslibdos.h oslibmenu.h
 win32dlg.obj:   win32dlg.cpp win32class.h win32wbase.h win32dlg.h gen_object.h $(PDWIN32_INCLUDE)\heapshared.h oslibwin.h win32wndchild.h oslibmsg.h controls.h $(PDWIN32_INCLUDE)\win\winproc.h
@@ -167,5 +168,5 @@
 
 clean:
-        $(RM) *.obj *.lib *.dll *.map *.pch *.res *.lrf resource.asm *.lrf
+        $(RM) *.obj *.lib *.dll *.map *.pch *.res *.lrf resource.asm
         $(RM) $(PDWIN32_BIN)\$(TARGET).dll
         $(RM) $(PDWIN32_LIB)\$(TARGET).lib
Index: trunk/src/user32/loadres.cpp
===================================================================
--- trunk/src/user32/loadres.cpp	(revision 2382)
+++ trunk/src/user32/loadres.cpp	(revision 2383)
@@ -1,3 +1,3 @@
-/* $Id: loadres.cpp,v 1.17 1999-12-30 11:20:34 sandervl Exp $ */
+/* $Id: loadres.cpp,v 1.18 2000-01-09 14:37:09 sandervl Exp $ */
 
 /*
@@ -390,4 +390,6 @@
  HBITMAP hBitmap = 0;
 
+  return LoadBitmapA((hinst == 0) ? hInstanceUser32:hinst,lpszBitmap,0,0,0);
+#if 0
   if (!hinst)
   {
@@ -399,5 +401,5 @@
   } else hBitmap = LoadBitmapA(hinst, lpszBitmap, 0, 0, 0);
   dprintf(("LoadBitmapA returned %08xh\n", hBitmap));
-
+#endif
   return(hBitmap);
 }
@@ -409,21 +411,11 @@
  HBITMAP hBitmap = 0;
 
-  if (!hinst)
-  {
-    if(IsSystemBitmap((ULONG *)&lpszBitmap))
-    {
-      hBitmap = O32_LoadBitmap(hInstanceUser32,(LPCSTR)lpszBitmap);
-      if (!hBitmap) hBitmap = O32_LoadBitmap(hinst,(LPCSTR)lpszBitmap);
-    } else hBitmap = 0;
-  } else
-  {
-    if(HIWORD(lpszBitmap) != 0)
-      lpszBitmap = (LPWSTR)UnicodeToAsciiString((LPWSTR)lpszBitmap);
-
-    hBitmap = LoadBitmapA(hinst, (LPSTR)lpszBitmap, 0, 0, 0);
-
-    if(HIWORD(lpszBitmap) != 0)
-      FreeAsciiString((LPSTR)lpszBitmap);
-  }
+  if(HIWORD(lpszBitmap) != 0)
+    lpszBitmap = (LPWSTR)UnicodeToAsciiString((LPWSTR)lpszBitmap);
+
+  hBitmap = LoadBitmapA((hinst == 0) ? hInstanceUser32:hinst, (LPSTR)lpszBitmap, 0, 0, 0);
+
+  if(HIWORD(lpszBitmap) != 0)
+    FreeAsciiString((LPSTR)lpszBitmap);
 
   dprintf(("LoadBitmapW returned %08xh\n", hBitmap));
Index: trunk/src/user32/oslibmsgtranslate.cpp
===================================================================
--- trunk/src/user32/oslibmsgtranslate.cpp	(revision 2382)
+++ trunk/src/user32/oslibmsgtranslate.cpp	(revision 2383)
@@ -1,3 +1,3 @@
-/* $Id: oslibmsgtranslate.cpp,v 1.10 2000-01-08 16:53:38 sandervl Exp $ */
+/* $Id: oslibmsgtranslate.cpp,v 1.11 2000-01-09 14:37:09 sandervl Exp $ */
 /*
  * Window message translation functions for OS/2
@@ -7,4 +7,7 @@
  * Copyright 1999      Daniela Engert (dani@ngrt.de)
  * Copyright 1999      Rene Pronk (R.Pronk@twi.tudelft.nl)
+ *
+ * NOTE: WM_NCHITTEST messages are sent whenever the mouse cursor moves or a mouse button is clicked/released
+ *       (directly when receiving those messages)
  *
  * Project Odin Software License can be found in LICENSE.TXT
@@ -119,5 +122,5 @@
             fIsFrameControl = (win32wnd != 0);
         }
-        //NOTE: We only translate WM_PAINT/WM_HITTEST & mouse messages; the rest must not be seen by win32 apps
+        //NOTE: We only translate WM_PAINT, WM_ACTIVATE & mouse messages; the rest must not be seen by win32 apps
   }
   //PostThreadMessage posts WIN32APP_POSTMSG msg without window handle
@@ -226,6 +229,6 @@
         //     this message
         if(lpRect->right == thdb->wp.x+thdb->wp.cx && lpRect->bottom == thdb->wp.y+thdb->wp.cy) {
-                winMsg->message    = WINWM_WINDOWPOSCHANGED;
-                winMsg->lParam = (LPARAM)&thdb->wp;
+                winMsg->message = WINWM_WINDOWPOSCHANGED;
+                winMsg->lParam  = (LPARAM)&thdb->wp;
         }
         else {
@@ -252,7 +255,15 @@
         }
 
-        winMsg->message = WINWM_ACTIVATE;
-        winMsg->wParam  = MAKELONG((SHORT1FROMMP(os2Msg->mp1)) ? WA_ACTIVE_W : WA_INACTIVE_W, fMinimized);
-        winMsg->lParam  = (LPARAM)hwndActivate;
+        if(fIsFrameControl) {
+            fTranslateFrameControlMsg = TRUE; //we want a win32 app to see this msg for a frame control
+            winMsg->message = WINWM_NCACTIVATE;
+            winMsg->wParam  = SHORT1FROMMP(os2Msg->mp1);
+        }
+        else
+        {
+            winMsg->message = WINWM_ACTIVATE;
+            winMsg->wParam  = MAKELONG((SHORT1FROMMP(os2Msg->mp1)) ? WA_ACTIVE_W : WA_INACTIVE_W, fMinimized);
+            winMsg->lParam  = (LPARAM)hwndActivate;
+        }
         break;
     }
@@ -292,12 +303,17 @@
     case WM_BUTTON3UP:
     case WM_BUTTON3DBLCLK:
+    {
+     ULONG hittest;
+
         if(fIsFrameControl) {
             fTranslateFrameControlMsg = TRUE; //we want a win32 app to see this msg for a frame control
         }
 
+        hittest = win32wnd->MsgHitTest(winMsg->pt.x, winMsg->pt.y);
+
         //WM_NC*BUTTON* is posted when the cursor is in a non-client area of the window
-        if(win32wnd->lastHitTestVal != HTCLIENT_W) {
+        if(hittest != HTCLIENT_W) {
             winMsg->message = WINWM_NCLBUTTONDOWN + (os2Msg->msg - WM_BUTTON1DOWN);
-            winMsg->wParam  = win32wnd->lastHitTestVal;
+            winMsg->wParam  = hittest;
             winMsg->lParam  = MAKELONG(winMsg->pt.x, winMsg->pt.y); //screen coordinates
         }
@@ -311,6 +327,6 @@
             winMsg->lParam  = MAKELONG(ClientPoint.x, ClientPoint.y); //client coordinates
         }
-
-        break;
+        break;
+    }
 
     case WM_BUTTON2MOTIONSTART:
@@ -327,5 +343,5 @@
     case WM_MOUSEMOVE:
     {
-        ULONG keystate = 0, setcursormsg = WINWM_MOUSEMOVE;
+        ULONG keystate = 0, setcursormsg = WINWM_MOUSEMOVE, hittest;
 
         if(fIsFrameControl) {
@@ -344,9 +360,11 @@
             keystate |= MK_CONTROL_W;
 
+        hittest = win32wnd->MsgHitTest(winMsg->pt.x, winMsg->pt.y);
+
         //WM_NCMOUSEMOVE is posted when the cursor moves into a non-client area of the window
-        if(win32wnd->lastHitTestVal != HTCLIENT_W)
+        if(hittest != HTCLIENT_W)
         {
           setcursormsg   = WINWM_NCMOUSEMOVE;
-          winMsg->wParam = (WPARAM)win32wnd->lastHitTestVal;
+          winMsg->wParam = (WPARAM)hittest;
           winMsg->lParam = MAKELONG(winMsg->pt.x,winMsg->pt.y);
         }
@@ -546,5 +564,6 @@
 
         if(wndParams->fsStatus & WPM_TEXT) {
-            win32wnd->MsgSetText(wndParams->pszText, wndParams->cchText);
+            winMsg->message = WINWM_SETTEXT;
+            winMsg->lParam  = (LPARAM)wndParams->pszText;
             break;
         }
@@ -585,20 +604,4 @@
         }
         else    winMsg->message = WINWM_PAINT;
-        break;
-    }
-
-    case WM_HITTEST:
-    {
-        OSLIBPOINT pt;
-
-        fTranslateFrameControlMsg = TRUE; //we want a win32 app to see this msg for a frame control
-
-        pt.x = (*(POINTS *)&os2Msg->mp1).x;
-        pt.y = (*(POINTS *)&os2Msg->mp1).y;
-
-        mapOS2ToWin32Point(os2Msg->hwnd,OSLIB_HWND_DESKTOP,&pt);
-        winMsg->message  = WINWM_NCHITTEST;
-        winMsg->wParam  = 0;
-        winMsg->lParam  = MAKELONG((USHORT)pt.x, (USHORT)pt.y);
         break;
     }
Index: trunk/src/user32/oslibwin.cpp
===================================================================
--- trunk/src/user32/oslibwin.cpp	(revision 2382)
+++ trunk/src/user32/oslibwin.cpp	(revision 2383)
@@ -1,3 +1,3 @@
-/* $Id: oslibwin.cpp,v 1.57 2000-01-08 14:15:06 sandervl Exp $ */
+/* $Id: oslibwin.cpp,v 1.58 2000-01-09 14:37:09 sandervl Exp $ */
 /*
  * Window API wrappers for OS/2
@@ -175,13 +175,19 @@
   else
   {
-    if((dwStyle & WS_CAPTION_W) == WS_DLGFRAME_W)
+    if((dwStyle & WS_CAPTION_W) == WS_DLGFRAME_W) {
         *OSFrameStyle |= FCF_DLGBORDER;
+        *borderHeight = *borderWidth = 2; //TODO: Correct?
+    }
     else
     {
-        if((dwStyle & WS_CAPTION_W) == WS_CAPTION_W)
+        if((dwStyle & WS_CAPTION_W) == WS_CAPTION_W) {
             *OSFrameStyle |= (FCF_TITLEBAR | FCF_BORDER);
+            *borderHeight = *borderWidth = 1;
+        }
         else
-        if(dwStyle & WS_BORDER_W)
+        if(dwStyle & WS_BORDER_W) {
             *OSFrameStyle |= FCF_BORDER;
+            *borderHeight = *borderWidth = 1;
+        }
     }
 
@@ -191,6 +197,4 @@
           *OSFrameStyle |= FCF_HORZSCROLL;
 
-    if(dwStyle & WS_SYSMENU_W)
-          *OSFrameStyle |= FCF_SYSMENU;
     if(dwStyle & WS_THICKFRAME_W)
           *OSFrameStyle |= FCF_SIZEBORDER;        //??
@@ -198,4 +202,6 @@
     //SvL: We subclass the titlebar control when win32 look is selected
     if(fOS2Look) {
+    	if(dwStyle & WS_SYSMENU_W)
+          *OSFrameStyle |= FCF_SYSMENU;
     	if(dwStyle & WS_MINIMIZEBOX_W)
           *OSFrameStyle |= FCF_MINBUTTON;
@@ -1165,2 +1171,21 @@
 //******************************************************************************
 //******************************************************************************
+HWND OSLibWinGetFrameControlHandle(HWND hwndFrame, int framecontrol, RECT *lpRect)
+{
+    switch(framecontrol) {
+    case OSLIB_FID_TITLEBAR:
+	framecontrol = FID_TITLEBAR;
+	break;
+    case OSLIB_FID_SYSMENU:
+	framecontrol = FID_SYSMENU;
+	break;
+    case OSLIB_FID_MENU:
+	framecontrol = FID_MENU;
+	break;
+    default:
+	return 0;
+    }
+    return WinWindowFromID(hwndFrame, framecontrol);
+}
+//******************************************************************************
+//******************************************************************************
Index: trunk/src/user32/oslibwin.h
===================================================================
--- trunk/src/user32/oslibwin.h	(revision 2382)
+++ trunk/src/user32/oslibwin.h	(revision 2383)
@@ -1,3 +1,3 @@
-/* $Id: oslibwin.h,v 1.32 2000-01-08 14:15:06 sandervl Exp $ */
+/* $Id: oslibwin.h,v 1.33 2000-01-09 14:37:09 sandervl Exp $ */
 /*
  * Window API wrappers for OS/2
@@ -289,4 +289,5 @@
 
 HWND  OSLibWinIsFrameControl(HWND hwnd);
+HWND  OSLibWinGetFrameControlHandle(HWND hwndFrame, int framecontrol);
  
 #endif //__OSLIBWIN_H__
Index: trunk/src/user32/pmframe.cpp
===================================================================
--- trunk/src/user32/pmframe.cpp	(revision 2382)
+++ trunk/src/user32/pmframe.cpp	(revision 2383)
@@ -1,3 +1,3 @@
-/* $Id: pmframe.cpp,v 1.33 2000-01-08 14:15:06 sandervl Exp $ */
+/* $Id: pmframe.cpp,v 1.34 2000-01-09 14:37:09 sandervl Exp $ */
 /*
  * Win32 Frame Managment Code for OS/2
@@ -234,5 +234,4 @@
       //CB: call WM_NCCALCSIZE and set client pos
       //    WM_PAINT -> WM_NCPAINT
-      //    WM_HITTEST -> MsgHitTest()
       //    mouse messages -> MsgButton()
       goto RunDefFrameProc;
@@ -320,4 +319,11 @@
         dprintf(("PMFRAME: WM_WINDOWPOSCHANGED (%x) %x %x (%d,%d) (%d,%d)", mp2, win32wnd->getWindowHandle(), pswp->fl, pswp->x, pswp->y, pswp->cx, pswp->cy));
 
+	//Signal to the children that their parent's window rect has changed
+        //(the children don't always receive a notification -> their window
+        // rectangle (in screen coordinates) will get out of sync)
+        if(pswp->fl & (SWP_MOVE | SWP_SIZE)) {
+		win32wnd->setWindowRectChanged();
+        }
+
         RestoreOS2TIB();
         rc = OldFrameProc(hwnd,msg,mp1,mp2);
@@ -337,7 +343,8 @@
         OSLibMapSWPtoWINDOWPOSFrame(pswp, &wp, &swpOld, hParent, hwnd);
 
-        win32wnd->setWindowRect(wp.x, wp.y, wp.x+wp.cx, wp.y+wp.cy);
-        win32wnd->setClientRect(swpOld.x, swpOld.y, swpOld.x + swpOld.cx, swpOld.y + swpOld.cy);
-
+        if(pswp->fl & (SWP_MOVE | SWP_SIZE)) {
+        	win32wnd->setWindowRect(wp.x, wp.y, wp.x+wp.cx, wp.y+wp.cy);
+        	win32wnd->setClientRect(swpOld.x, swpOld.y, swpOld.x + swpOld.cx, swpOld.y + swpOld.cy);
+	}
         if(win32wnd->CanReceiveSizeMsgs())
           win32wnd->MsgPosChanged((LPARAM)&wp);
Index: trunk/src/user32/pmtitlebar.cpp
===================================================================
--- trunk/src/user32/pmtitlebar.cpp	(revision 2382)
+++ trunk/src/user32/pmtitlebar.cpp	(revision 2383)
@@ -1,3 +1,3 @@
-/* $Id: pmtitlebar.cpp,v 1.1 2000-01-08 14:15:38 sandervl Exp $ */
+/* $Id: pmtitlebar.cpp,v 1.2 2000-01-09 14:37:10 sandervl Exp $ */
 /*
  * Win32 Titlebar Managment Code for OS/2
@@ -6,4 +6,7 @@
  * Copyright 2000 by Christoph Bratschi (cbratschi@datacomm.ch)
  *
+ *
+ * NOTE:  When fOS2Look == TRUE, mouse message & painting is handled by us
+ *        (not by the PM titlebar control)
  *
  * Project Odin Software License can be found in LICENSE.TXT
@@ -27,4 +30,5 @@
 #include "oslibmsg.h"
 #include "pmtitlebar.h"
+#include "pmwindow.h"
 
 //******************************************************************************
@@ -50,7 +54,4 @@
   OldTitleBarProc = (PFNWP)win32wnd->getOldTitleBarProc();
 
-  if(msg == WM_MOUSEMOVE) {
-	rc = 0;
-  }
   if((thdb->msgstate & 1) == 0)
   {//message that was sent directly to our window proc handler; translate it here
@@ -79,31 +80,12 @@
   switch(pWinMsg->message)
   {
-  case WINWM_NCHITTEST:
-  {
-      DWORD res;
-
-      // Only send this message if the window is enabled
-      if (!WinIsWindowEnabled(hwnd))
-        res = HT_ERROR;
-      else if (win32wnd->getIgnoreHitTest())
-        res = HT_NORMAL;
-      else
-      {
-        dprintf(("USER32: WM_HITTEST %x (%d,%d)",hwnd,(*(POINTS *)&mp1).x,(*(POINTS *)&mp1).y));
-
-        //CB: WinWindowFromPoint: PM sends WM_HITTEST -> loop -> stack overflow
-        win32wnd->setIgnoreHitTest(TRUE);
-        res = win32wnd->MsgHitTest(pWinMsg);
-        win32wnd->setIgnoreHitTest(FALSE);
-      }
-      RestoreOS2TIB();
-      return (MRESULT)res;
-  }
   case WINWM_NCPAINT:
         win32wnd->DispatchMsgA(pWinMsg);
-	if(win32wnd->getDefWndProcCalled())
-        	goto RunDefTitleBarProc;
 	goto RunDefWndProc;
 
+  case WINWM_NCACTIVATE:
+        win32wnd->DispatchMsgA(pWinMsg);
+        break;
+	
   case WINWM_NCLBUTTONDOWN:
   case WINWM_NCLBUTTONUP:
@@ -116,7 +98,4 @@
   case WINWM_NCRBUTTONDBLCLK:
         win32wnd->MsgButton(pWinMsg);
-	if(win32wnd->getDefWndProcCalled())
-        	goto RunDefTitleBarProc;
-
         rc = TRUE;
         break;
@@ -124,8 +103,5 @@
   case WINWM_NCMOUSEMOVE:
   {
-        //OS/2 Window coordinates -> Win32 Window coordinates
         win32wnd->MsgMouseMove(pWinMsg);
-	if(win32wnd->getDefWndProcCalled())
-        	goto RunDefTitleBarProc;
         break;
   }
Index: trunk/src/user32/pmwindow.cpp
===================================================================
--- trunk/src/user32/pmwindow.cpp	(revision 2382)
+++ trunk/src/user32/pmwindow.cpp	(revision 2383)
@@ -1,3 +1,3 @@
-/* $Id: pmwindow.cpp,v 1.75 2000-01-08 14:15:07 sandervl Exp $ */
+/* $Id: pmwindow.cpp,v 1.76 2000-01-09 14:37:10 sandervl Exp $ */
 /*
  * Win32 Window Managment Code for OS/2
@@ -95,5 +95,5 @@
      (PSZ)WIN32_STDCLASS,               /* Window class name            */
      (PFNWP)Win32WindowProc,            /* Address of window procedure  */
-     CS_HITTEST,
+     0,
      NROF_WIN32WNDBYTES)) {
         dprintf(("WinRegisterClass Win32BaseWindow failed"));
@@ -472,26 +472,4 @@
         win32wnd->DispatchMsgA(pWinMsg);
         goto RunDefWndProc;
-
-    case WM_HITTEST:
-    {
-      DWORD res;
-
-      // Only send this message if the window is enabled
-      if (!WinIsWindowEnabled(hwnd))
-        res = HT_ERROR;
-      else if (win32wnd->getIgnoreHitTest())
-        res = HT_NORMAL;
-      else
-      {
-        dprintf(("USER32: WM_HITTEST %x (%d,%d)",hwnd,(*(POINTS *)&mp1).x,(*(POINTS *)&mp1).y));
-
-        //CB: WinWindowFromPoint: PM sends WM_HITTEST -> loop -> stack overflow
-        win32wnd->setIgnoreHitTest(TRUE);
-        res = win32wnd->MsgHitTest(pWinMsg);
-        win32wnd->setIgnoreHitTest(FALSE);
-      }
-      RestoreOS2TIB();
-      return (MRESULT)res;
-    }
 
     case WM_CONTEXTMENU:
Index: trunk/src/user32/win32wbase.cpp
===================================================================
--- trunk/src/user32/win32wbase.cpp	(revision 2382)
+++ trunk/src/user32/win32wbase.cpp	(revision 2383)
@@ -1,3 +1,3 @@
-/* $Id: win32wbase.cpp,v 1.134 2000-01-08 14:41:27 sandervl Exp $ */
+/* $Id: win32wbase.cpp,v 1.135 2000-01-09 14:37:11 sandervl Exp $ */
 /*
  * Win32 Window Base Class for OS/2
@@ -151,4 +151,5 @@
   fParentDC            = FALSE;
   fDefWndProcCalled    = FALSE;
+  fWindowRectChanged   = FALSE; //Set when parent window has been moved; cleared when window rect is updated
 
   windowNameA      = NULL;
@@ -193,5 +194,4 @@
   isIcon           = FALSE;
   lastHitTestVal   = HTOS_NORMAL;
-  fIgnoreHitTest   = FALSE;
   owner            = NULL;
   windowClass      = 0;
@@ -645,5 +645,6 @@
   subclassScrollBars(dwStyle & WS_HSCROLL,dwStyle & WS_VSCROLL);
 
-//  FrameSubclassTitleBar(this);
+  if(!fOS2Look)
+    FrameSubclassTitleBar(this);
 
   fakeWinBase.hwndThis     = OS2Hwnd;
@@ -864,19 +865,12 @@
 }
 //******************************************************************************
-//******************************************************************************
-ULONG Win32BaseWindow::MsgHitTest(MSG *msg)
-{
-  lastHitTestVal = SendInternalMessageA(WM_NCHITTEST, 0, MAKELONG((USHORT)msg->pt.x, (USHORT)msg->pt.y));
-  dprintf2(("MsgHitTest returned %x", lastHitTestVal));
-
-  if (lastHitTestVal == HTERROR)
-    return HTOS_ERROR;
-
-#if 0 //CB: problems with groupboxes, internal handling is better
-  if (lastHitTestVal == HTTRANSPARENT)
-    return HTOS_TRANSPARENT;
-#endif
-
-  return HTOS_NORMAL;
+// NOTE: WM_NCHITTEST messages are sent whenever the mouse cursor moves or a mouse button is clicked/released
+//       (directly when receiving those messages)
+//******************************************************************************
+ULONG Win32BaseWindow::MsgHitTest(ULONG x, ULONG y)
+{
+  lastHitTestVal = SendInternalMessageA(WM_NCHITTEST, 0, MAKELONG((USHORT)x, (USHORT)y));
+  dprintf(("MsgHitTest (%d,%d) (%d,%d) (%d,%d) returned %x", x, y, rectWindow.left, rectWindow.right, rectWindow.top, rectWindow.bottom, lastHitTestVal));
+  return lastHitTestVal;
 }
 //******************************************************************************
@@ -1239,114 +1233,4 @@
 }
 /***********************************************************************
- *           NC_HandleNCLButtonDown
- *
- * Handle a WM_NCLBUTTONDOWN message. Called from DefWindowProc().
- */
-LONG Win32BaseWindow::HandleNCLButtonDown(WPARAM wParam,LPARAM lParam)
-{
-  switch(wParam)  /* Hit test */
-  {
-    case HTCAPTION:
-      SendInternalMessageA(WM_SYSCOMMAND,SC_MOVE+HTCAPTION,lParam);
-      break;
-
-    case HTSYSMENU:
-      SendInternalMessageA(WM_SYSCOMMAND,SC_MOUSEMENU+HTSYSMENU,lParam);
-      break;
-
-    case HTMENU:
-      SendInternalMessageA(WM_SYSCOMMAND,SC_MOUSEMENU,lParam);
-      break;
-
-    case HTHSCROLL:
-      SendInternalMessageA(WM_SYSCOMMAND,SC_HSCROLL+HTHSCROLL,lParam);
-      break;
-
-    case HTVSCROLL:
-      SendInternalMessageA(WM_SYSCOMMAND,SC_VSCROLL+HTVSCROLL,lParam);
-      break;
-
-    case HTLEFT:
-    case HTRIGHT:
-    case HTTOP:
-    case HTTOPLEFT:
-    case HTTOPRIGHT:
-    case HTBOTTOM:
-    case HTBOTTOMLEFT:
-    case HTBOTTOMRIGHT:
-        /* make sure hittest fits into 0xf and doesn't overlap with HTSYSMENU */
-        SendInternalMessageA(WM_SYSCOMMAND,SC_SIZE+wParam-2,lParam);
-        break;
-    case HTBORDER:
-        break;
-  }
-
-  return 0;
-}
-//******************************************************************************
-//******************************************************************************
-LONG Win32BaseWindow::HandleNCLButtonUp(WPARAM wParam,LPARAM lParam)
-{
-  switch(wParam)  /* Hit test */
-  {
-    case HTMINBUTTON:
-      SendInternalMessageA(WM_SYSCOMMAND,SC_MINIMIZE,lParam);
-      break;
-
-    case HTMAXBUTTON:
-      SendInternalMessageA(WM_SYSCOMMAND,SC_MAXIMIZE,lParam);
-      break;
-
-    case HTCLOSE:
-      SendInternalMessageA(WM_SYSCOMMAND,SC_CLOSE,lParam);
-      break;
-  }
-
-  return 0;
-}
-/***********************************************************************
- *           NC_HandleNCLButtonDblClk
- *
- * Handle a WM_NCLBUTTONDBLCLK message. Called from DefWindowProc().
- */
-LONG Win32BaseWindow::HandleNCLButtonDblClk(WPARAM wParam,LPARAM lParam)
-{
-  /*
-   * if this is an icon, send a restore since we are handling
-   * a double click
-   */
-  if (dwStyle & WS_MINIMIZE)
-  {
-    SendInternalMessageA(WM_SYSCOMMAND,SC_RESTORE,lParam);
-    return 0;
-  }
-
-  switch(wParam)  /* Hit test */
-  {
-    case HTCAPTION:
-      /* stop processing if WS_MAXIMIZEBOX is missing */
-      if (dwStyle & WS_MAXIMIZEBOX)
-        SendInternalMessageA(WM_SYSCOMMAND,
-                      (dwStyle & WS_MAXIMIZE) ? SC_RESTORE : SC_MAXIMIZE,
-                      lParam);
-      break;
-
-    case HTSYSMENU:
-      if (!(GetClassWord(Win32Hwnd,GCW_STYLE) & CS_NOCLOSE))
-        SendInternalMessageA(WM_SYSCOMMAND,SC_CLOSE,lParam);
-      break;
-
-    case HTHSCROLL:
-      SendInternalMessageA(WM_SYSCOMMAND,SC_HSCROLL+HTHSCROLL,lParam);
-      break;
-
-    case HTVSCROLL:
-      SendInternalMessageA(WM_SYSCOMMAND,SC_VSCROLL+HTVSCROLL,lParam);
-      break;
-  }
-
-  return 0;
-}
-/***********************************************************************
  *           NC_HandleSysCommand
  *
@@ -1605,5 +1489,6 @@
         setStyle(getStyle() | WS_VISIBLE);
         OSLibWinEnableWindowUpdate(OS2HwndFrame,TRUE);
-      } else
+      }
+      else
       {
         if (getStyle() & WS_VISIBLE)
@@ -1615,19 +1500,4 @@
       return 0;
     }
-
-    case WM_NCPAINT:
-        return 0;
-
-    case WM_NCACTIVATE:
-        return TRUE;
-
-    case WM_NCCREATE:
-        return(TRUE);
-
-    case WM_NCDESTROY:
-        return 0;
-
-    case WM_NCCALCSIZE:
-        return NCHandleCalcSize(wParam, (NCCALCSIZE_PARAMS *)lParam);
 
     case WM_CTLCOLORMSGBOX:
@@ -1778,6 +1648,6 @@
           if( (getStyle() & WS_MINIMIZE) && getWindowClass()->getIcon())
           {
-            int x = (rectWindow.right - rectWindow.left - GetSystemMetrics(SM_CXICON))/2;
-            int y = (rectWindow.bottom - rectWindow.top - GetSystemMetrics(SM_CYICON))/2;
+            int x = (getWindowRect()->right - getWindowRect()->left - GetSystemMetrics(SM_CXICON))/2;
+            int y = (getWindowRect()->bottom - getWindowRect()->top - GetSystemMetrics(SM_CYICON))/2;
             dprintf(("Painting class icon: vis rect=(%i,%i - %i,%i)\n", ps.rcPaint.left, ps.rcPaint.top, ps.rcPaint.right, ps.rcPaint.bottom ));
             DrawIcon(hdc, x, y, getWindowClass()->getIcon() );
@@ -1791,12 +1661,42 @@
         return 0;
 
+    case WM_NCPAINT:
+        if(!fOS2Look) {
+            HandleNCPaint(wParam, FALSE);
+        }
+        return 0;
+
+    case WM_NCACTIVATE:
+        if(!fOS2Look) {
+            return HandleNCActivate(wParam);
+        }
+        return TRUE;
+
+    case WM_NCCREATE:
+        return(TRUE);
+
+    case WM_NCDESTROY:
+        return 0;
+
+    case WM_NCCALCSIZE:
+        return NCHandleCalcSize(wParam, (NCCALCSIZE_PARAMS *)lParam);
+
     case WM_NCLBUTTONDOWN:
-        return HandleNCLButtonDown(wParam,lParam);
+        if(!fOS2Look) {
+            return HandleNCLButtonDown(wParam,lParam);
+        }
+        return 0;
 
     case WM_NCLBUTTONUP:
-        return HandleNCLButtonUp(wParam,lParam);
+        if(!fOS2Look) {
+            return HandleNCLButtonUp(wParam,lParam);
+        }
+        return 0;
 
     case WM_NCLBUTTONDBLCLK:
-        return HandleNCLButtonDblClk(wParam,lParam);
+        if(!fOS2Look) {
+            return HandleNCLButtonDblClk(wParam,lParam);
+        }
+        return 0;
 
     case WM_NCRBUTTONDOWN:
@@ -1818,5 +1718,8 @@
       point.y = (SHORT)HIWORD(lParam);
 
-      return FrameHitTest(this,point.x,point.y);
+      if(fOS2Look) {
+                return FrameHitTest(this, point.x, point.y);
+      }
+      else      return HandleNCHitTest(point);
     }
 
@@ -2316,4 +2219,52 @@
 }
 //******************************************************************************
+//When our parent window is moved, we aren't notified of the change (rectWindow is in
+//screen coordinates, so it needs to be updated)
+//Set the fWindowRectChanged flag and do the same for all the children
+//Whenever getWindowRect is called and this flag is set, it refreshes the rectWindow structure
+//******************************************************************************
+void Win32BaseWindow::setWindowRectChanged()
+{
+ Win32BaseWindow *child;
+
+    fWindowRectChanged = TRUE;
+
+    child = (Win32BaseWindow *)getFirstChild();
+    while(child)
+    {
+        child->setWindowRectChanged();
+        child = (Win32BaseWindow *)child->getNextChild();
+    }
+}
+//******************************************************************************
+//******************************************************************************
+PRECT Win32BaseWindow::getWindowRect()
+{
+    if(fWindowRectChanged) {
+        OSLibWinQueryWindowRect(getOS2FrameWindowHandle(), &rectWindow, RELATIVE_TO_SCREEN);
+        fWindowRectChanged = FALSE;
+    }
+    return &rectWindow;
+}
+//******************************************************************************
+//******************************************************************************
+void Win32BaseWindow::setWindowRect(LONG left, LONG top, LONG right, LONG bottom)
+{
+    fWindowRectChanged = FALSE;
+
+    rectWindow.left   = left;
+    rectWindow.top    = top;
+    rectWindow.right  = right;
+    rectWindow.bottom = bottom;
+}
+//******************************************************************************
+//******************************************************************************
+void Win32BaseWindow::setWindowRect(PRECT rect)
+{
+    fWindowRectChanged = FALSE;
+
+    rectWindow = *rect;
+}
+//******************************************************************************
 //******************************************************************************
 BOOL Win32BaseWindow::SetWindowPos(HWND hwndInsertAfter, int x, int y, int cx, int cy, UINT fuFlags)
@@ -2882,10 +2833,4 @@
     return OSLibWinIsWindowVisible(OS2HwndFrame);
 #endif
-}
-//******************************************************************************
-//******************************************************************************
-BOOL Win32BaseWindow::GetWindowRect(PRECT pRect)
-{
-    return OSLibWinQueryWindowRect(OS2HwndFrame, pRect, RELATIVE_TO_SCREEN);
 }
 //******************************************************************************
Index: trunk/src/user32/win32wbase.h
===================================================================
--- trunk/src/user32/win32wbase.h	(revision 2382)
+++ trunk/src/user32/win32wbase.h	(revision 2383)
@@ -1,3 +1,3 @@
-/* $Id: win32wbase.h,v 1.67 2000-01-08 14:15:09 sandervl Exp $ */
+/* $Id: win32wbase.h,v 1.68 2000-01-09 14:37:12 sandervl Exp $ */
 /*
  * Win32 Window Base Class for OS/2
@@ -84,5 +84,5 @@
          ULONG  MsgEraseBackGround(HDC hdc);
          ULONG  MsgInitMenu(MSG *msg);
-         ULONG  MsgHitTest(MSG *msg);
+         ULONG  MsgHitTest(ULONG x, ULONG y);
          ULONG  MsgNCPaint();
          ULONG  DispatchMsgA(MSG *msg);
@@ -110,7 +110,4 @@
          HWND   getOS2FrameWindowHandle()       { return OS2HwndFrame; };
  Win32WndClass *getWindowClass()                { return windowClass; };
-
-         BOOL   getIgnoreHitTest()              { return fIgnoreHitTest; }
-         VOID   setIgnoreHitTest(BOOL ignore)   { fIgnoreHitTest = ignore; }
 
 	 BOOL   getDefWndProcCalled()           { return fDefWndProcCalled; };
@@ -139,5 +136,4 @@
          PRECT  getClientRect()                 { return &rectClient; };
          void   setClientRect(PRECT rect)       { rectClient = *rect; };
-         PRECT  getWindowRect()                 { return &rectWindow; };
          void   setClientRect(LONG left, LONG top, LONG right, LONG bottom)
          {
@@ -145,10 +141,9 @@
                 rectClient.right = right; rectClient.bottom = bottom;
          };
-         void   setWindowRect(LONG left, LONG top, LONG right, LONG bottom)
-         {
-                rectWindow.left  = left;  rectWindow.top    = top;
-                rectWindow.right = right; rectWindow.bottom = bottom;
-         };
-         void   setWindowRect(PRECT rect)       { rectWindow = *rect; };
+         PRECT  getWindowRect();
+         void   setWindowRect(LONG left, LONG top, LONG right, LONG bottom);
+         void   setWindowRect(PRECT rect);
+	 void   setWindowRectChanged();
+
          DWORD  getFlags()                      { return flags; };
          void   setFlags(DWORD newflags)        { flags = newflags; };
@@ -196,5 +191,4 @@
          BOOL   IsWindowUnicode();
 
-         BOOL   GetWindowRect(PRECT pRect);
          int    GetWindowTextLength();
          int    GetWindowTextA(LPSTR lpsz, int cch);
@@ -304,22 +298,23 @@
         DWORD   contextHelpId;
         LONG    lastHitTestVal;         //Last value returned by WM_NCHITTEST handler
-        BOOL    fIgnoreHitTest;         //Use WinWindowFromPoint during WM_HITTEST
-
-        BOOL    isIcon;
-        BOOL    fFirstShow;
-        BOOL    fIsDialog;
-        BOOL    fIsModalDialog;
-        BOOL    fIsModalDialogOwner;
+
         HWND    OS2HwndModalDialog;
-        BOOL    fInternalMsg;           //Used to distinguish between messages
-                                        //sent by PM and those sent by apps
-        BOOL    fNoSizeMsg;
-        BOOL    fIsDestroyed;
-        BOOL    fDestroyWindowCalled;   //DestroyWindow was called for this window
-        BOOL    fCreated;
-        BOOL    fTaskList;              //should be listed in PM tasklist or not
-        BOOL    fParentDC;
-
-        BOOL    fDefWndProcCalled;      //set when DefWndProc called; used in PM window handlers to determine what to do next
+
+        ULONG   isIcon               :1,
+        	fFirstShow	     :1,
+        	fIsDialog            :1,
+        	fIsModalDialog       :1,
+        	fIsModalDialogOwner  :1,
+        	fInternalMsg         :1, //Used to distinguish between messages
+                                         //sent by PM and those sent by apps
+        	fNoSizeMsg           :1,
+        	fIsDestroyed         :1,
+        	fDestroyWindowCalled :1, //DestroyWindow was called for this window
+        	fCreated             :1,
+        	fTaskList            :1, //should be listed in PM tasklist or not
+        	fParentDC            :1, 
+        	fIsSubclassedOS2Wnd  :1, //subclassed OS/2 window: Netscape plug-in/scrollbar
+        	fDefWndProcCalled    :1, //set when DefWndProc called; used in PM window handlers to determine what to do next
+                fWindowRectChanged   :1; //Set when parent window has been moved; cleared when window rect is updated
 
  	HRGN    hWindowRegion;
@@ -334,5 +329,4 @@
 
         PVOID   pOldWndProc;
-        BOOL    fIsSubclassedOS2Wnd;  //subclassed OS/2 window: Netscape plug-in/scrollbar
 
    Win32BaseWindow *owner;
@@ -365,7 +359,4 @@
         void  GetMinMaxInfo(POINT *maxSize, POINT *maxPos, POINT *minTrack, POINT *maxTrack );
         LONG  HandleWindowPosChanging(WINDOWPOS *winpos);
-        LONG  HandleNCLButtonDown(WPARAM wParam,LPARAM lParam);
-        LONG  HandleNCLButtonUp(WPARAM wParam,LPARAM lParam);
-        LONG  HandleNCLButtonDblClk(WPARAM wParam,LPARAM lParam);
         LONG  HandleSysCommand(WPARAM wParam, POINT *pt32);
 
@@ -386,4 +377,25 @@
 friend BOOL  OS2ToWinMsgTranslate(void *pThdb, QMSG *os2Msg, MSG *winMsg, BOOL isUnicode, BOOL fTranslateExtraMsgs);
 #endif
+
+        //painting & non-client methods
+        BOOL  DrawSysButton(HDC hdc,BOOL down);
+        BOOL  DrawGrayButton(HDC hdc,int x,int y);
+        VOID  DrawCloseButton(HDC hdc,BOOL down,BOOL bGrayed);
+        VOID  DrawMaxButton(HDC hdc,BOOL down,BOOL bGrayed);
+        VOID  DrawMinButton(HDC hdc,BOOL down,BOOL bGrayed);
+        VOID  DrawCaption(HDC hdc,RECT *rect,BOOL active);
+        VOID  DrawFrame(HDC hdc,RECT *rect,BOOL dlgFrame,BOOL active);
+
+        VOID  GetInsideRect(RECT *rect);
+
+        VOID  TrackMinMaxBox(WORD wParam);
+        VOID  TrackCloseButton(WORD wParam);
+
+        VOID  HandleNCPaint(HRGN clip,BOOL suppress_menupaint);
+	LONG  HandleNCHitTest(POINT pt);
+        LONG  HandleNCActivate(WPARAM wParam);
+        LONG  HandleNCLButtonDown(WPARAM wParam,LPARAM lParam);
+        LONG  HandleNCLButtonUp(WPARAM wParam,LPARAM lParam);
+        LONG  HandleNCLButtonDblClk(WPARAM wParam,LPARAM lParam);
 
 public:
Index: trunk/src/user32/win32wbasepaint.cpp
===================================================================
--- trunk/src/user32/win32wbasepaint.cpp	(revision 2383)
+++ trunk/src/user32/win32wbasepaint.cpp	(revision 2383)
@@ -0,0 +1,935 @@
+/* $Id: win32wbasepaint.cpp,v 1.1 2000-01-09 14:38:30 sandervl Exp $ */
+/*
+ * Win32 Window Base Class for OS/2
+ *
+ * Copyright 2000 Sander van Leeuwen (sandervl@xs4all.nl)
+ * Copyright 2000 Christoph Bratschi (cbratschi@datacomm.ch)
+ *
+ * Based on Wine code (windows\nonclient.c)
+ *
+ * Copyright 1994 Alexandre Julliard
+ *
+ * TODO: Not thread/process safe
+ *
+ * Project Odin Software License can be found in LICENSE.TXT
+ *
+ */
+#include <os2win.h>
+#include <win.h>
+#include <stdlib.h>
+#include <string.h>
+#include <stdarg.h>
+#include <assert.h>
+#include <misc.h>
+#include <heapstring.h>
+#include <win32wbase.h>
+#include <winres.h>
+#include "wndmsg.h"
+#include "oslibwin.h"
+#include "oslibmsg.h"
+#include "oslibutil.h"
+#include "oslibgdi.h"
+#include "oslibres.h"
+#include "oslibmenu.h"
+#include "oslibdos.h"
+#include "syscolor.h"
+#include "win32wndhandle.h"
+#include "dc.h"
+#include "pmframe.h"
+#include "pmtitlebar.h"
+#include "win32wdesktop.h"
+#include "pmwindow.h"
+#include "controls.h"
+
+#define HAS_DLGFRAME(style,exStyle) \
+    (((exStyle) & WS_EX_DLGMODALFRAME) || \
+     (((style) & WS_DLGFRAME) && !((style) & WS_THICKFRAME)))
+
+#define HAS_THICKFRAME(style,exStyle) \
+    (((style) & WS_THICKFRAME) && \
+     !((exStyle) & WS_EX_DLGMODALFRAME))
+
+#define HAS_THINFRAME(style) \
+    (((style) & WS_BORDER) || !((style) & (WS_CHILD | WS_POPUP)))
+
+#define HAS_BIGFRAME(style,exStyle) \
+    (((style) & (WS_THICKFRAME | WS_DLGFRAME)) || \
+     ((exStyle) & WS_EX_DLGMODALFRAME))
+
+#define HAS_ANYFRAME(style,exStyle) \
+    (((style) & (WS_THICKFRAME | WS_DLGFRAME | WS_BORDER)) || \
+     ((exStyle) & WS_EX_DLGMODALFRAME) || \
+     !((style) & (WS_CHILD | WS_POPUP)))
+
+#define HAS_3DFRAME(exStyle) \
+    ((exStyle & WS_EX_CLIENTEDGE) || (exStyle & WS_EX_STATICEDGE) || (exStyle & WS_EX_WINDOWEDGE))
+
+#define HAS_BORDER(style, exStyle) \
+    ((style & WS_BORDER) || HAS_THICKFRAME(style) || HAS_DLGFRAME(style,exStyle))
+
+#define IS_OVERLAPPED(style) \
+    !(style & (WS_CHILD | WS_POPUP))
+
+#define HAS_MENU(w) (!((w)->getStyle() & WS_CHILD) && ((w)->getWindowId() != 0))
+
+static HBITMAP hbitmapClose = 0;
+static HBITMAP hbitmapCloseD = 0;
+static HBITMAP hbitmapMinimize = 0;
+static HBITMAP hbitmapMinimizeD = 0;
+static HBITMAP hbitmapMaximize = 0;
+static HBITMAP hbitmapMaximizeD = 0;
+static HBITMAP hbitmapRestore = 0;
+static HBITMAP hbitmapRestoreD = 0;
+
+BYTE lpGrayMask[] = { 0xAA, 0xA0,
+                      0x55, 0x50,
+                      0xAA, 0xA0,
+                      0x55, 0x50,
+                      0xAA, 0xA0,
+                      0x55, 0x50,
+                      0xAA, 0xA0,
+                      0x55, 0x50,
+                      0xAA, 0xA0,
+                      0x55, 0x50};
+
+//******************************************************************************
+//******************************************************************************
+VOID Win32BaseWindow::TrackMinMaxBox(WORD wParam)
+{
+  MSG msg;
+  HDC hdc;
+  BOOL pressed = TRUE;
+  UINT state;
+
+  if (wParam == HTMINBUTTON)
+  {
+    /* If the style is not present, do nothing */
+    if (!(dwStyle & WS_MINIMIZEBOX))
+      return;
+    /* Check if the sysmenu item for minimize is there  */
+#if 0 //CB: todo
+    state = GetMenuState(hSysMenu,SC_MINIMIZE,MF_BYCOMMAND);
+#endif
+  } else
+  {
+    /* If the style is not present, do nothing */
+    if (!(dwStyle & WS_MAXIMIZEBOX))
+      return;
+    /* Check if the sysmenu item for maximize is there  */
+#if 0 //CB: todo
+    state = GetMenuState(hSysMenu, SC_MAXIMIZE, MF_BYCOMMAND);
+#endif
+  }
+  SetCapture(Win32Hwnd);
+  hdc = GetWindowDC(Win32Hwnd);
+  if (wParam == HTMINBUTTON)
+    DrawMinButton(hdc,TRUE,FALSE);
+  else
+    DrawMaxButton(hdc,TRUE,FALSE);
+
+  do
+  {
+    BOOL oldstate = pressed;
+
+    GetMessageA(&msg,Win32Hwnd,0,0);
+    pressed = (HandleNCHitTest(msg.pt) == wParam);
+    if (pressed != oldstate)
+    {
+      if (wParam == HTMINBUTTON)
+        DrawMinButton(hdc,pressed,FALSE);
+      else
+        DrawMaxButton(hdc,pressed,FALSE);
+    }
+  }
+
+  while (msg.message != WM_LBUTTONUP);
+
+  if (wParam == HTMINBUTTON)
+    DrawMinButton(hdc,FALSE,FALSE);
+  else
+    DrawMaxButton(hdc,FALSE,FALSE);
+
+  ReleaseCapture();
+  ReleaseDC(Win32Hwnd,hdc);
+  /* If the item minimize or maximize of the sysmenu are not there */
+  /* or if the style is not present, do nothing */
+  if ((!pressed) || (state == 0xFFFFFFFF))
+    return;
+
+  if (wParam == HTMINBUTTON)
+    SendInternalMessageA(WM_SYSCOMMAND,SC_MINIMIZE,*(LPARAM*)&msg.pt);
+  else
+    SendInternalMessageA(WM_SYSCOMMAND,IsZoomed(Win32Hwnd) ? SC_RESTORE:SC_MAXIMIZE,*(LPARAM*)&msg.pt);
+}
+//******************************************************************************
+//******************************************************************************
+VOID Win32BaseWindow::TrackCloseButton(WORD wParam)
+{
+  MSG msg;
+  HDC hdc;
+  BOOL pressed = TRUE;
+  UINT state;
+
+#if 0 //CB: todo
+  if (hSysMenu == 0)
+    return;
+  state = GetMenuState(hSysMenu, SC_CLOSE, MF_BYCOMMAND);
+#else
+state = 0;
+#endif
+  /* If the item close of the sysmenu is disabled or not there do nothing */
+  if((state & MF_DISABLED) || (state & MF_GRAYED) || (state == 0xFFFFFFFF))
+    return;
+  hdc = GetWindowDC(Win32Hwnd);
+  SetCapture(Win32Hwnd);
+  DrawCloseButton(hdc,TRUE,FALSE);
+  do
+  {
+    BOOL oldstate = pressed;
+
+    GetMessageA(&msg,Win32Hwnd,0,0);
+    pressed = (HandleNCHitTest(msg.pt) == wParam);
+    if (pressed != oldstate)
+      DrawCloseButton(hdc, pressed, FALSE);
+  } while (msg.message != WM_LBUTTONUP);
+  DrawCloseButton(hdc,FALSE,FALSE);
+  ReleaseCapture();
+  ReleaseDC(Win32Hwnd,hdc);
+  if (!pressed) return;
+  SendInternalMessageA(WM_SYSCOMMAND,SC_CLOSE,*(LPARAM*)&msg.pt);
+}
+//******************************************************************************
+//******************************************************************************
+LONG Win32BaseWindow::HandleNCLButtonUp(WPARAM wParam,LPARAM lParam)
+{
+  switch(wParam)  /* Hit test */
+  {
+    case HTMINBUTTON:
+      SendInternalMessageA(WM_SYSCOMMAND,SC_MINIMIZE,lParam);
+      break;
+
+    case HTMAXBUTTON:
+      SendInternalMessageA(WM_SYSCOMMAND,SC_MAXIMIZE,lParam);
+      break;
+
+    case HTCLOSE:
+      SendInternalMessageA(WM_SYSCOMMAND,SC_CLOSE,lParam);
+      break;
+  }
+
+  return 0;
+}
+/***********************************************************************
+ *           NC_HandleNCLButtonDblClk
+ *
+ * Handle a WM_NCLBUTTONDBLCLK message. Called from DefWindowProc().
+ */
+LONG Win32BaseWindow::HandleNCLButtonDblClk(WPARAM wParam,LPARAM lParam)
+{
+  /*
+   * if this is an icon, send a restore since we are handling
+   * a double click
+   */
+  if (dwStyle & WS_MINIMIZE)
+  {
+    SendInternalMessageA(WM_SYSCOMMAND,SC_RESTORE,lParam);
+    return 0;
+  }
+
+  switch(wParam)  /* Hit test */
+  {
+    case HTCAPTION:
+      /* stop processing if WS_MAXIMIZEBOX is missing */
+      if (dwStyle & WS_MAXIMIZEBOX)
+        SendInternalMessageA(WM_SYSCOMMAND,
+                      (dwStyle & WS_MAXIMIZE) ? SC_RESTORE : SC_MAXIMIZE,
+                      lParam);
+      break;
+
+    case HTSYSMENU:
+      if (!(GetClassWord(Win32Hwnd,GCW_STYLE) & CS_NOCLOSE))
+        SendInternalMessageA(WM_SYSCOMMAND,SC_CLOSE,lParam);
+      break;
+
+    case HTHSCROLL:
+      SendInternalMessageA(WM_SYSCOMMAND,SC_HSCROLL+HTHSCROLL,lParam);
+      break;
+
+    case HTVSCROLL:
+      SendInternalMessageA(WM_SYSCOMMAND,SC_VSCROLL+HTVSCROLL,lParam);
+      break;
+  }
+
+  return 0;
+}
+//******************************************************************************
+//******************************************************************************
+LONG Win32BaseWindow::HandleNCLButtonDown(WPARAM wParam,LPARAM lParam)
+{
+  switch(wParam)  /* Hit test */
+  {
+    case HTCAPTION:
+      SetActiveWindow();
+      if (GetActiveWindow() == Win32Hwnd)
+        SendInternalMessageA(WM_SYSCOMMAND,SC_MOVE+HTCAPTION,lParam);
+      break;
+
+    case HTSYSMENU:
+      if(dwStyle & WS_SYSMENU )
+      {
+        if( !(dwStyle & WS_MINIMIZE) )
+        {
+          HDC hDC = GetWindowDC(Win32Hwnd);
+          DrawSysButton(hDC,TRUE);
+          ReleaseDC(Win32Hwnd,hDC);
+        }
+        SendInternalMessageA(WM_SYSCOMMAND,SC_MOUSEMENU+HTSYSMENU,lParam);
+      }
+      break;
+
+    case HTMENU:
+      SendInternalMessageA(WM_SYSCOMMAND,SC_MOUSEMENU,lParam);
+      break;
+
+    case HTHSCROLL:
+      SendInternalMessageA(WM_SYSCOMMAND,SC_HSCROLL+HTHSCROLL,lParam);
+      break;
+
+    case HTVSCROLL:
+      SendInternalMessageA(WM_SYSCOMMAND,SC_VSCROLL+HTVSCROLL,lParam);
+      break;
+
+    case HTMINBUTTON:
+    case HTMAXBUTTON:
+      TrackMinMaxBox(wParam);
+      break;
+
+    case HTCLOSE:
+      TrackCloseButton(wParam);
+      break;
+
+    case HTLEFT:
+    case HTRIGHT:
+    case HTTOP:
+    case HTTOPLEFT:
+    case HTTOPRIGHT:
+    case HTBOTTOM:
+    case HTBOTTOMLEFT:
+    case HTBOTTOMRIGHT:
+        /* make sure hittest fits into 0xf and doesn't overlap with HTSYSMENU */
+        SendInternalMessageA(WM_SYSCOMMAND,SC_SIZE+wParam-2,lParam);
+        break;
+    case HTBORDER:
+        break;
+  }
+
+  return 0;
+}
+//******************************************************************************
+//******************************************************************************
+LONG Win32BaseWindow::HandleNCHitTest(POINT pt)
+{
+  RECT rect;
+
+  rect = *getWindowRect();
+  if (!PtInRect(&rect,pt)) return HTNOWHERE;
+
+  if (dwStyle & WS_MINIMIZE) return HTCAPTION;
+
+  if (!(flags & WIN_MANAGED))
+  {
+    /* Check borders */
+    if (HAS_THICKFRAME(dwStyle,dwExStyle))
+    {
+      InflateRect(&rect,-GetSystemMetrics(SM_CXFRAME),-GetSystemMetrics(SM_CYFRAME));
+      if (!PtInRect(&rect,pt))
+      {
+        /* Check top sizing border */
+        if (pt.y < rect.top)
+        {
+          if (pt.x < rect.left+GetSystemMetrics(SM_CXSIZE)) return HTTOPLEFT;
+          if (pt.x >= rect.right-GetSystemMetrics(SM_CXSIZE)) return HTTOPRIGHT;
+          return HTTOP;
+        }
+        /* Check bottom sizing border */
+        if (pt.y >= rect.bottom)
+        {
+          if (pt.x < rect.left+GetSystemMetrics(SM_CXSIZE)) return HTBOTTOMLEFT;
+          if (pt.x >= rect.right-GetSystemMetrics(SM_CXSIZE)) return HTBOTTOMRIGHT;
+          return HTBOTTOM;
+        }
+        /* Check left sizing border */
+        if (pt.x < rect.left)
+        {
+          if (pt.y < rect.top+GetSystemMetrics(SM_CYSIZE)) return HTTOPLEFT;
+          if (pt.y >= rect.bottom-GetSystemMetrics(SM_CYSIZE)) return HTBOTTOMLEFT;
+          return HTLEFT;
+        }
+        /* Check right sizing border */
+        if (pt.x >= rect.right)
+        {
+          if (pt.y < rect.top+GetSystemMetrics(SM_CYSIZE)) return HTTOPRIGHT;
+          if (pt.y >= rect.bottom-GetSystemMetrics(SM_CYSIZE)) return HTBOTTOMRIGHT;
+          return HTRIGHT;
+        }
+      }
+    } else  /* No thick frame */
+    {
+      if (HAS_DLGFRAME(dwStyle,dwExStyle))
+        InflateRect(&rect, -GetSystemMetrics(SM_CXDLGFRAME), -GetSystemMetrics(SM_CYDLGFRAME));
+      else if (HAS_THINFRAME(dwStyle ))
+        InflateRect(&rect, -GetSystemMetrics(SM_CXBORDER), -GetSystemMetrics(SM_CYBORDER));
+      if (!PtInRect( &rect, pt )) return HTBORDER;
+    }
+
+    /* Check caption */
+
+    if ((dwStyle & WS_CAPTION) == WS_CAPTION)
+    {
+      if (dwExStyle & WS_EX_TOOLWINDOW)
+        rect.top += GetSystemMetrics(SM_CYSMCAPTION)-1;
+      else
+        rect.top += GetSystemMetrics(SM_CYCAPTION)-1;
+      if (!PtInRect(&rect,pt))
+      {
+        /* Check system menu */
+        if(dwStyle & WS_SYSMENU)
+        {
+          /* Check if there is an user icon */
+          HICON hIcon = (HICON) GetClassLongA(Win32Hwnd, GCL_HICONSM);
+          if(!hIcon) hIcon = (HICON) GetClassLongA(Win32Hwnd, GCL_HICON);
+
+          /* If there is an icon associated with the window OR              */
+          /* If there is no hIcon specified and this is not a modal dialog, */
+          /* there is a system menu icon.                                   */
+          if((hIcon != 0) || (!(dwStyle & DS_MODALFRAME)))
+          rect.left += GetSystemMetrics(SM_CYCAPTION) - 1;
+        }
+        if (pt.x < rect.left) return HTSYSMENU;
+
+        /* Check close button */
+        if (dwStyle & WS_SYSMENU)
+        rect.right -= GetSystemMetrics(SM_CYCAPTION) - 1;
+        if (pt.x > rect.right) return HTCLOSE;
+
+        /* Check maximize box */
+        /* In win95 there is automatically a Maximize button when there is a minimize one*/
+        if ((dwStyle & WS_MAXIMIZEBOX)|| (dwStyle & WS_MINIMIZEBOX))
+        rect.right -= GetSystemMetrics(SM_CXSIZE) + 1;
+        if (pt.x > rect.right) return HTMAXBUTTON;
+
+        /* Check minimize box */
+        /* In win95 there is automatically a Maximize button when there is a Maximize one*/
+        if ((dwStyle & WS_MINIMIZEBOX)||(dwStyle & WS_MAXIMIZEBOX))
+        rect.right -= GetSystemMetrics(SM_CXSIZE) + 1;
+
+        if (pt.x > rect.right) return HTMINBUTTON;
+        return HTCAPTION;
+      }
+    }
+  }
+
+  /* Check client area */
+
+  ScreenToClient(Win32Hwnd,&pt);
+  rect = *getClientRect();
+  if (PtInRect(&rect,pt)) return HTCLIENT;
+
+  /* Check vertical scroll bar */
+
+  if (dwStyle & WS_VSCROLL)
+  {
+    rect.right += GetSystemMetrics(SM_CXVSCROLL);
+    if (PtInRect( &rect, pt )) return HTVSCROLL;
+  }
+
+  /* Check horizontal scroll bar */
+
+  if (dwStyle & WS_HSCROLL)
+  {
+    rect.bottom += GetSystemMetrics(SM_CYHSCROLL);
+    if (PtInRect( &rect, pt ))
+    {
+      /* Check size box */
+      if ((dwStyle & WS_VSCROLL) &&
+          (pt.x >= rect.right - GetSystemMetrics(SM_CXVSCROLL)))
+        return (dwStyle & WS_CHILD) ? HTSIZE:HTBOTTOMRIGHT;
+      return HTHSCROLL;
+    }
+  }
+
+  /* Check menu bar */
+
+  if (HAS_MENU(this))
+  {
+    if ((pt.y < 0) && (pt.x >= 0) && (pt.x < rect.right))
+      return HTMENU;
+  }
+
+  /* Should never get here */
+  return HTERROR;
+}
+
+//******************************************************************************
+//******************************************************************************
+VOID Win32BaseWindow::GetInsideRect(RECT *rect)
+{
+  rect->top    = rect->left = 0;
+  rect->right  = getWindowRect()->right - getWindowRect()->left;
+  rect->bottom = getWindowRect()->bottom - getWindowRect()->top;
+
+  if ((dwStyle & WS_ICONIC) || (flags & WIN_MANAGED)) return;
+
+  /* Remove frame from rectangle */
+  if (HAS_THICKFRAME(dwStyle,dwExStyle))
+  {
+    InflateRect( rect, -GetSystemMetrics(SM_CXSIZEFRAME), -GetSystemMetrics(SM_CYSIZEFRAME) );
+  }
+  else if (HAS_DLGFRAME(dwStyle,dwExStyle ))
+  {
+    InflateRect( rect, -GetSystemMetrics(SM_CXFIXEDFRAME), -GetSystemMetrics(SM_CYFIXEDFRAME));
+  }
+  else if (HAS_THINFRAME(dwStyle))
+  {
+    InflateRect( rect, -GetSystemMetrics(SM_CXBORDER), -GetSystemMetrics(SM_CYBORDER) );
+  }
+
+  /* We have additional border information if the window
+   * is a child (but not an MDI child) */
+  if ( (dwStyle & WS_CHILD)  &&
+       ( (dwExStyle & WS_EX_MDICHILD) == 0 ) )
+  {
+    if (dwExStyle & WS_EX_CLIENTEDGE)
+      InflateRect (rect, -GetSystemMetrics(SM_CXEDGE), -GetSystemMetrics(SM_CYEDGE));
+
+    if (dwExStyle & WS_EX_STATICEDGE)
+      InflateRect (rect, -GetSystemMetrics(SM_CXBORDER), -GetSystemMetrics(SM_CYBORDER));
+  }
+}
+//******************************************************************************
+//******************************************************************************
+VOID Win32BaseWindow::DrawFrame(HDC hdc,RECT *rect,BOOL dlgFrame,BOOL active)
+{
+  INT width, height;
+  HBRUSH oldBrush;
+
+  if (dlgFrame)
+  {
+    width = GetSystemMetrics(SM_CXDLGFRAME) - GetSystemMetrics(SM_CXEDGE);
+    height = GetSystemMetrics(SM_CYDLGFRAME) - GetSystemMetrics(SM_CYEDGE);
+  }
+  else
+  {
+    width = GetSystemMetrics(SM_CXFRAME) - GetSystemMetrics(SM_CXEDGE);
+    height = GetSystemMetrics(SM_CYFRAME) - GetSystemMetrics(SM_CYEDGE);
+  }
+
+  oldBrush = SelectObject(hdc,GetSysColorBrush(active ? COLOR_ACTIVEBORDER:COLOR_INACTIVEBORDER));
+
+  /* Draw frame */
+
+  PatBlt(hdc,rect->left,rect->top,rect->right-rect->left,height,PATCOPY);
+  PatBlt(hdc,rect->left,rect->top,width,rect->bottom-rect->top,PATCOPY);
+  PatBlt(hdc,rect->left,rect->bottom-1,rect->right-rect->left,-height,PATCOPY);
+  PatBlt(hdc,rect->right-1,rect->top,-width,rect->bottom-rect->top,PATCOPY);
+  SelectObject(hdc,oldBrush);
+
+  InflateRect(rect,-width,-height);
+}
+//******************************************************************************
+//******************************************************************************
+BOOL Win32BaseWindow::DrawSysButton(HDC hdc,BOOL down)
+{
+    HICON  hIcon;
+    RECT rect;
+
+    GetInsideRect(&rect);
+
+    hIcon = (HICON) GetClassLongA(Win32Hwnd, GCL_HICONSM);
+    if(!hIcon) hIcon = (HICON) GetClassLongA(Win32Hwnd, GCL_HICON);
+
+    /* If there is no hIcon specified or this is not a modal dialog, */
+    /* get the default one.                                          */
+    if(hIcon == 0)
+      if (!(dwStyle & DS_MODALFRAME))
+        hIcon = LoadImageA(0, MAKEINTRESOURCEA(OIC_WINEICON), IMAGE_ICON, 0, 0, LR_DEFAULTCOLOR);
+
+    if (hIcon)
+      DrawIconEx (hdc, rect.left + 2, rect.top + 2, hIcon,
+                  GetSystemMetrics(SM_CXSMICON),
+                  GetSystemMetrics(SM_CYSMICON),
+                  0, 0, DI_NORMAL);
+
+    return (hIcon != 0);
+}
+//******************************************************************************
+//******************************************************************************
+BOOL Win32BaseWindow::DrawGrayButton(HDC hdc,int x,int y)
+{
+  HBITMAP hMaskBmp;
+  HDC hdcMask = CreateCompatibleDC (0);
+  HBRUSH hOldBrush;
+  hMaskBmp = CreateBitmap (12, 10, 1, 1, lpGrayMask);
+
+  if(hMaskBmp == 0)
+    return FALSE;
+
+  SelectObject (hdcMask, hMaskBmp);
+
+  /* Draw the grayed bitmap using the mask */
+  hOldBrush = SelectObject (hdc, RGB(128, 128, 128));
+  BitBlt (hdc, x, y, 12, 10,
+          hdcMask, 0, 0, 0xB8074A);
+
+  /* Clean up */
+  SelectObject (hdc, hOldBrush);
+  DeleteObject(hMaskBmp);
+  DeleteDC (hdcMask);
+
+  return TRUE;
+}
+//******************************************************************************
+//******************************************************************************
+VOID Win32BaseWindow::DrawCloseButton(HDC hdc,BOOL down,BOOL bGrayed)
+{
+  RECT rect;
+  HDC hdcMem;
+
+  if( !(flags & WIN_MANAGED) )
+  {
+    BITMAP bmp;
+    HBITMAP hBmp, hOldBmp;
+
+    GetInsideRect(&rect);
+
+    hdcMem = CreateCompatibleDC( hdc );
+    hBmp = down ? hbitmapCloseD : hbitmapClose;
+    hOldBmp = SelectObject (hdcMem, hBmp);
+    GetObjectA (hBmp, sizeof(BITMAP), &bmp);
+
+    BitBlt (hdc, rect.right - (GetSystemMetrics(SM_CYCAPTION) + 1 + bmp.bmWidth) / 2,
+            rect.top + (GetSystemMetrics(SM_CYCAPTION) - 1 - bmp.bmHeight) / 2,
+            bmp.bmWidth, bmp.bmHeight, hdcMem, 0, 0, SRCCOPY);
+
+    if(bGrayed)
+      DrawGrayButton(hdc,rect.right - (GetSystemMetrics(SM_CYCAPTION) + 1 + bmp.bmWidth) / 2 + 2,
+                     rect.top + (GetSystemMetrics(SM_CYCAPTION) - 1 - bmp.bmHeight) / 2 + 2);
+
+    SelectObject (hdcMem, hOldBmp);
+    DeleteDC (hdcMem);
+  }
+}
+//******************************************************************************
+//******************************************************************************
+VOID Win32BaseWindow::DrawMaxButton(HDC hdc,BOOL down,BOOL bGrayed)
+{
+  RECT rect;
+  HDC hdcMem;
+
+  if( !(flags & WIN_MANAGED))
+  {
+    BITMAP  bmp;
+    HBITMAP  hBmp,hOldBmp;
+
+    GetInsideRect(&rect);
+    hdcMem = CreateCompatibleDC( hdc );
+    hBmp = IsZoomed(Win32Hwnd) ?
+            (down ? hbitmapRestoreD : hbitmapRestore ) :
+            (down ? hbitmapMaximizeD: hbitmapMaximize);
+    hOldBmp=SelectObject( hdcMem, hBmp );
+    GetObjectA (hBmp, sizeof(BITMAP), &bmp);
+
+    if (dwStyle & WS_SYSMENU)
+      rect.right -= GetSystemMetrics(SM_CYCAPTION) + 1;
+
+    BitBlt( hdc, rect.right - (GetSystemMetrics(SM_CXSIZE) + bmp.bmWidth) / 2,
+          rect.top + (GetSystemMetrics(SM_CYCAPTION) - 1 - bmp.bmHeight) / 2,
+          bmp.bmWidth, bmp.bmHeight, hdcMem, 0, 0, SRCCOPY );
+
+    if(bGrayed)
+      DrawGrayButton(hdc, rect.right - (GetSystemMetrics(SM_CXSIZE) + bmp.bmWidth) / 2 + 2,
+                      rect.top + (GetSystemMetrics(SM_CYCAPTION) - 1 - bmp.bmHeight) / 2 + 2);
+
+
+    SelectObject (hdcMem, hOldBmp);
+    DeleteDC( hdcMem );
+  }
+}
+//******************************************************************************
+//******************************************************************************
+VOID Win32BaseWindow::DrawMinButton(HDC hdc,BOOL down,BOOL bGrayed)
+{
+  RECT rect;
+  HDC hdcMem;
+
+  if( !(flags & WIN_MANAGED))
+
+  {
+    BITMAP  bmp;
+    HBITMAP  hBmp,hOldBmp;
+
+    GetInsideRect(&rect);
+
+    hdcMem = CreateCompatibleDC( hdc );
+    hBmp = down ? hbitmapMinimizeD : hbitmapMinimize;
+    hOldBmp= SelectObject( hdcMem, hBmp );
+    GetObjectA (hBmp, sizeof(BITMAP), &bmp);
+
+    if (dwStyle & WS_SYSMENU)
+      rect.right -= GetSystemMetrics(SM_CYCAPTION) + 1;
+
+    /* In win 95 there is always a Maximize box when there is a Minimize one */
+    if ((dwStyle & WS_MAXIMIZEBOX) || (dwStyle & WS_MINIMIZEBOX))
+      rect.right += -1 - (GetSystemMetrics(SM_CXSIZE) + bmp.bmWidth) / 2;
+
+    BitBlt( hdc, rect.right - (GetSystemMetrics(SM_CXSIZE) + bmp.bmWidth) / 2,
+          rect.top + (GetSystemMetrics(SM_CYCAPTION) - 1 - bmp.bmHeight) / 2,
+          bmp.bmWidth, bmp.bmHeight, hdcMem, 0, 0, SRCCOPY );
+
+    if(bGrayed)
+      DrawGrayButton(hdc, rect.right - (GetSystemMetrics(SM_CXSIZE) + bmp.bmWidth) / 2 + 2,
+                      rect.top + (GetSystemMetrics(SM_CYCAPTION) - 1 - bmp.bmHeight) / 2 + 2);
+
+
+    SelectObject (hdcMem, hOldBmp);
+    DeleteDC( hdcMem );
+  }
+}
+//******************************************************************************
+//******************************************************************************
+VOID Win32BaseWindow::DrawCaption(HDC hdc,RECT *rect,BOOL active)
+{
+  RECT  r = *rect;
+  char  buffer[256];
+  HPEN  hPrevPen;
+  HMENU hSysMenu;
+
+  hPrevPen = SelectObject( hdc, GetSysColorPen(COLOR_3DFACE) );
+  MoveToEx( hdc, r.left, r.bottom - 1, NULL );
+  LineTo( hdc, r.right, r.bottom - 1 );
+  SelectObject( hdc, hPrevPen );
+  r.bottom--;
+
+  FillRect( hdc, &r, GetSysColorBrush(active ? COLOR_ACTIVECAPTION : COLOR_INACTIVECAPTION) );
+
+  if (!hbitmapClose)
+  {
+    if (!(hbitmapClose = LoadBitmapA(0,MAKEINTRESOURCEA(OBM_CLOSE)))) return;
+    hbitmapCloseD    = LoadBitmapA(0,MAKEINTRESOURCEA(OBM_CLOSED));
+    hbitmapMinimize  = LoadBitmapA(0,MAKEINTRESOURCEA(OBM_REDUCE));
+    hbitmapMinimizeD = LoadBitmapA(0,MAKEINTRESOURCEA(OBM_REDUCED));
+    hbitmapMaximize  = LoadBitmapA(0,MAKEINTRESOURCEA(OBM_ZOOM));
+    hbitmapMaximizeD = LoadBitmapA(0,MAKEINTRESOURCEA(OBM_ZOOMD));
+    hbitmapRestore   = LoadBitmapA(0,MAKEINTRESOURCEA(OBM_RESTORE));
+    hbitmapRestoreD  = LoadBitmapA(0,MAKEINTRESOURCEA(OBM_RESTORED));
+  }
+
+  if ((dwStyle & WS_SYSMENU) && !(dwExStyle & WS_EX_TOOLWINDOW))
+  {
+    if (DrawSysButton(hdc,FALSE))
+      r.left += GetSystemMetrics(SM_CYCAPTION) - 1;
+  }
+
+  if (dwStyle & WS_SYSMENU)
+  {
+    UINT state;
+#if 0 //CB: todo
+    /* Go get the sysmenu */
+    state = GetMenuState(hSysMenu, SC_CLOSE, MF_BYCOMMAND);
+#else
+    state = 0;
+#endif
+    /* Draw a grayed close button if disabled and a normal one if SC_CLOSE is not there */
+    DrawCloseButton(hdc, FALSE,
+                    ((((state & MF_DISABLED) || (state & MF_GRAYED))) && (state != 0xFFFFFFFF)));
+    r.right -= GetSystemMetrics(SM_CYCAPTION) - 1;
+
+    if ((dwStyle & WS_MAXIMIZEBOX) || (dwStyle & WS_MINIMIZEBOX))
+    {
+      /* In win95 the two buttons are always there */
+      /* But if the menu item is not in the menu they're disabled*/
+
+      DrawMaxButton(hdc, FALSE, (!(dwStyle & WS_MAXIMIZEBOX)));
+      r.right -= GetSystemMetrics(SM_CXSIZE) + 1;
+
+      DrawMinButton(hdc, FALSE,  (!(dwStyle & WS_MINIMIZEBOX)));
+            r.right -= GetSystemMetrics(SM_CXSIZE) + 1;
+    }
+  }
+
+  if (GetWindowTextA(buffer, sizeof(buffer) ))
+  {
+    NONCLIENTMETRICSA nclm;
+    HFONT hFont, hOldFont;
+    nclm.cbSize = sizeof(NONCLIENTMETRICSA);
+    SystemParametersInfoA (SPI_GETNONCLIENTMETRICS, 0, &nclm, 0);
+    if (dwExStyle & WS_EX_TOOLWINDOW)
+      hFont = CreateFontIndirectA (&nclm.lfSmCaptionFont);
+    else
+      hFont = CreateFontIndirectA (&nclm.lfCaptionFont);
+    hOldFont = SelectObject (hdc, hFont);
+    if (active) SetTextColor( hdc, GetSysColor( COLOR_CAPTIONTEXT ) );
+    else SetTextColor( hdc, GetSysColor( COLOR_INACTIVECAPTIONTEXT ) );
+    SetBkMode( hdc, TRANSPARENT );
+    r.left += 2;
+    DrawTextA( hdc, buffer, -1, &r,
+             DT_SINGLELINE | DT_VCENTER | DT_NOPREFIX | DT_LEFT );
+    DeleteObject (SelectObject (hdc, hOldFont));
+  }
+}
+//******************************************************************************
+//******************************************************************************
+VOID Win32BaseWindow::HandleNCPaint(HRGN clip, BOOL suppress_menupaint)
+{
+  BOOL active  = flags & WIN_NCACTIVATED;
+  HDC hdc;
+  RECT rect,rectClip,rfuzz;
+
+  if (dwStyle & WS_MINIMIZE) 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( Win32Hwnd, (clip > 1) ? clip : 0, DCX_USESTYLE | DCX_WINDOW |
+                      ((clip > 1) ?(DCX_INTERSECTRGN /*| DCX_KEEPCLIPRGN*/) : 0) ))) return;
+
+  rect.top = rect.left = 0;
+  rect.right  = getWindowRect()->right - getWindowRect()->left;
+  rect.bottom = getWindowRect()->bottom - getWindowRect()->top;
+
+  if( clip > 1 )
+    GetRgnBox( clip, &rectClip );
+  else
+  {
+    clip = 0;
+    rectClip = rect;
+  }
+
+  SelectObject( hdc, GetSysColorPen(COLOR_WINDOWFRAME) );
+
+  if (HAS_BIGFRAME( dwStyle, dwExStyle))
+  {
+      DrawEdge (hdc, &rect, EDGE_RAISED, BF_RECT | BF_ADJUST);
+  }
+  if (HAS_THICKFRAME( dwStyle, dwExStyle ))
+      DrawFrame(hdc, &rect, FALSE, active );
+  else if (HAS_DLGFRAME( dwStyle, dwExStyle ))
+      DrawFrame( hdc, &rect, TRUE, active );
+  else if (HAS_THINFRAME( dwStyle ))
+  {
+      SelectObject( hdc, GetStockObject(NULL_BRUSH) );
+      Rectangle( hdc, 0, 0, rect.right, rect.bottom );
+  }
+
+  if ((dwStyle & WS_CAPTION) == WS_CAPTION)
+  {
+      RECT  r = rect;
+      if (dwExStyle & WS_EX_TOOLWINDOW)
+      {
+        r.bottom = rect.top + GetSystemMetrics(SM_CYSMCAPTION);
+        rect.top += GetSystemMetrics(SM_CYSMCAPTION);
+      }
+      else
+      {
+        r.bottom = rect.top + GetSystemMetrics(SM_CYCAPTION);
+        rect.top += GetSystemMetrics(SM_CYCAPTION);
+      }
+      if( !clip || IntersectRect( &rfuzz, &r, &rectClip ) )
+        DrawCaption(hdc, &r, active);
+  }
+
+#if 0 //CB: todo
+  if (HAS_MENU(wndPtr))
+  {
+    RECT r = rect;
+    r.bottom = rect.top + GetSystemMetrics(SM_CYMENU);
+
+    rect.top += MENU_DrawMenuBar( hdc, &r, hwnd, suppress_menupaint ) + 1;
+  }
+
+  if (dwExStyle & WS_EX_CLIENTEDGE)
+    DrawEdge (hdc, &rect, EDGE_SUNKEN, BF_RECT | BF_ADJUST);
+
+  if (dwExStyle & WS_EX_STATICEDGE)
+    DrawEdge (hdc, &rect, BDR_SUNKENOUTER, BF_RECT | BF_ADJUST);
+
+  /* Draw the scroll-bars */
+#if 0 //CB: todo
+  if (dwStyle & WS_VSCROLL)
+    SCROLL_DrawScrollBar(hwnd,hdc,SB_VERT,TRUE,TRUE);
+  if (wndPtr->dwStyle & WS_HSCROLL)
+    SCROLL_DrawScrollBar(hwnd,hdc,SB_HORZ,TRUE,TRUE);
+#endif
+  /* Draw the "size-box" */
+  if ((dwStyle & WS_VSCROLL) && (dwStyle & WS_HSCROLL))
+  {
+    RECT r = rect;
+    r.left = r.right - GetSystemMetrics(SM_CXVSCROLL) + 1;
+    r.top  = r.bottom - GetSystemMetrics(SM_CYHSCROLL) + 1;
+    FillRect( hdc, &r,  GetSysColorBrush(COLOR_SCROLLBAR) );
+    if (!(dwStyle & WS_CHILD))
+    {
+      POINT p1,p2;
+      HPEN penDark = GetSysColorPen(COLOR_3DSHADOW);
+      HPEN penWhite = GetSysColorPen(COLOR_3DHILIGHT);
+      HPEN oldPen = SelectObject(hdc,penDark);
+      INT x;
+
+      p1.x = r.right-1;
+      p1.y = r.bottom;
+      p2.x = r.right;
+      p2.y = r.bottom-1;
+      for (x = 0;x < 3;x++)
+      {
+        SelectObject(hdc,penDark);
+        MoveToEx(hdc,p1.x,p1.y,NULL);
+        LineTo(hdc,p2.x,p2.y);
+        p1.x--;
+        p2.y--;
+        MoveToEx(hdc,p1.x,p1.y,NULL);
+        LineTo(hdc,p2.x,p2.y);
+        SelectObject(hdc,penWhite);
+        p1.x--;
+        p2.y--;
+        MoveToEx(hdc,p1.x,p1.y,NULL);
+        LineTo(hdc,p2.x,p2.y);
+        p1.x -= 2;
+        p2.y -= 2;
+      }
+
+      SelectObject(hdc,oldPen);
+    }
+  }
+#endif
+
+  ReleaseDC(Win32Hwnd,hdc);
+}
+//******************************************************************************
+//******************************************************************************
+LONG Win32BaseWindow::HandleNCActivate(WPARAM wParam)
+{
+  WORD wStateChange;
+
+  if( wParam ) {
+        wStateChange = !(flags & WIN_NCACTIVATED);
+  }
+  else  wStateChange = flags & WIN_NCACTIVATED;
+
+  if( wStateChange )
+  {
+    if (wParam)
+         flags |= WIN_NCACTIVATED;
+    else flags &= ~WIN_NCACTIVATED;
+
+    if(!(dwStyle & WS_MINIMIZE))
+      HandleNCPaint((HRGN)1,FALSE);
+  }
+  return TRUE;
+}
+//******************************************************************************
+//******************************************************************************
+
Index: trunk/src/user32/win32wbasepos.cpp
===================================================================
--- trunk/src/user32/win32wbasepos.cpp	(revision 2382)
+++ trunk/src/user32/win32wbasepos.cpp	(revision 2383)
@@ -1,3 +1,3 @@
-/* $Id: win32wbasepos.cpp,v 1.7 1999-12-16 00:11:47 sandervl Exp $ */
+/* $Id: win32wbasepos.cpp,v 1.8 2000-01-09 14:37:12 sandervl Exp $ */
 /*
  * Win32 Window Base Class for OS/2 (nonclient/position methods)
@@ -86,6 +86,6 @@
     LPINTERNALPOS lpPos;
 
-    size.x = rectWindow.left; size.y = rectWindow.top;
-    lpPos = WINPOS_InitInternalPos( wndPtr, size, &rectWindow );
+    size.x = getWindowRect()->left; size.y = getWindowRect()->top;
+    lpPos = WINPOS_InitInternalPos( wndPtr, size, getWindowRect() );
 
     if (lpPos && !HOOK_CallHooks16(WH_CBT, HCBT_MINMAX, hwndSelf, cmd))
Index: trunk/src/user32/window.cpp
===================================================================
--- trunk/src/user32/window.cpp	(revision 2382)
+++ trunk/src/user32/window.cpp	(revision 2383)
@@ -1,3 +1,3 @@
-/* $Id: window.cpp,v 1.46 1999-12-29 22:54:04 cbratschi Exp $ */
+/* $Id: window.cpp,v 1.47 2000-01-09 14:37:12 sandervl Exp $ */
 /*
  * Win32 window apis for OS/2
@@ -648,7 +648,7 @@
         return 0;
     }
-    rc = window->GetWindowRect(pRect);
+    *pRect = *window->getWindowRect();
     dprintf(("GetWindowRect %x (%d,%d) (%d,%d)", hwnd, pRect->left, pRect->top, pRect->right, pRect->bottom));
-    return rc;
+    return TRUE;
 }
 //******************************************************************************
@@ -1009,5 +1009,5 @@
     DWP *pDWP;
 
-    dprintf(("USER32:  BeginDeferWindowPos\n"));
+    dprintf(("USER32: BeginDeferWindowPos %x", count));
     if (count <= 0)
     {
